PDA

View Full Version : When to Learn OOP


nisim7
05-10-2005, 12:35 PM
I am currenlty learning PHP and am quickly getting the basics down. I have no prior programming experience and the concept of OOP is a bit much for me currently. So I was wondering, in your most humble opinions, at what skill level should one really worry about learning OOP? I'm still working on fully getting the concepts of functions, muti-dimensional arrays, etc down so I'm assuming now (beginner level) would not be the most wise time to focus on it.

Any suggestions?

Nisim

darksidepuffin
05-10-2005, 01:07 PM
My suggestion is...start learning OOP when your comfortable with general and universal programming concepts. For example...when you can tell me, ver batim...without reading the manual...what the "general" data types, control structures, declarations, etc. in PHP are...then you should look into OOP.

You see Nisim, OOP shouldn't be taken as an 'extension' to PHP...it's a general programming concept which can be applied to many languages (Java, Ruby, C#...etc) -- the idea when learning OOP isn't to say "mmkay..in PHP...a class is " it should be "In OOP...classes are [blah]"....when you do learn OOP...you should learn it as an open concept -- not as a PHP specific 'operation', that way..if a year from now or such you choose to change languages..your mind doesn't go "but...I only knew how to do that in PHP :("...sure..the specific items used will be different (eg: PHP's syntax will be different from that of, for example, Ruby..and even languages with similar syntax [eg: "c syntax"] will have different rules [eg: data types, exceptions, catch/throw error handling, etc.])...the concept is the same.

OOP in itself isn't a difficult topic...but it does require practice..and...really...implementation..to understand not only [b]how to do it..but...why. If you don't know why you'd use OOP...you won't have any reason to use OOP properly.

I used to write all my php code procedural...until about 1.5 - 2 years ago...I learned OOP concepts..and never looked back.

If you have any specific questions -- feel free to post or pm me..I'd be more than happy to answer them to the best of my knowledge.

Just for reference...I write my PHP code in OOP almost exclusively...you could say I'm OOPsessed -- but...Brian[Scoutt] for example, uses both. Comparing my code to Brian's would be like comparing someone's printing to someone elses handwriting. Both are entirely valid...but the implementations and methods used to produce results are different.

Procedural is an entirely valid way to code...but I think that if you get a handle on OOP..you will embrace it with open arms.

Horus_Kol
05-11-2005, 03:10 AM
Also, I would suggest finding another OOP (such as PHPmailer - which is open source) which lets you actually understand how the different parts of objects and classes work to produce a final result.

They tried to teach me OOP at uni, but were too abstract about it - and I only got it after seeing actual programs do their thing.

darksidepuffin
05-11-2005, 05:17 AM
You make an excellent point, Stuart. I don't know how many times I've read explainations of OOP which were more confusing than looking at php code with no whitespace and all letters converted to Kanji. I mean, I'm sure the authors mean well...but what, honestly, is helpful about:


Imagine a car manufacturer, they make 'cars', different types of 'cars' might be sedans, trucks, suvs, minivans, sports cars..but they all have certain components which remain the same.....blahblahblahblahblah


We don't care about the relationship between car designs -- what we care about is how to use OOP in atchual programming.

So as Stuart pointed out -- look around at OOP code, and lots of it. Try to understand why it's designed the way it is. I'm positive that even if you asked here -- both myself and the other OOP users would be quite willing to give you some examples of OOP concepts -- but it may be worth looking into a script your familiar with, or have at least used before. That way you can go "oh..so thats why..." rather than "nice..but whats the point of this code?".

torrent
05-11-2005, 01:32 PM
Don't use PHP to learn OOP. Learn OOP then apply it PHP (especially the case with verison 5). It is vitally important that you gain a full understanding of the OOP concepts first and these can be learned online, or through books. Once you actually understand OOP and are ready to apply it then start using it in PHP. Otherwise you are trying to learn two things at the same time, both of which are vast subjects in their own right.

darksidepuffin
05-11-2005, 01:34 PM
Don't use PHP to learn OOP. Learn OOP then apply it PHP (especially the case with verison 5). It is vitally important that you gain a full understanding of the OOP concepts first and these can be learned online, or through books. Once you actually understand OOP and are ready to apply it then start using it in PHP. Otherwise you are trying to learn two things at the same time, both of which are vast subjects in their own right.

Precisely what I said -- except in a more compact form :P

torrent
05-11-2005, 01:39 PM
yeah, apologies for that. I was a bit too lazy to read it. :dunce2:

nisim7
05-11-2005, 02:27 PM
Thanks guys, This is sort of what I thought but without the passion and emotion of years of experience behind it ;-)

My plan is to move to C++ once I have fully grasped PHP and I know I'll learn OOP there. I would have started with C++ in the first place but being a web developer (at least in some capacity) I knew that PHP was more immediate.

Nisim

AaronCampbell
05-12-2005, 10:56 AM
nisim7: If you are goig to learn C++ next, you might want to seriously consider getting a C++ basics book, and trying some of the samples now. In this way, you can see some of the fundamental differences. If you were going the other way (C++ first...PHP later), I wouldn't say anything, but C++ is more strict than PHP in many ways, the first coming to mind is variable types. In PHP you can do:$var = 5; //$var is an int
$var = 5.5; //$var is now a float
$var = "String"; //$var is now a string
$var = array(1,2,3); //$var is now an arrayIn C++, you have to tell is WHAT a variable is when you first declare it:int var = 5; //var is an int
var = "test"; //YOU CANNOT DO THIS...you can't pass a string to an int.Also, " and ' aren't the same, etc, etc.

Since you plan on going from something flexible to something strict, knowing the basics of the stricter of the 2 will help you NOT develop bad coding practices that will hinder you later. You can find books pretty cheap, and many of them include a CD with a C++ compiler (in case you aren't using *nix, which includes one).

nisim7
05-12-2005, 03:08 PM
I few years ago I bought a couple of C++ books to try and learn it. The problem with them (although they were marked as beginner books) is that the authors assumed that the reader had some sort of programming experience and they rushed through the materials of the books, just giving syntax and rules but never really explaining programming concepts. I then bought a Basic book that seemed to explain things slower and more indepth but I was running FBSD at the time and my wife hogged my windows box. I found a few Basic compilers for *nix but none that were really what I was looking for.

I decided that if the authors (mainly the C++ ones) were going to assume that I had some programming experience then I would get some weighed out Perl, Python, and PHP. Tried them all out a bit and liked PHP the most (probably seeing that I've been doing web design for about six years). But, once I'm comfortable with PHP I will at least have the concepts of programming down once I go back to C++. Thank you for your advice.

Nisim

Horus_Kol
05-13-2005, 02:46 AM
Get yourself the Jamsa C/C++ Programmers' Bible - it takes you right from "where's the any key?" through to a good foundation for Application software...

darksidepuffin
05-13-2005, 05:23 AM
Yeah..I find a lot of new programmers ask me for book ideas..I say, fairly bluntly "none". Why?Because if they're looking for a full explaination -- 99.9% of books fail. I mean -- you can get a better explaination of programming concepts from any number of people here, than you can from a $65-$80 book.

Horus_Kol
05-13-2005, 06:36 AM
i dunno - for c/c++ stuff, my first port of call is always my trusty Jamsa - got me through uni that book did :P