Jump to content

OOP vs Procedural

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
38 replies to this topic

#1
Guest_Jordan_*

Guest_Jordan_*
  • Guests
Which do you prefer, Object Oriented Programming or Procedural? Why?

I prefer OOP. I like the ability to reuse code and the idea of a class makes more sense to me. Procedural code also has a bad habit of turning into spaghetti code.

Some project I develop in PHP, it makes more sense to use Procedural style, however. For larger projects I feel that OOP is critical in order to develop code that is easily expandable.

What about you?

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
I think it's something of a false distinction. OOP Methods are generally procedural, for example. See my upcoming OOP tutorial (not yet released) for more ideas :)
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
BlaineSch

BlaineSch

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,448 posts
Awaiting that tutorial WP =)

#4
marwex89

marwex89

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 10,720 posts
OOP is my favourite, I think. It seems to be a great tool to solve problems in a logical and clear way. Yet, I wouldn't turn down procedural programming. OOP can be a bit overkill at times.

Spaghetti-code, on the other hand, is absolutely awful. I've done it, and it is a nightmare both to maintain and expand. :eek:
Hey! Check out my new Toyota keyboaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

#5
chili5

chili5

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 7,247 posts
Objects

I like the idea of being able to reuse code as well. Lately I've found a use for object inheritance and it makes programs so easy to maintain. I don't know if procedural code can be written in a way that would be any easier to maintain. I haven't written much code that is "procedural".

#6
amrosama

amrosama

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 8,674 posts
well, i really like OOP
but i find myself coding in Procedural style, specially in PHP , i mostly write set of related functions in a php file and include that file when i need them. im currently trying to be OOP person its seems easy when people talk about funny objects like "human" have hands and legs as private variables blah blah blah.... but in reality i find it hard to do a class for actual stuff
yo homie i heard you like one-line codes so i put a one line code that evals a decrypted one line code that prints "i love one line codes"
eval(base64_decode("cHJpbnQgJ2kgbG92ZSBvbmUtbGluZSBjb2Rlcyc7"));
www.amrosama.com | the unholy methods of javascript

#7
PythonPower

PythonPower

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 230 posts
The only thing OOP adds is code reuse whether by generality, easy extension or whatever.

#8
John

John

    Writes binary right handed and hex left handed

  • Moderators
  • 6,321 posts
OOP is great. What you can do in three lines of procedural code, I can do in fifty lines of OOP.
<?php


interface greeting {

    public function hello();	

}


class hello implements greeting {

	

	public function hello() {

		return "Hello ";

	}

	

	public function __toString() {

		return $this->hello();

	}

}


class say {

    private $a;

    public function say($a) {

		$this->a = $a;

		return $a;

	}

	

	public function __toString() {

		return $this->a;

	}


}


class expression {

	

    public function __construct( greeting $a, say $b, $c ) {

		echo $a . $b;

		switch($c) {

			case "exclamation":

			    echo "!";

				break;

			default:

				echo ".";			

		}		

	}

	

}


new expression(new hello(), new say("World"), "exclamation");


?>

One of the problems many people face when it comes to object oriented programming is the whole notion of an object. Many inexperienced programmers will get carried away and represent an entity as an object when there is no need to (like the exaggerated example above). A few months ago I was a strong advocate of OOP, not because you can use objects, but because of design patterns and the beautiful architectures you can create. However, as WingedPanther pointed out these patterns and architectures can just as easily be implemented procedurally. That being said, I don't prefer either. I use what is right for the job.

#9
NatalieM

NatalieM

    Learning Programmer

  • Members
  • PipPipPip
  • 77 posts
As I'm teaching myself programming, I really like the concept of OOP so I voted for that but at the moment, I mostly do procedural. However, as I'm dreaming up more and more complex programs, I can totally see the power of OOP.

But even if you love OOP, It seems to me though that procedural programming has a place as OOP can be a bit overkill as some others have pointed out (loved your example John :lol:)

#10
cdg10620

cdg10620

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 389 posts
OOP is definitely the way to go. Code re-use is a major thing for me. If I can write a method only once and use it in multiple places, that means less work for me. :)
-CDG10620
Software Developer

#11
zeroradius

zeroradius

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,406 posts
I do procedreal and than use includes so that I can reuse the procedral code. I never took the time to learn OOP and procedral works just fine for me so I will stick with that until i get a job and they fource me into OOP
Posted Image

#12
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
Why is it that people assume OOP = reusable, but procedural = forced recode?
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog