PHP applications code quality
Par jd le jeudi, mars 27 2008, 07:57 - Internet - Lien permanent
Ah, Erich, that IS so true. I never found a well written PHP application anyway, or it was only 10 lines long.
I guess that's primarily the language fault. It permits to do a lot of stuff and does not simplify, help nor force the simplest implementation methods like MVC which should be the base in Web developement.
Well, take as example what we would do with Python and GTK+ if they were like PHP and HTML (I do not have the API reference so it will be somewhat improvised):
#finally we do not need this module I wrote everything myself
#import somemodule
def main():
# Well we want to do some printing
window = GtkWindow()
# Connect to the database without any abstraction, that sucks
db = mysql.connect()
data = db.query("select RANDOMLYTYPEDDATA from MYONLYTABLE");
while data:
# Ah, we do not have include() so we cannot reuse code
# I'm a PHP developer, I do not know functions
import somestuff
window.print(somestuff.result)
# Obviously, forgot to close db connection, etc.
if form.data.field == "hello":
# The user asked for hello, print hello
window.print("hello")
# debug
print data[0]
if form.data.anotherfield[0] == "morning":
data = db.query("select anotherdata from MYONLYDATA")
else:
sys.exit(42)
label = GtkLabel()
# Yes know we construct the view!
window.add(label)
label.print(data)
That is typical PHP code: we just take randomly typed data from our DB eng... no wait, from MySQL (remember that's LAMP!!! Not LAPP or anything else, bitches!), then we print some HTML code with data, and we do tests on environment, forms, etc, and we get back data, reprint them, do not use functions but include() multiple times thousand of files and then do not close/free anything.
It's so easy to do bad code that lot of people coming from nowhere and who did not learn anything from other languages are doing it.
Another hypothesis coming from my experiment: PHP is a language which can be developed under any OS since it's server-side executed. A link between mostly brain dead "developers" from the Microsoft world and whose from the Free Software world. A clash.
I apologize to some of my coworkers doing better PHP all the day. 
Commentaires
I got a chance to do a php contract and do a maintainable job of it. The language doesn't make it easy. Zendcframework helps, so does the eclipse php plugin.
If you want to see the result, look at the groupus project on launchpad.
Like any codebase, there are lots of places where we just didnt manage to finish a transition. Overall, the code is clean enough to show the outside world.
Like C, PHP gives you enough rope to hang yourself. Just be glad it's not like Visual Basic, which gives you enough rope to shoot yourself. My biggest gripe is its utter disregard for types, which enables the above-mentioned randomly-typed data. That, and the fact that the older mysql interface will close connections if the script crashes, but the newer, otherwise-nicer mysqli will not. And the lack of support for prepared queries (hello, SQL injection). I could probably complain about PHP for hours on end. I am currently developing a web app in PHP, and my experiences could probably be published in a book entitled "Object-Oriented Programming and Clean Design in a Hostile Environment".
Juste une note, proner le libre et appliquer la censure n'est pas vraiment tres coherent. Enfin, les filtres dans mon feed read sont pratiques, planet-debian ne sera que plus interessant.
Well... another "elite" developer rant about a low entry language.... Nothing new here
Erich is very tiring in this regard, don't follow the same path.
It's not in the language, its in the developer
Wow, by reading this article, it looks you are one of the best developers in the world.
"It's so easy to do bad code that lot of people coming from nowhere and who did not learn anything from other languages are doing it."
That *hurts* you in some way? Don't use that code, man! Congratulations for being so ego-centric.
PHP is an easy and powerfull language, it`s stupid to critisize it for being easy and powerfull.
Whining about type conversion all day, doesn`t make your preffered language any better than php.
Yes there are weak minded PHP developers, but there are also weak minded C, Perl, Ruby, Java , Python .... etc. developers also.
Get over it, PHP can do things that other languaes don`t.
"do not use functions but include() multiple times thousand of files and then do not close/free anything."
That`s not true, you looked at one code then you generalize it. And did you hear of garbage collection? or did you hear that an averave PHP script runs less than a second and after it`s execution all memory is freed? freeing memory during runtime is so pointless, uses extra CPU cycles, get over it PHP is for web not for client side apps.
"Well, take as example what we would do with Python and GTK+ if they were like PHP and HTML"
HTML is not GTK and never will be this example is invalid. By the way it`s a very greate excuse for GTK`s brain damaged API.
"I guess that's primarily the language fault."
Languagees don`t write bad code, people do.
"It permits to do a lot of stuff and does not simplify, help nor force the simplest implementation methods like MVC which should be the base in Web developement."
It does simplify everything, but if you don`t like it write your own classes that force people (who can`t program without forcing) to program the right way.
Please don`t post any more posts likt these, because it`s a ridicilous comparism that doesn`t prove anything, remember:
Languagees don`t write bad code, people do.
Well, that's sad most of you fall into that huge troll blindly.
Do not read this post at first degree, and read between the lines, guys.
Obviously there is great applications in PHP. I do work in a company writing PHP apps all the day, and I really do not think what my coworkers do every day is crap.
Good developers do good code, whatever the language they're using, no one will tell you the opposite.
But, lots of newbie developers come in with PHP and learn with that and then do puslish crappy code.
Why they learn with PHP ? Because da Web 2.0 time obviously.
Alex did a pretty good analyse, I'd just add that PHP gives you enough rope to hang you and all your family (server) in the ride (again hello SQL injection, XSS etc.) if you do not care.
And you do NOT HAVE TO care.
Make an error in C, it'll segfault. That at least learns you to "think before writing" when you begin.
PHP does not learn people to think before writing; and that's not bad if you're a good developer.
But if you are a newbie, beginning your coding experience with PHP like some (I use "some" to not tell "many") people I know did, you will do crap, no matter what.
Fil des commentaires de ce billet