Smoking toooooo much PHP



good
I learned a lot form this article
#1 - kinch ( Link) on 22 Mar 2008, 14:31 Delete Comment
Good Post
Nice to read other's take on developing standards with php, and agree with all of it. Well done, and hope you get to feeling better.
#2 - Hugh ( Link) on 23 Mar 2008, 02:44 Delete Comment
Start proofreading
You know what else is so 1999?

Posting something to a blog you want to be taken without proofreading it.

Please properly spell and punctuate your posts in the future, that was just hard to read.
#3 - Steve ( Link) on 24 Mar 2008, 05:54 Delete Comment
Proofreading
Actually this one's not too bad compared to some of my previous ones..

I did go through it again but fr**ging serendipity, which is what the backend of this thing uses timed out and lost the changes..

Not quite sure if Blogs are more just 'venting' frustration or ever supposed to be taken seriously....

#4 - Alan Knowles ( Link) on 24 Mar 2008, 10:57 Delete Comment
Just ok
I have to disagree with some of your points...

"Mixing PHP and HTML"
This should be retitled as "Mixing HTML and business logic". I think that's what you mean anyway. It's ok to mix php and html (how else do you generate a dynamic page), however, having your business logic interspersed with the display html is a PITA for code maintenance, among other things.

"Functional Crap (or Procedural code)"
I disagree that no complex program can be created procedurally. This is entirely programmer dependent. If the person doing the programming is competent and disciplined then anything that can be done w/OOP can be done just as well procedurally. The biggest advantage of OOP is reusability. Everything is in a nice, neat package that is able to be used over and over. Aside from that advantage (which is quite large), there is little more, in my opinion, than additional overhead that is added with OOP.
#5 - Andrew ( Link) on 24 Mar 2008, 20:35 Delete Comment
OOP is slower
OOP actually is slower. I was benchmarking some code, and when I had the algorithm down, I converted the function to a class method. Solely from putting the identical code into a class, its speed dropped by 30%. Apparently the engine has to do a lot more work from inside an object to call functions.

After I noticed that with 5.1.6, I was able to duplicate it on then-current 5.2.3.

Not that it mattered. That code got ported to Perl; it failed in production because I forgot PHP *still* can't handle large files. Grrr!
#6 - sapphirecat ( Link) on 24 Mar 2008, 20:45 Delete Comment
Well...
Well, I guess that is a most instructive post than the previous one, but there is a few points I disagree with.

*.class.php
As for me, using procedural AND objet in the same application is a quality for php, you don't have to modelize everything nor using static methods if you don't want to. I really love OOP, but I think a few things would have pissed me off if I had to turn them into classes. Even if using static functions make your code easy to organize, it stays slower than using simple functions, I guess.
What I want to say is using *.class.php extention is, in my opinions, very usefull as you know this file contains a class (named Plop for plop.class.php...) and there is no need to look for something in this file, you know what I mean ? (I'm not sure I understand my own words...)

Mixing PHP and HTML is pretty cool too, if your code is well-organized (queries at the top, not in the HTML code, for exemple)...).

I'm still using defines for config vars, but not as you said, I usually put them in a file named "config.php" or "needs.php" or something like that...

Php actually is a quite simple language you can do powerfull thing with without discouraging beginners with jiberish concepts... If I were you, I'll put a few "I think", "In my opinion" or "as for me" in my posts, otherwise it's a bit impetuous, just my 2 cents...

