bleggee
asked on
PHP Nesting question
Hi - Given a PHP website file, what is the easiest way to see the nesting of the { and } brackets?
(Indented, Colorized, etc)
I have latest versions of Dreamweaver, Coda 2, BBEDIT, and PHPStorm, of course any other 3rd party utility will do!
(Indented, Colorized, etc)
I have latest versions of Dreamweaver, Coda 2, BBEDIT, and PHPStorm, of course any other 3rd party utility will do!
Firstly - code so you don't end up with too much nesting. If you are finding you are going 3/4/5 levels deep you are probably needing to refactor.
Secondly - neat code - make sure your indenting is exact on all your code - messy code = bad code.
Third - as Chris said any decent editor will do the matching for you - when you position your cursor on one it highlights the closing bracket - they should also support collapsible blocks so you can collapse bracketed blocks you are not interested in.
An addendum to the second point - there are no points for writing the most code on one line.. Break your code up so it is easily readable - that means within the limit (horizontal) of your editor pane. If necessary break your line up or refactor into several lines.
The goal with your code is that you can read it - easily - by looking it it without having to scroll the window or pull apart complex code on a single line.
Secondly - neat code - make sure your indenting is exact on all your code - messy code = bad code.
Third - as Chris said any decent editor will do the matching for you - when you position your cursor on one it highlights the closing bracket - they should also support collapsible blocks so you can collapse bracketed blocks you are not interested in.
An addendum to the second point - there are no points for writing the most code on one line.. Break your code up so it is easily readable - that means within the limit (horizontal) of your editor pane. If necessary break your line up or refactor into several lines.
The goal with your code is that you can read it - easily - by looking it it without having to scroll the window or pull apart complex code on a single line.
ASKER
Thanks guys. I appreciate all the "Write Clean Code" comments, though the files I am working with were written elsewhere ... I inherited them. Very Spagetti coded!!
If I need to go the refactoring route, have either of you used any of the automatic refactoring tools that come with XCode or VS?
If I need to go the refactoring route, have either of you used any of the automatic refactoring tools that come with XCode or VS?
I've not used the automatic tools, but I can't imagine they'll give you particularly good results. Some of the code may be improved by using the tools, but large parts of it will likely come down to your own personal choice and programming styles. You can run it through a Code Sniffer to see if any problems are highlighted, and that may go some way to improving it.
In my experience, generally speaking, bad code can't be made into good code by simply running a tool.
In my experience, generally speaking, bad code can't be made into good code by simply running a tool.
I have used VS Code refactoring but not with PHP - mostly with Typescript - it works well - not familiar with the other environments.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
And sometimes, using the alternative control blocks in PHP can help quite a bit - particularly if you have lots of nested curly brackets:
Open in new window
Sometime this makes your code easier to read :)