Every where I look, every popular PHP Application uses functions for most of the functionality. I ask why? Why not a completely class based application? It seems that it doesn’t ‘scale’ well. Why doesn’t it scale well?
Applications: Who Uses them and Who Doesn’t
Forums
You look at Simple Machine Forums and it is a forum that kicks major ass. All of the functionality is in functions. Even phpBB only uses a few classes for the underlying user and database features.
There Are complete OO based Forum packages, but they aren’t at the level of SMF or phpBB. If class based architecture is so easy to develop, why aren’t more people jumping onto them?
Simple Site
I would group this into an Object-Oriented Class Package. Yeah, of course, the developer made it to make his coding projects easier and conform to their standards. Unlike other CMS where they have to be all things to all people (and fail at it). Um, I think it will be neat and I will try to learn and see how well it goes. However, it is now on the back burner after all of the other projects I have to complete. If I ever start doing this professionally, then I’ll be sure to look this up.
Serendipity
Again, class and function based architecture. Which shouldn’t be bad, WordPress is the same way. Um, I don’t know, I like it actually.
Why I Hate Functions
Classes allow you to group like functions in an easy place without having to pass the same data around. Take SMF Registering for example, there is Register1 and register2. Hmm, that is interesting, is it possible to call register2 before? Most likely no without having to look at the code inside. It would be better, I think, if the names had some sort of description that told me what the function does instead of what order to call the functions in. Where do I call register1 and register2? On the same page or on different pages?
When it Works
The issue is finding and calling the correct function. You could place every function in a new file or you could group like functions in the same file. Doing the latter would negate class structure if you use good naming conventions, register1 and register2 don’t really work for me.
Use of Globals, use $GLOBALS superglobal. If I see
global $variable
in a group of functions, I’ll just refactor it into a class. Save time, headache and maybe bugs. The nice thing about classes is its use of the $this that allows you to access methods and variables. $this variables are automatically global to the class and other classes if public or var.
Functions Purpose
Functions do allow you to group class functionality to make it easier for developers to do common tasks. You can do this using another class also, but it would probably have to be static.
Java is Object Sexy
God, I loved Java when I was working with it. It was bliss it was heaven. To bad I don’t code in it anymore. You know, I like using what I know and since I can’t do any JavaServlets on Dreamhost (those bastards) I don’t see the point. Also, I read that JavaServlets are slower than PHP code, which I have witnessed on the school server.
Damn Java and its Descriptive Method Names
I hated having to write out a long string of text just to get input from the console and output text to the console. usually you would break down and just copy and paste the function as you would use it often enough.
It is good naming convention and I suppose I’m just contradicting myself, but if I have to type 100 characters just to do a common task then something needs to be done. Oh yeah! Ha ha. Oh man, I remember another guy broke down and wrote a new class that did just that. I was thinking about it and thought he was insane, then I did it myself.
Objects Just Aren’t Fast Enough
Java is optimized completely for objects and you can get performance for console applications to the same level as C++. GUI applications give Java a bad name because of the APIs used are not done well enough. This could be corrected with preloading and multitasking (which is easy-ish in Java).
PHP is not optimized for classes, which is why many opt-out of building complete object application. PHP 5 added features to take it to the level of other languages that support classes. I believe it isn’t that simple to do however and it may take a while before it is done.
The ability to assign class variables as private, protected, and public are great and a step up from just var in PHP 4, but I need speed like what I would get if I didn’t use classes. There will always be overhead when classes are used, some languages may minimize the overhead, but it is worth the overhead for the ability to assign visiblity for variables and functions.
To say, “You don’t call this method… bitch!” Or “Nope, this variable is private. Step back and talk to the middle finger.” Is a great, but I want speed.
I suppose I’m just power hungry. I have been thinking of Ruby lately to see how well it handles objects and classes. From what I have seen so far, it does it well.
Possibly Related Posts:
- Bullet: E-Book Library Management and Content Server
- Using ZendFramework 2 beta1 For Directory Project
- The Way of Kings and Cosmere Theory
- “In Time” Movie Premise Flawed
- Completing HTTP Library For PHP
Comments are closed.