PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Tue Jun 25, 2019 5:57 pm

All times are UTC - 5 hours




Post new topic Reply to topic  [ 10 posts ] 
Author Message
PostPosted: Thu Jul 11, 2013 11:53 am 
Offline
Forum Newbie

Joined: Wed Jul 10, 2013 6:26 am
Posts: 5
Hi

I am learning php and see that most beginner tutorials and books start with procedural programming.

After looking at OOP I am thinking why not just delve into OOB before messing around with procedural programming if OOP will be the eventual goal?

Would it not be better to just go straight into Object Oriented Programming from the start?


Any thoughts on this?


Top
 Profile  
 
PostPosted: Thu Jul 11, 2013 12:41 pm 
Offline
Spammer :|
User avatar

Joined: Wed Oct 15, 2008 2:35 am
Posts: 6617
Location: WA, USA
Same reason you would want to learn to drive on surface roads before you go onto the highway: solid foundations.


Top
 Profile  
 
PostPosted: Thu Jul 11, 2013 1:14 pm 
Offline
Forum Newbie

Joined: Wed Jul 10, 2013 6:26 am
Posts: 5
Still doesn't really answer my question

Is it not possible to learn the solid foundations while using classes and objects?

For example if i call a function inside of a class assigned through a made object rather than just a function on it's own(procedural style). Would it not be better to start learning this way?

Am i missing something here?


Top
 Profile  
 
PostPosted: Thu Jul 11, 2013 1:22 pm 
Offline
Spammer :|
User avatar

Joined: Wed Oct 15, 2008 2:35 am
Posts: 6617
Location: WA, USA
It is, but you're going to be spending most of your effort learning OOP.

I'm not saying you can't do it but that I, personally, would rather people had a solid foundation in procedural PHP before they went off and learned PHP+OOP. Because at some point you're writing procedural/linear code and if you don't know how to do that well enough you'll be writing weird OOP code.


Top
 Profile  
 
PostPosted: Thu Jul 11, 2013 4:06 pm 
Offline
Site Administrator
User avatar

Joined: Wed Aug 25, 2004 7:54 pm
Posts: 13590
Location: New York, NY, US
I think if you understand the history and definitions a little, you will understand why to start with OOP. By "procedural programming" I think you actually talking about a combination of the initial improvements in Imperative Programming -- which are Structured Programming, Procedural Programming and Modular Programming. Imperative Programming is the style we commonly use in which we describe what the program does, instead of the goal. Structured Programming add the common loop and logical constructs to reduce the need for gotos; Procedural Programming added sub-routines with parameters and return values; Modular Programming added packaging concepts. OOP adds classes and opens up a whole world of new concepts and patterns enabled by having objects (data structures plus the code that operates specifically on them). OOP subsumes Structured, Procedural and Modular Programming, so by learning OOP you are learning "procedural programming" (as you called it) as well.

tl;dr Yes

_________________
(#10850)


Top
 Profile  
 
PostPosted: Sat Jul 13, 2013 6:48 am 
Offline
Forum Newbie

Joined: Wed Jul 10, 2013 6:26 am
Posts: 5
Thanks Christopher

That was something along the lines what I was thinking but you expressed it much better.

This view seems hard to find.


Top
 Profile  
 
PostPosted: Sat Jul 13, 2013 10:49 am 
Offline
Site Administrator
User avatar

Joined: Wed Aug 25, 2004 7:54 pm
Posts: 13590
Location: New York, NY, US
dazzy wrote:
This view seems hard to find.
For me, the strangest thing about programming is that most Best Practices are very counter-intuitive. So much so that most people when they start programming find what they are being told so incredible that they just go ahead with what seem completely obvious to them. Then they discover that their solutions really don't work very well, but they gain understanding of the problems in programming. As their understanding improves the originally counter-intuitive Best Practices seem more plausible. And they more often produce successful, changeable and maintainable implementations. By that point the counter-intuitive seems intuitive due to having done it the wrong way so many times. That's why there seem to be this endless debate between stubborn pro-procedural newcomers and incredulous pro-OOP veterans.

_________________
(#10850)


Top
 Profile  
 
PostPosted: Sat Jul 13, 2013 7:18 pm 
Offline
Forum Contributor
User avatar

Joined: Wed Apr 14, 2010 4:45 pm
Posts: 375
Location: UK
dazzy wrote:
For example if i call a function inside of a class assigned through a made object rather than just a function on it's own(procedural style). Would it not be better to start learning this way?

Am i missing something here?


I think what you're missing there is the fact that calling a function inside of a class is (by definition) harder than just calling a function - if you don't understand how to write a function, what chance have you got of writing a class that calls that function correctly? Arguments are also a lot easier to get your head around than properties - passing a variable to a function is fundamentally simpler than deciding what visibility a property in your class needs - is it meant to be public, protected, or private? does it need to be declared statically? - and then figuring out a way to assign a value to that property and accessing it inside your class.

I will admit that it took me a little while to get a handle on what the benefits of OOP were for my projects, but up until that point I had been writing perfectly good, maintainable scripts that did exactly what I wanted (albeit in Perl rather PHP, back when flat files were all the rage). PHP has form in this area - the barrier to entry is very low (which is good) but this also means that people who get into PHP don't always have a solid foundation in the programming concepts that someone who learned C++ or Java at college/university has. As with anything like this, just do what works for you - anyone who wants to learn PHP programming in a formal programming environment will learn about OOP soon enough anyway, and everyone else will just have to make the effort to get up to speed as and when their projects demand it.

Mecha Godzilla


Top
 Profile  
 
PostPosted: Sun Jul 28, 2013 5:06 pm 
Offline
Forum Commoner
User avatar

Joined: Thu Dec 15, 2011 2:40 pm
Posts: 85
Location: Nelson, NZ
Quote:
Why not learn OOP before Procedural?


One of the major points of OOP is to make it more efficient to manage a team of programmers. But can you say today that you will always be managed, working in a team?

When working around the house, the bloke who can't do anything without reaching for his whizz-bang powerdrill and compound-angle mitre saw is actually handicapped. It's eye-opening what a good handyman (and I'm not claiming to be one) can do with a plain hammer, saw, spanner etc.

But it all depends on the context in which you're planning to work. If you're only going to work in teams for big outfits that build houses on standard plans, then it matters less how skilled you are with basic tools. You may not even have much choice as to which tools to use. And that makes sense, because standards make it easier for people to work together, to ensure it's done the same way every time, to inspect, etc...
The guys who work by themselves on custom projects, however, have more latitude in their choice of tools.


Top
 Profile  
 
PostPosted: Wed Oct 23, 2013 1:55 pm 
Offline
DevNet Resident
User avatar

Joined: Sat Jun 08, 2002 1:24 pm
Posts: 1207
Location: Florida
I do believe that there is one big potential problem with focusing on OOP early. That is that it seems to encourage a view point that is purely OOP. By that I mean, there are no algorithmic or lower level considerations.

Lego programming! :D

A small example that I saw only yesterday is where the programmer essentially had 4 steps to do for registering a user with a given system. For each step he instantiated a new object that took care of the particulars of that step. That's not really bad if you ask me. However, each object required the same information. What he did in this case was make a request to the data store 4 times for each object for the same data!

:lol:

So in terms of seperation of concerns he was right on the money, but why not just request that data once then pass copies of it (by reference if needed) to each object at instantiation or right after?


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group