(I'm still french since my last comment, once again please excuse my english ;))
#7 - Palleas ( Link) on 25 Mar 2008, 05:48 Delete Comment
Just about Class nominating
I just wanted to add something about the class nomination.
I'm okay to say that a good nomination is important, but the way you explain (using Aaaa_Bbbbb_Cccc) makes me think that you are involved into the Zend fw :D.
Maybe it's a good idea the way they call their classes, but it's certainly not the only one.

Otherwise, I read an other post into your blog (the original post of this one, this one you listed the bad cms), and I disagree with you with the fact some cms does not use PDO or some PEAR code. I'm totally agree to the fact theses codes are powerful and they have a lot of user contributed features and 6 years of bug fixes. But sometime, on some web server, you don't have PDO or PEAR package. So if you use a cms/fw that need Pear/PDO, you screwed !
Maybe the better way is to have a cms/fw that could use pear/pdo but also implement their own scripts (or a functionnal else). Don't you ?


Sorry for my english..
#8 - cx42 ( Link) on 25 Mar 2008, 06:26 Delete Comment
Zend Framework components
As far as packaging goes you pretty much have to download the whole Zend Framework if you want to use it (with the exceptions of the Google Data APIs and Microsoft Infocard components which can be downloaded separately). However, just because you have to download it all doesn't mean you have to use it all. Zend Framework is really just a bunch of loosely coupled components that you can use to "glue" your application together. This is important to keep in mind - just because the whole framework is sitting on disk doesn't mean you have the overhead of a whole framework. You can use it like a class library that you pick-and-choose components from. There's really no reason to not use Zend Framework in your application - there's a lots of useful stuff in there that your application could most likely benefit from. There is, however, a Zend Framework MVC stack which you can use if you'd like. It's your choice, individual Zend Framework components or the whole MVC stack plus individual components.
#9 - Bradley Holt ( Link) on 26 Mar 2008, 02:55 Delete Comment
asdf
Full of yourself? Never "mixing" php and HTML? Are you advocating a use of a template system like Smarty (Hey, PHP IS a template system).

Not defining constants in a config file? Why not? You are assuming everyone uses the front controller pattern then if you only set it in index.php...what happens when you have another page? Oh no, they are defined there unless you include index.php too.

Get off your high horse and make a constructive post, instead of your "I'm better than you" junk you have up there.
#10 - Wow ( Link) on 26 Mar 2008, 03:38 Delete Comment
Couple points
Andrew - "It's ok to mix php and html (how else do you generate a dynamic page)"

Actually you can do this by using a JS front end that is only asking for data that it will mold on the clients side. I have a current project where the PHP is just generating JSON for an ext-js frontend. Though I still love having to have the ability to go into a current HTML page we have and throw in 5 lines of php where needed and not have rewrite the whole file.
#11 - ripsup ( Link) on 26 Mar 2008, 04:49 Delete Comment
Zend Fw rebund
@Bradley Holt : If your previous post was for me, I totally agree at the fact that you could use a part of the zend fw, and it's not because you have all the files that you need to load all of them. But I was talking about external needs. A framework that use PDO, Pear, is great because not use the "I created from scratch because I'm a roxor". But if your server does not have Pdo/Pear, you can't do nothing with this fw. That's why the most important framework (zend, cake, code igniter, etc) use their own abstract database, cache and view renderers.
#12 - cx42 ( Link) on 26 Mar 2008, 07:16 Delete Comment
Terminology
What are 'defines'? A common name for what you mean is 'constants'. They are called like that for ages.

Telling other people about 'sins' and then you don't even know how things are called...

Why do you notice the splinter in your brother's eye, but do not perceive the wooden beam in your own eye?

Telling others about unwritten laws and rules and saying they are sinning? How's that?

Nobody has told about what is the best, so you can't sin against it either. You can argue about best practices, but why calling it sins if one doens't comply with it?

- Unomi -
#13 - Unomi ( Link) on 26 Mar 2008, 17:12 Delete Comment
The Sins
LOL - Some people obviously dont get the sin's analogy...

The fact that good coding practices are often treated with religious fervor is quite an apt way to title the post...
#14 - Alan Knowles ( Link) on 26 Mar 2008, 17:35 Delete Comment
Filenaming
I name my class-files .class.php because I name my interface-files .interface.php, because I have interfaces and classes in OOP. And if I have Test-Cases (for unit-tests) I call this files .test.php .. and I have them all in the same directory: foo.class.php, foo.interface.php and foo.test.php

#15 - defel ( Link) on 26 Mar 2008, 19:21 Delete Comment
Javascript dependent pages are an accident waiting to happen
@ripsup:

"Actually you can do this by using a JS front end that is only asking for data that it will mold on the clients side."

I love jQuery and ext-js, however, it is insane in my opinion to have an entire web application completely dependent on javascript for rendering content. There are too many flukes, bugs, and discrepancies between the browsers for it to come anywhere near productive.

I've tried to use js as the main content display mechanism and I end up spending more time fighting the js to get it to work in all 3 major browsers than I do everything else...combined. In addition to that, performance when you have a large amount of data to display is on par with "stupidly slow". Sending the data from the server takes 2 seconds. Then js spends the next 60 rendering the html and attaching events to it, during which the browser is eating .5 a gig of ram, or more, and 95% processor time (I'm staring at you FIREFOX).

Not to mention the headaches that are caused with each "update" from the browsers. IE is especially bad about things like that...a supposedly minor update creates a new bug that will break your site.

