Author Topic: The benefits of OOP  (Read 6669 times)

0 Members and 1 Guest are viewing this topic.

Offline AngelFish

  • Is this my custom title?
  • Administrator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3242
  • Rating: +270/-27
  • I'm a Fishbot
    • View Profile
The benefits of OOP
« on: June 23, 2011, 05:57:43 pm »
I've been curious about what tangible benefits Object Oriented Programming offers over normal procedural programming [for some unknown but competent programmer], since everyone seems to rave about it.

From what I understand, OOP basically expands upon the idea of a class that's effectively a general classification of objects. To create objects, you instantiate them from their classes. This is actually very similar to a problem I solved in Khavi where multiple threads have to be created that are very similar to each other. However, since Khavi is written in a procedural language (ASM), I couldn't just instantiate from a class. My solution (which took remarkably little code) was just to treat the initial primary thread as an array of bytes and do a simple array copy to another location in RAM.

As for objects, I don't see why they're any different than subroutines with argument passing. You pass the arguments to the methods, which operate on them and change the state of the object, precisely as subroutines do to the program state in procedural programming. This also brings up the point of data encapsulation, which I honestly can't fathom a reason for as long as the programmer is competent enough to properly debug their code (or not do stupid things like arbitrarily change the arguments the function requires).

Another argument I see for OOP is code re-usability, which touches on several things, most notably inheritance. Inheritance can be fully implemented in any reasonable procedural language with a simple subroutine call or copy and paste. A subroutine call doesn't take much more code than a declaration of inheritance. However, if you want to re-use code across different projects, it would seem that classes are good as black boxes, right? If you think about it for a minute, the most widely re-used code in existence, the C standard library, is entirely procedural. It's also incredibly simple to use, effective, and a nice black box to most programmers.

Packages are another story. What benefit is there to using hundreds of classes over using subroutines or subprograms? Almost every operating system ever written has a library of some sort. That's represented procedurally and yet people maintain operating systems for years. Same for pretty much every library.

"Self Documenting code:" My general view on self-documenting code is that when you go to maintain it in ten years, it won't seem so self-documenting. Use comments. They're there for a reason.

"Maintainability:" If your code is well written, maintenance should be relatively straightforward.


