Author Topic: Best Way To Code?  (Read 1550 times)

Offline Karlos

  • Level 7
  • *
  • Posts: 31
  • Reputation: +2/-0
    • View Profile
Best Way To Code?
« on: April 17, 2010, 09:51:27 AM »
I know there are many types of ways to coding, but I am wondering what one would be best for a game?

  • Procedural?
  • OOP
    • Factory
    • Singleton
    • Ect...
  • Other?

Offline Nox

  • Level 35
  • **
  • Posts: 768
  • Reputation: +12/-2
    • View Profile
Re: Best Way To Code?
« Reply #1 on: April 17, 2010, 09:59:31 AM »
As always :) depends

The more complex the game is, the more beneficial OOP becomes imho. On the other hand of course you can of course you some objects in a simple project where it's useful

I started to go more the OOP way, but.... there were already discussions about this topic, try to look it up

Many people will list you advantages of OOP, Chris will tell you it's overkill, you get the idea :)
Meet us at an IRC irc.freenode.net #bbg as well
https://vimeo.com/36579366 (a must-watch) | Join BOINC - no longer a hype, but you can help never the less

Offline Karlos

  • Level 7
  • *
  • Posts: 31
  • Reputation: +2/-0
    • View Profile
Re: Best Way To Code?
« Reply #2 on: April 17, 2010, 10:09:28 AM »
True it does depend on quite a few factors.

I'll have a look to see if I can find it.

Offline Mufasa

  • Game Owner
  • Level 18
  • *
  • Posts: 189
  • Reputation: +3/-0
  • Maniac Developer
    • View Profile
Re: Best Way To Code?
« Reply #3 on: April 17, 2010, 10:59:13 AM »
Personally, if it's going to be a game you plan to continually develop and expand on, doing it right from the beginning is often best, and using an OO model is usually the easiest way to expand in the future.

For example, when I added forums to prisonblock, I needed my "user object" to have extra data like post count, last post viewed etc. So I created userObjectForum which extended my main User class which expended user object. It had all that the others had, but also had the specific stuff related to forums.

The addition was easy, and I didn't need to muck up my other classes with stuff they'd never use.

Offline Chris

  • Game Owner
  • Level 35
  • *
  • Posts: 2,217
  • Reputation: +28/-1
    • View Profile
Re: Best Way To Code?
« Reply #4 on: April 17, 2010, 11:23:47 AM »
Many people will list you advantages of OOP, Chris will tell you it's overkill, you get the idea :)
It is an overkill :)

Offline Delifisek

  • Level 12
  • *
  • Posts: 79
  • Reputation: +1/-1
    • View Profile
Re: Best Way To Code?
« Reply #5 on: May 14, 2010, 07:45:41 AM »
Just stick one of them and relase your game soon as possible.

There is always better coding, there is always better ideas, better algorithms, frameworks, languages etc.

And just look OGAME.

Probably one of the worst gaming model. And it's complete and still making money after more than 5 years...






Offline Shrapnel

  • Level 9
  • *
  • Posts: 46
  • Reputation: +0/-0
    • View Profile
Re: Best Way To Code?
« Reply #6 on: May 14, 2010, 09:40:10 AM »
Chris, am I right that you do not like OOP?  If so I'm curious about your thoughts on this.
"Never compromise. Not even in the face of Armageddon" -Rorschach, Watchmen (2009)

Offline Murzim

  • Game Owner
  • Level 14
  • *
  • Posts: 107
  • Reputation: +1/-0
    • View Profile
Re: Best Way To Code?
« Reply #7 on: May 15, 2010, 05:46:05 PM »
Object Oriented Programming can become very complex. If you do it, I would suggest you keep enough comments to make sure that you will remember what this big class of yours do, when you will revisit it after 12 or 18 months.

Offline gnoh

  • Game Owner
  • Level 15
  • *
  • Posts: 127
  • Reputation: +2/-0
    • View Profile
Re: Best Way To Code?
« Reply #8 on: May 16, 2010, 03:40:16 AM »
Eh, if the class isn't doing one thing well you haven't broke down the problem correctly.

One of the main points of OOP is managing complexity.

Offline lolninja

  • Level 19
  • *
  • Posts: 194
  • Reputation: +5/-0
  • BSc powered Programmer
    • View Profile
    • HTTPmmo
Re: Best Way To Code?
« Reply #9 on: May 16, 2010, 08:24:03 AM »
Yeah ideally classes would be not much longer than 300-500 lines of code, with each function running in at 30-50 lines on average, yes there are situations when this may increate, for example using an overly verbose API.

Because you have very small blocks of code that do one specific task its easy to imply its intention via the use of descriptive variable names, and a short comment block and you have an extremely good idea of what your looking at.

Offline Chris

  • Game Owner
  • Level 35
  • *
  • Posts: 2,217
  • Reputation: +28/-1
    • View Profile
Re: Best Way To Code?
« Reply #10 on: May 16, 2010, 05:34:39 PM »
Chris, am I right that you do not like OOP?  If so I'm curious about your thoughts on this.
It is not that I do not like it, I even say in some cases it is the only way to go. Sometimes the thing can be done only by using OOP. But, in my 20 years of programming I stumbled upon only 1 case when OOP was really needed and benefitial. So I think that OOP is very extemely highly overused, everyone and his dog trys to use OOP no matter if it is the best tool in his case or not.

I'm also very sceptical about PHP + OOP combo, due to the lack of persistent memory model in PHP all classes has to be recreated on each page refresh. It is against the core concept of OOP and puts more stress on the hardware than classic PC dev. In combo with the fact that 99% of PHP code in BBGs is on server side triggered by client (as opposed to the possibility to move some stress from server to client by making downoadable client in 3D MMOG) and that all code has to be parsed and interpreted (code size affects performance) it makes OOP with PHP much more dangerous performance wise than OOP and C++.

Offline dsheroh

  • Level 21
  • *
  • Posts: 235
  • Reputation: +6/-0
  • Perl Vicar
    • View Profile
    • Psi Rangers
Re: Best Way To Code?
« Reply #11 on: May 16, 2010, 06:26:24 PM »
So I think that OOP is very extemely highly overused, everyone and his dog trys to use OOP no matter if it is the best tool in his case or not.

OOP is very useful in a wide variety of cases, so I probably don't think it's as overused as you do, but you're absolutely right that it is not the One True Way to write code.

I'm also very sceptical about PHP + OOP combo, due to the lack of persistent memory model in PHP all classes has to be recreated on each page refresh. It is against the core concept of OOP and puts more stress on the hardware than classic PC dev. In combo with the fact that 99% of PHP code in BBGs is on server side triggered by client (as opposed to the possibility to move some stress from server to client by making downoadable client in 3D MMOG) and that all code has to be parsed and interpreted (code size affects performance) it makes OOP with PHP much more dangerous performance wise than OOP and C++.

This isn't entirely accurate, though.  First off, PHP can be run under FastCGI or other accelerators which allow the pages to be compiled to bytecode once and reused on subsequent requests instead of having to rebuild the whole thing on every request.  Anyone running a production web application without some form of persistent runtime server environment is, most likely, doing it wrong.

Secondly, one advantage of dynamic languages is that they allow you to include only the code (i.e., classes, in an OOP context) that you actually need, unlike languages such as C++ where you don't know in advance which parts will actually be needed at runtime, so you're forced to include everything, just in case.

 


SimplePortal 2.3.3 © 2008-2010, SimplePortal