Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Running everything in Main.  (Read 1814 times)

0 Members and 1 Guest are viewing this topic.

synok

  • Newbie
  • *
  • Posts: 18
    • View Profile
Running everything in Main.
« on: December 20, 2012, 11:19:16 am »
Well, how safe do you think it is? Is there any noticable changes if you have alot of code inside the Main function or the While loop inside of it, or is it better (not only structure-wise) to divide all functions in to headers and calling them seperately?

Anyone noticed any slow-downs or other bieffects of putting alot of game code inside one main file with one main function and one while loop that runs?

Sui

  • Jr. Member
  • **
  • Posts: 67
    • View Profile
    • http://www.suisoft.co.uk/
Re: Running everything in Main.
« Reply #1 on: December 20, 2012, 11:37:03 am »
You shouldn't encounter any performance problems, however your code will become increasingly difficult to maintain if you don't structure it. For a trivial demo program it doesn't matter too much.

On a larger, more complex project the compile time would get longer and longer as all of the code has to be compiled every time. Ideally you should be breaking your functionality into multiple header and code files. Your best bet is to pick up a book on Object-Oriented Programming (OOP) to learn how to design object models and structure your code.

Sorry I can't recommend a specific book, as I have been coding a long time and haven't read that kind of book recently. Perhaps some of the other guys on here know of a good book.

Which programming language are you using? Is it C++?
Gary Marples, Developer of games and other stuff.
www.suisoft.co.uk/games/BlogTwitter

synok

  • Newbie
  • *
  • Posts: 18
    • View Profile
Re: Running everything in Main.
« Reply #2 on: December 20, 2012, 11:58:07 am »
I am using C++ at the moment. And it started with coding inside the main function, since my game loop was there. And I just kept on adding more and more code without structuring it, so now it is a mess probably.

Sui

  • Jr. Member
  • **
  • Posts: 67
    • View Profile
    • http://www.suisoft.co.uk/
Re: Running everything in Main.
« Reply #3 on: December 20, 2012, 12:21:28 pm »
You shouldn't have any problems with the end result, but your code will become hard to maintain.

How did you learn C++?

Have you read about OOP (Object-Oriented Programming) at all?

I have been using it for about 20 years (along with other languages like VB and C#) and am still learning new and better ways to code.

'Refactoring' by Martin Fowler is a great book on restructuring code, but you really need a solid C++ / OOP book first.
Gary Marples, Developer of games and other stuff.
www.suisoft.co.uk/games/BlogTwitter

 

anything