So, can anyone try to explain what benefits there are to OOP? I feel like I must be missing something if so many people rave about it (And it's taught in every software school).
∂²Ψ    -(2m(V(x)-E)Ψ
---  = -------------
∂x²        ℏ²Ψ

Offline ben_g

  • Hey cool I can set a custom title now :)
  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1002
  • Rating: +125/-4
  • Asm noob
    • View Profile
    • Our programmer's team: GameCommandoSquad
Re: The benefits of OOP
« Reply #1 on: June 23, 2011, 06:06:15 pm »
OOP is usually easyer and makes your code clearer, but is mostly a tiny bit slower than 'normal' programming
My projects
 - The Lost Survivors (Unreal Engine) ACTIVE [GameCommandoSquad main project]
 - Oxo, with single-calc multiplayer and AI (axe) RELEASED (screenshot) (topic)
 - An android version of oxo (java)  ACTIVE
 - A 3D collision detection library (axe) RELEASED! (topic)(screenshot)(more recent screenshot)(screenshot of it being used in a tilemapper)
Spoiler For inactive:
- A first person shooter with a polygon-based 3d engine. (z80, will probably be recoded in axe using GLib) ON HOLD (screenshot)
 - A java MORPG. (pc) DEEP COMA(read more)(screenshot)
 - a minecraft game in axe DEAD (source code available)
 - a 3D racing game (axe) ON HOLD (outdated screenshot of asm version)

This signature was last updated on 20/04/2015 and may be outdated

Offline tloz128

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 324
  • Rating: +58/-6
  • I feel asleep.
    • View Profile
Re: The benefits of OOP
« Reply #2 on: June 23, 2011, 06:06:57 pm »
It is possible to do everything that can be done in OOP with procedural programming, but that is not where the benefits come in.

Let's say, for instance, that you are working with a large group of people on a very large project, and that each person is assigned a different part of the code. Abstraction through OOP makes it so that each programmer does not need to know the specifics of how everything works. Rather, everything is simplified so that only what is required can be seen, making the code much less of a hassle to understand.
Also, classes are excellent organizational tools. For example, I find them very useful for making enemies in games.

In short, OOP provides no functional benefits, but organizational.
« Last Edit: June 23, 2011, 06:07:42 pm by tloz128 »
Naaa... Na Nah Na Nana Na Nah... Hey Jude!

Offline AngelFish

  • Is this my custom title?
  • Administrator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3242
  • Rating: +270/-27
  • I'm a Fishbot
    • View Profile
Re: The benefits of OOP
« Reply #3 on: June 23, 2011, 06:11:49 pm »
@Ben: I don't think anyone is going to argue that Java (OO) is easier than TI-BASIC (Procedural). Ease of understanding really depends more on the language's syntax than the paradigm.

EDIT: @tloz: I understand that class are organizational, but how are they better in that aspect from subroutines with documented variable use?
« Last Edit: June 23, 2011, 06:12:36 pm by Qwerty.55 »
∂²Ψ    -(2m(V(x)-E)Ψ
---  = -------------
∂x²        ℏ²Ψ

Offline tloz128

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 324
  • Rating: +58/-6
  • I feel asleep.
    • View Profile
Re: The benefits of OOP
« Reply #4 on: June 23, 2011, 06:20:25 pm »
@Ben: I don't think anyone is going to argue that Java (OO) is easier than TI-BASIC (Procedural). Ease of understanding really depends more on the language's syntax than the paradigm.
If I may chime in, it would be a nightmare to write any really large project in TI-BASIC.

EDIT: @tloz: I understand that class are organizational, but how are they better in that aspect from subroutines with documented variable use?
Like I said, there are no functional benefits over procedural programming. But, having worked with both documented subroutines and classes before, classes are far superior. The layers of abstraction they provide keep the code organized and manageable.
Naaa... Na Nah Na Nana Na Nah... Hey Jude!

Offline nemo

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1203
  • Rating: +95/-11
    • View Profile
Re: The benefits of OOP
« Reply #5 on: June 23, 2011, 06:21:14 pm »
supposedly the benefits of OOP come in on large projects, but overall OOP projects require much more time planning how classes interact with each other. IMO OOP gets in the way when i code. i really only use java over C/C++/functional programming languages because i can't find an easy to install GUI library. so i agree with Qwerty. programs being programmed by 1 person aren't large enough to reap the benefits of OOP, and for larger scale projects i can't say because i've never programmed in a team.


Offline ben_g

  • Hey cool I can set a custom title now :)
  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1002
  • Rating: +125/-4
  • Asm noob
    • View Profile
    • Our programmer's team: GameCommandoSquad
Re: The benefits of OOP
« Reply #6 on: June 23, 2011, 06:28:13 pm »
With large projects, OOP is much easyer to find the piece of code you should work at becouse you can store the classes in different folders so you won't have to spend 70% of your time by scrollingto the code you want to edit.

I'm working at a large project with java, and it has got a total of abouth 15000 lines of code, but becouse they are arranged in five different classes, the files only have got an average of 300 lines. This is much easyer to find the code you need
My projects
 - The Lost Survivors (Unreal Engine) ACTIVE [GameCommandoSquad main project]
 - Oxo, with single-calc multiplayer and AI (axe) RELEASED (screenshot) (topic)
 - An android version of oxo (java)  ACTIVE
 - A 3D collision detection library (axe) RELEASED! (topic)(screenshot)(more recent screenshot)(screenshot of it being used in a tilemapper)
Spoiler For inactive:
- A first person shooter with a polygon-based 3d engine. (z80, will probably be recoded in axe using GLib) ON HOLD (screenshot)
 - A java MORPG. (pc) DEEP COMA(read more)(screenshot)
 - a minecraft game in axe DEAD (source code available)
 - a 3D racing game (axe) ON HOLD (outdated screenshot of asm version)

This signature was last updated on 20/04/2015 and may be outdated

Ashbad

  • Guest
Re: The benefits of OOP
« Reply #7 on: June 23, 2011, 06:31:06 pm »
I think that life can go on without OOP, but it is very useful.  I use it all the time to make easy-to manipulate instances which can have entirely different command sets yet be similarly-functioning, which can be appended to applications in the same way primitives can, but have even more benefits.

Offline Spyro543

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1189
  • Rating: +74/-3
    • View Profile
Re: The benefits of OOP
« Reply #8 on: June 23, 2011, 06:34:53 pm »
I've only coded in Python and HTML, and HTML really isn't much of a programming language, but I think OOP can just get in the way of things and even make a project harder.

Offline ben_g

  • Hey cool I can set a custom title now :)
  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1002
  • Rating: +125/-4
  • Asm noob
    • View Profile
    • Our programmer's team: GameCommandoSquad
