Would it be wise for someone with beginning to intermediate experience in Php to undertake learning OOP, or should I wait til I'm very good with linear code before I go about that?
Just wondering...
Would it be wise for someone with beginning to intermediate experience in Php to undertake learning OOP, or should I wait til I'm very good with linear code before I go about that?
Just wondering...
Straight in - there's really nothing difficult about it. If you can understand arrays are collections of scalar values (or other arrays) then knowing that objects are collections of data with functions that act on that data... it's not that big a leap of faith. I've never understood the problems people have with objects. I think the whole myth that object programming is difficult is because there was a bad teacher in the first place who thought his students might not get it. Quite a patronising idea to be honest.
Thanks for the quick response.
I suppose your right, from what I have learned so far it appears pretty simple.
Perhaps the real question is, is it worth using or is standard coding procedure just as fast?
SportinStyle;10882700 wrote:Perhaps the real question is, is it worth using or is standard coding procedure just as fast?
OOP is definately worth learning and using. While you can get away with not using it, it has advantages. If you need to create a bunch of related variables (properties) and functions (methods), it's much more organized. Some properties and methods can be private, meaning that there is a strict way of controlling how some things are created (which is great if you want fine control). Plus with contructors and destructors, you can have automated behaviors. Plus you can extend classes (child classes that inherit their parent classes properties and methods). While on the surface, it seems like a hassle, I think it's worse doing all those kind of things procedurally.
Overall, it's far more flexable than procedural systems. I think once you get the hang of it, you'll see the advantages are apparent.
Definately go for it
Cheers,
NRG
what's linear code? Do you mean procedural programming? http://en.wikipedia.org/wiki/Procedural_programming
Every problem can be solved with unstructured, procedural or OO solutions. The question is: which is easier to test? which is easier to maintain? which is easier to understand? which is most flexible to changes in dependencies?
I think OO stands head and shoulders above procedural programming and you should dive in. I was pretty burnt out on programming from my college days, but in 2002 I learned about OO and got all warm and fuzzy about programming again.
I agree with others who have recommended diving right in with OOP. One recommendation though is to not dive in by just learning the syntax of PHP classes and objects, but spend a little time up front learning the underlying concepts of OOP, as it is possible to write what is essentially object-oriented code without using the built-in class/object syntax, just as it is possible (and probably much easier) to write what is essentially procedural code even though you are using classes and objects. (Geez, that was one ugly sentence...hopefully it made sense?)
Nogdog said perfectly what I wanted to say last night but had too many caipirinhas in me - you can use classes and essentially be using them in a quite pointless procedural fashion, and I've seen loads of tutorials on the net that do just that, and have made me quite angry (yeah, that's hard to do). It's good to find examples that show what oop programming really makes easy, then you start to get more out of it. You'll soon come across the term 'design patterns' which are really good to look into to get a good idea of how objects can interact in a good way, but of course there are tutorials out there that even get that totally wrong.
I've recommended this before: http://devzone.zend.com/node/view/id/3
and I like the tutorial style of Quentin Zervaas at phpriot, it's concise, not reapeating itself again and again and again. This for example is quite nice: http://phpriot.com/articles/databaseobject-intro and the databaseobject class used in it is a good example of extras that objects make easier.