OO vs. Procedural

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

Post Reply
User avatar
evilmonkey
Forum Regular
Posts: 823
Joined: Sun Oct 06, 2002 1:24 pm
Location: Toronto, Canada

OO vs. Procedural

Post by evilmonkey »

Hello. I've been coding in PHP for about 2 years now, doing mostly databasing. Up until now, I've been using strictly procedural approaches to my problems, and it worked fine. I'm now in a position where I have to develop a big project using PHP4's OO capabilities. I've read a lot of tutorials and sections of books on this topic, but now I want to hear from people. Which style do you use and why. Also, any tips for a coder migrating from procedural to OO are greatly appreciated.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I try to use OO for the most part. Although it takes a bit more time for initial set up of 1 instance, the general level the implementations are is great for reuse..
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Post by infolock »

OO is definately the way to go imo.. considering all the scripts you'll make in the future that can use this class' login functions, it's table/frame builds, loops, etc, you are going to find it not only to be a nicer way to keep all your functions in one file, but also that it will save you on time.

basically, if ur going to be reusing a lot of custom/redundant functions in more than one place, classes are the only way to go. otherwise, u'll just be wasting your time imo.
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

OO is the only way to go for large projects (>~1M lines of code) imo.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I have to absolutely, hands-down, agree with Weirdan on that. There no faster way to get into trouble in a large project than to not use classes/objects and OOP.. unless you're a very gifted professional
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

this tiny shell script can help you to decide whether you need to switch or don't:

Code: Select all

lines=`(find ./ -name *php -exec wc {} \;) | awk '{as=as+$1;}
END {print as}'`;
if ї $lines -gt 1000000 ]; then 
	echo \&quote;You need to switch to OOP NOW! \&quote;; 
elif ї $lines -gt 100000 ]; then 
	echo \&quote;Go buy some books on OOP, you'll need to swith soon! \&quote;; 
else 
	echo \&quote;You can live without OOP... for some time ;)\&quote;;
fi
Run it in the directory under which all your php files located and it will tell you :lol:
Last edited by Weirdan on Thu Jul 14, 2005 9:32 am, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

heheh nice one Weirdan..

CONGRATS ON 1000 POSTS!
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

feyd wrote:heheh nice one Weirdan..
Mine told me I needed some books ;)
feyd wrote: CONGRATS ON 1000 POSTS!
Thanks 8)
User avatar
evilmonkey
Forum Regular
Posts: 823
Joined: Sun Oct 06, 2002 1:24 pm
Location: Toronto, Canada

Post by evilmonkey »

Thanks for the input, looks like I have to learn OOP in PHP. Got suggestions on resources?

Thanks!
User avatar
nigma
DevNet Resident
Posts: 1094
Joined: Sat Jan 25, 2003 1:49 am

Post by nigma »

basic tutorial on oop in php4
----------------------------------
part 1: http://www.onlamp.com/pub/a/php/2002/07 ... tions.html
part 2: http://www.onlamp.com/pub/a/php/2002/08 ... tions.html
User avatar
evilmonkey
Forum Regular
Posts: 823
Joined: Sun Oct 06, 2002 1:24 pm
Location: Toronto, Canada

Post by evilmonkey »

Thanks Nigma, I'll read those. :)
Post Reply