I'm not saying it's not possible, but it's not for me :).
#16 - Andrew ( Link) on 28 Mar 2008, 19:57 Delete Comment
I'm clean...
None of those... Well, I really DO like static methods. What's wrong with them? I think they are like Ubik, "safe when used as directed..."
#17 - Adam ( Link) on 15 May 2008, 08:56 Delete Comment
Did I understand this correctly?
The error that occurred when I tried to post, pretty much makes my point about the very poor quality of code that is AVAILABLE.

Maybe my message was too big, let me try segmenting it and see what happens?

-----------------------------

er uh lets see if I got this right.... JavaScript Sucks(true), PHP Sucks(not really), Frameworks Suck(mostly), in fact Everything Sucks!

But on the other hand, you SHOULD use all of that succky stuff just because it was already written (by someone of unknown capability) and IT IS AVAILABLE, instead of writing your own hopefully less suckky stuff??? Did I get that right???

Frankly I have yet to be impressed with PEAR; way too many inscrutable dependencies for my taste. Why brag about how many bug fixes it has? That's often a sign of some poor quality code! Do it right and you won't have so many bugs to brag about fixing.

I just wanted to use one simple thing from PEAR and it loads in gobs of stuff... I tried to hack out such things as the fancy dancy error logging that I didn't want or need and which itself pulled in a zillion other dependencies. But I ultimately found that it was easier to write my own program than to try to extract anything out of the entwined ensnared mesh of PEAR. I do think that there is some good stuff in PEAR but with a gridlocked structure like that I say No thanks. (I've even heard one of the main PEAR devs talk about that problem. He said it was a mistake but it was too late to undo it.)




Part 2: Did I understand this correctly?
okay, breaking it up into pieces seems to work... so why can't this blog program be bother to give a proper error message?

especially since the focus of this discussion is on code quality.

Part 2
------------------------

And that is the whole problem, take "PHP Classes" which you mention above. I find it's a good place for inspiration of a wide range of techniques, but most of the code there is er uh I'll be polite and call it "less than production quality code", translate to your favorite word as you will. There are a few jewels on that site but it's rare, most of it is for "demonstration purposes only".

There is little QC in most of these projects (frameworks, forums, etc) and no qualifications for joining up and writing code. It's often the ~first~ serious program that somebody has written and it shows. Hey it's great that people have an opportunity to get experience and to have fun, but don't ask me to gamble on it for production use in critical apps.

The greatest recurring nightmare of a programmer is to be dependent upon somebody else's buggy code. It bites you every time. This is even true for commercial code from places like M$. The less dependencies that I have on other peoples code the happier I am and the more likely something is to work long term reliably. Does that sound arrogant? It's not intended to be, this is just the voice of agonized experience.

Frankly, (I won't mention names) but some of the code I see in some of these big name PHP projects is downright scary. And this kind of stuff results in membership in the security exploit of the week club.

You want to see something interesting? Put some big name forums and frameworks on a server and then monitor your web logs and take a look at all of the exploits that are being probed for.


Part 3: Did I understand this correctly?
here we go again, error [invalidbody] = 1...

still trying to solve the problem, no indication of what it does not like.

Marks this blog software as... well, you figure it out.

-----------------------

At least if there is a bug in one of my programs, I know what my intentions were and it is easier to fix. But if there is a bug in someone else's program you must first expend a considerable effort to figure out their intention before you can even begin to fix it. Thus there is some validity for the 'Not Invented Here' syndrome.

Objects are Cool! Procedural is Cool! Huge Complex Programs were written in FORTRAN and Assembly a long time before objects came along. That's just an absurd notion that it can't be done. Ever heard of 'Turing Complete?'.

Objects are for Encapsulation, no more no less. If you have something that it makes sense to encapsulate then by all means go for it. You can achieve huge structural efficiencies by using objects. As far as speed concerns, these days it is generally cheaper to buy faster hardware then to expend expensive dev time to save a few millisecs -
Part 3: Did I understand this correctly?
this stupid content filter was rejecting my pithy signoff message. Not what I ask you is wrong with this???

--------

beware of prem + ature optimization..

The Jab + ber + wock Out gabe...

JavaScript
P.S. I agree with Andrew (16) above

about the horror that is JavaScript.

But unfortunately we are stuck with it and must make the best of a very bad situation. The show must go on!



Add a comment (requires javascript!)

Name
Email
Homepage
Comment Title
Comment
 
Contact me at alan@akbkhome.com