![]() |
A little bit of code that needs critiquing
what do you guys think:
PHP Code:
|
The first thing that strikes me is that code is awfully difficult to read. I dislike the actual layout of the code, and there's a lack of commenting. I fear it would take me a while to understand what's going on there, and whilst you may think that's not such a bad thing, because perhaps you're the only person who's working on it. What happens if you neglect it and then come back to it in 6 month's time? Do you think you'll still understand what is going on?
I think the best approach is probably to separate out the difficult tasks to other classes. That way one class only has one responsibility, and that responsibility can be clearly detailed by yourself. So when you do come back to the code in 6 month's time, you'll be able to read the comments in which you wrote down, and begin working on the classes again within, hopefully, 5 minutes or so. In addition to that, I think placing the curly brackets on new lines -- lines of their own, really does help in readability, but that's merely a personal preference. |
@up- Totally agree. This code looks really messy and, as you said, very hard to read.
|
I do have to agree, although its certainly not the worst code block i have ever seen, it certainly could do with a bit of a tidy up.
Why if you are using a class that has PHP5 style syntax have you used 'var' instead of the visibility modifiers, if you want the class to be PHP4 compliant, you will need to remove your construct and replace it with the C++ style constructor (a method with the same name as the class), if not then use either 'public', 'private' or 'protected' instead of var (it used to call a E_STRICT warning, but i cant seem to replicate it). Dont call non-static methods as static: PHP Code:
PHP Code:
PHP Code:
PHP Code:
Apart from that its all personal preference. I personally would have the code block delimiters {} on a new line and I wouldn't use the bash comment style. |
@ All the above, I couldn't agree more.
What they said, comment your code, use white-space to your advantage, be clear with variable names and so forth. As opposed to: PHP Code:
Also, you should form up your comments with newlines and explain what you're doing. It doesn't have to be pretty, you wouldn't need to great a peice of ASCII art of sorts, but just explain the function. Therefor the name, description, static function, an example (how it could be used in your script) and so forth. Don't be shy of using a couple of enters while you're at it. PHP Code:
PHP Code:
One more for the road. Try to comment your code as wisely as you can. PHP Code:
|
Don't worry about long function names:
sdba() or setDatabaseAdapter()... which do you understand better? I can't make sense of any of your functions except construct |
Kinda what the complete topic answers are about. :-P
|
| All times are GMT. The time now is 08:48 AM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0