Re: The benefits of OOP
« Reply #9 on: June 23, 2011, 06:38:17 pm »
I've only coded in Python and HTML, and HTML really isn't much of a programming language, but I think OOP can just get in the way of things and even make a project harder.
Wait, isn't python object oriented?

btw: HTML isn't a programming langue at all, it's a text markup langue, like BBcode
My projects
 - The Lost Survivors (Unreal Engine) ACTIVE [GameCommandoSquad main project]
 - Oxo, with single-calc multiplayer and AI (axe) RELEASED (screenshot) (topic)
 - An android version of oxo (java)  ACTIVE
 - A 3D collision detection library (axe) RELEASED! (topic)(screenshot)(more recent screenshot)(screenshot of it being used in a tilemapper)
Spoiler For inactive:
- A first person shooter with a polygon-based 3d engine. (z80, will probably be recoded in axe using GLib) ON HOLD (screenshot)
 - A java MORPG. (pc) DEEP COMA(read more)(screenshot)
 - a minecraft game in axe DEAD (source code available)
 - a 3D racing game (axe) ON HOLD (outdated screenshot of asm version)

This signature was last updated on 20/04/2015 and may be outdated

Offline Spyro543

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1189
  • Rating: +74/-3
    • View Profile
Re: The benefits of OOP
« Reply #10 on: June 23, 2011, 06:39:36 pm »
Yes, Python is OOP.

Offline ben_g

  • Hey cool I can set a custom title now :)
  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1002
  • Rating: +125/-4
  • Asm noob
    • View Profile
    • Our programmer's team: GameCommandoSquad
Re: The benefits of OOP
« Reply #11 on: June 23, 2011, 06:44:48 pm »
then why are you programming in python? You just said you think that OOP can make a project harder?

but anyway, just program what you like. Maybe OOP makes the code easyer to understand, and maybe prodecural programming lets you avoid the difficulties with the objects interacting, Programming in a langue you like is the way to succes.
My projects
 - The Lost Survivors (Unreal Engine) ACTIVE [GameCommandoSquad main project]
 - Oxo, with single-calc multiplayer and AI (axe) RELEASED (screenshot) (topic)
 - An android version of oxo (java)  ACTIVE
 - A 3D collision detection library (axe) RELEASED! (topic)(screenshot)(more recent screenshot)(screenshot of it being used in a tilemapper)
Spoiler For inactive:
- A first person shooter with a polygon-based 3d engine. (z80, will probably be recoded in axe using GLib) ON HOLD (screenshot)
 - A java MORPG. (pc) DEEP COMA(read more)(screenshot)
 - a minecraft game in axe DEAD (source code available)
 - a 3D racing game (axe) ON HOLD (outdated screenshot of asm version)

This signature was last updated on 20/04/2015 and may be outdated

