Author Topic: Class-based vs Function-based  (Read 1282 times)

Offline Broda

  • Level 13
  • *
  • Posts: 97
  • Reputation: +2/-0
    • View Profile
    • Nightfall Games
Class-based vs Function-based
« on: May 02, 2007, 01:55:01 PM »
I've been working on my PBBG and I can't decide between going class-based or just stay function-based.

My thinking is that for most of the work, classes would just add to the overhead of processing. If I want to do something specific to an item, say increase the stats, I don't want to have to create a class, fill it with the item's values, make the mods and then write it back to the database. I'd rather just call item_ModifyStats(lngItemID, sngStatAChange, sngStatBChange, ...) or even better item_ModifyStatA(lngItemID, sngChange)...

I know the advantages of OOP, I just can't really envision how it would make my game more efficient. Maybe go higher level with it, i.e. CItemMgr class that encapsulates everything that needs to happen to items and basicly just becomes a wrapper for the functions I mentioned earlier. With includes, I don't really see an advantage to that either - I could just as easily include items.inc.php that has all of the item functions.

I don't know... Just thought I'd try to start an interesting conversation.

Offline Zeggy

  • Global Moderator
  • Level 35
  • *****
  • Posts: 1,187
  • Reputation: +13/-4
    • View Profile
Re: Class-based vs Function-based
« Reply #1 on: May 02, 2007, 03:20:00 PM »
I doubt OOP would make your pages load faster since classes run slower than functions in general.
I think it could just be a matter a preference. OO isn't really 'easier' to learn/use than functions, and functions are just as reusable as objects.
Myself, I use both functions and objects, but mostly functions :) Objects can sometimes be useful when you want to group some functions together so you don't get mixed up :P

Offline Broda

  • Level 13
  • *
  • Posts: 97
  • Reputation: +2/-0
    • View Profile
    • Nightfall Games
Re: Class-based vs Function-based
« Reply #2 on: May 02, 2007, 05:56:56 PM »
Objects can sometimes be useful when you want to group some functions together so you don't get mixed up :P

This is why it's good to come up with a strict set of naming conventions and stick to them. All of the functions that have to do with a single item I use item_, if it pertains to a group of items I use items_, etc

Offline Wakish

  • Level 14
  • *
  • Posts: 111
  • Reputation: +0/-1
    • View Profile
    • Wakish Wonderz
Re: Class-based vs Function-based
« Reply #3 on: June 28, 2007, 10:57:15 AM »
Well, I see classes more reusable than functions..
OOP approach makes things alot more easier and more comprehensible.. it's like a philosophy to me..
I can;t imagine coding without using OOP..
And I dnt think it makes codes slower when compared to functions..  Well as far as I see things.. ;)
« Last Edit: June 28, 2007, 10:59:22 AM by wakish »

Offline Sinzygy

  • Level 28
  • **
  • Posts: 420
  • Reputation: +11/-0
    • View Profile
Re: Class-based vs Function-based
« Reply #4 on: June 28, 2007, 12:41:30 PM »
I'd say that it really depends on personal preference and skill. Well written procedural code will jump circles around badly written OO code, and vice versa.

And as far as games are concerned, I'd say that OOP isn't that important. If you're developing applications you most probably want to go the OO way.

Offline Wakish

  • Level 14
  • *
  • Posts: 111
  • Reputation: +0/-1
    • View Profile
    • Wakish Wonderz
Re: Class-based vs Function-based
« Reply #5 on: June 28, 2007, 01:33:04 PM »
I'd say that it really depends on personal preference and skill. Well written procedural code will jump circles around badly written OO code, and vice versa.

And as far as games are concerned, I'd say that OOP isn't that important. If you're developing applications you most probably want to go the OO way.

Urm, yeah perhaps a matter of taste since PHP allows for it ;)
But anyway, it's the result of your hardwork that counts in the end ;)

Cheers!

Offline Carrion

  • Level 4
  • *
  • Posts: 13
  • Reputation: +0/-0
    • View Profile
Re: Class-based vs Function-based
« Reply #6 on: June 30, 2007, 03:49:25 PM »
this is a very old arguement that goes back to the early days of OO. I think it is more important that you focus more on what you are more comfortable with coding/maintaining. Both will do the job and as stated before, well written code is always going to perform better.

But do remember to always...always comment your code. because six months after release when you are reading it (looking for a bug for example) you will have more experience with coding and may be confused about what and why you wrote code like that.....

 


SimplePortal 2.3.3 © 2008-2010, SimplePortal