Offline AngelFish

  • Is this my custom title?
  • Administrator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3242
  • Rating: +270/-27
  • I'm a Fishbot
    • View Profile
Re: The benefits of OOP
« Reply #12 on: June 23, 2011, 06:45:23 pm »
With large projects, OOP is much easyer to find the piece of code you should work at becouse you can store the classes in different folders so you won't have to spend 70% of your time by scrollingto the code you want to edit.

I'm working at a large project with java, and it has got a total of abouth 1500 lines of code, but becouse they are arranged in five different classes, the files only have got an average of 300 lines. This is much easyer to find the code you need

Khavi, the project I mentioned in my first post, as approximately 4000 lines of code at the moment*. The code is currently divided into 3 subprograms and it takes me around 15 seconds to find the code I'm looking for. I'm not sure that putting

Code: [Select]
public static void main()
{
      Something
}

 significantly improves your code's organization above "#include <file.s>" or ".macro"

*I assume you meant 1500 lines of code, not 15000, because 300*5= 1500.
« Last Edit: June 23, 2011, 06:46:14 pm by Qwerty.55 »
∂²Ψ    -(2m(V(x)-E)Ψ
---  = -------------
∂x²        ℏ²Ψ

Offline ben_g

  • Hey cool I can set a custom title now :)
  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1002
  • Rating: +125/-4
  • Asm noob
    • View Profile
    • Our programmer's team: GameCommandoSquad
Re: The benefits of OOP
« Reply #13 on: June 23, 2011, 06:48:08 pm »
make a simple program in an OOP langue, and the same program in a not OOP langue, and create your project in the langue you like the most.

some people like OOP better, some like prodecural programming better.

btw:
*I assume you meant 1500 lines of code, not 15000, because 300*5= 1500.
no, I actually forgot a 0 at the 300. that should be 3000

You rarely have a fully working engine and world in 1500 lines, especially in 3D games.
« Last Edit: June 23, 2011, 06:53:12 pm by ben_g »
My projects
 - The Lost Survivors (Unreal Engine) ACTIVE [GameCommandoSquad main project]
 - Oxo, with single-calc multiplayer and AI (axe) RELEASED (screenshot) (topic)
 - An android version of oxo (java)  ACTIVE
 - A 3D collision detection library (axe) RELEASED! (topic)(screenshot)(more recent screenshot)(screenshot of it being used in a tilemapper)
Spoiler For inactive:
- A first person shooter with a polygon-based 3d engine. (z80, will probably be recoded in axe using GLib) ON HOLD (screenshot)
 - A java MORPG. (pc) DEEP COMA(read more)(screenshot)
 - a minecraft game in axe DEAD (source code available)
 - a 3D racing game (axe) ON HOLD (outdated screenshot of asm version)

This signature was last updated on 20/04/2015 and may be outdated

Offline AngelFish

  • Is this my custom title?
  • Administrator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3242
  • Rating: +270/-27
  • I'm a Fishbot
    • View Profile
Re: The benefits of OOP
« Reply #14 on: June 23, 2011, 06:53:52 pm »
I'm not asking whether procedural programming or OOP is better, I'm asking what the benefits of OOP are over procedural programming. Procedural methods aren't perfect. For example, networking in most procedural languages is a PITA because of all the things you have to deal with. There are languages that make networking relatively easy though, like Java. I think tloz128 brought up a good point with the part about working with other programmers. It's much easier to just pass arguments than read the documentation for that routine.

Quote
*I assume you meant 1500 lines of code, not 15000, because 300*5= 1500.
no, I actually forgot a 0 at the 300. that should be 3000

You rarely have a fully working engine and world in 1500 lines, especially in 3D games.

Depends on the language and the desired realism. You can certainly do a decent game engine in 1500 lines with the right language.
« Last Edit: June 23, 2011, 06:55:43 pm by Qwerty.55 »
∂²Ψ    -(2m(V(x)-E)Ψ
---  = -------------
∂x²        ℏ²Ψ