Coding Styles and Speed

Apprentice
Posts: 17
Joined: 2008.01
Post: #1
So this is actually related to TNT basic, but I didnt state so in the title because a) it might scare people away, and b) it can relate to other languages.


I am working on my first game contest entry, the OMG Cup. I started in TNT basic, took 2 days to start learning pygame and python, realized that with my current schedule, I would be lucky to finish at all, and went back to my TNT code. I should let you know, this is both my first game as well as my first experiences with TNTBasic.

Basically, what I want to know, is would a procedural "spaghetti code" project (meaning just goto and label statements, and ifthenelses and loops) run faster than a project using functions? Since no variables need to ever be passed, or declare Shared or Global, and I dont need to ever use a whole chunk of memory for a function (since everything is done line by line), wouldn't it be midly faster? I know the increase in perfomance is likely to not be worth having code more confusing than the windows operating system, but I just need my own curiosity satisfied Annoyed

Thanks in advance




Oh BTW I am new here. Hi, how y'all doin. Know C++, Java, learning Haskell/Lua/Python, all kinda at the same time
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #2
That is pretty language-specific...

Whatever the actual answer to performance is, you /really/ don't want to go down that road. If you need more performance, there are better ways to get it than whatever minor advantage that might (or likely, might not) afford you.
Quote this message in a reply
Moderator
Posts: 3,572
Joined: 2003.06
Post: #3
First, welcome to iDevGames.

Second, I'll echo OSC's comment.

> "run faster than a project using functions?"

Technically yes, but probably not. Even in the most drastic case it probably wouldn't be noticeable anyway. Modern computing environments just aren't designed to be used that way. Plus, breaking code up into functions often has the side-effect of helping the programmer to produce faster code by virtue of design. For compiled languages it is important to remember that compilers are designed to better optimize code which is written in a semi-predictable format, so trying to skirt the beaten path can sometimes shoot you in the foot. For interpreted languages like TNT basic it's all up to the designer of the runtime environment. One thing to keep in mind about interpreted languages is that they often have a stack size limit which may or may not be intertwined with a funtion size limit internally. What I'm saying is that if you write the whole program in the global scope or in just one function, you might break the runtime environment. Again, "might" being the operative term here, it all depends upon the implementation when it comes to interpreted languages. For compiled languages I believe there is also the issue of screwing up the caching system if you make functions too big on a PowerPC (don't quote me on that though - I just remember reading somewhere that loop-unrolling on a PPC can work against you because the instruction cache can get blown, or something like that).

Bottom line - Don't tempt fate, functions are better.
Quote this message in a reply
Moderator
Posts: 434
Joined: 2002.09
Post: #4
Besides, functions will save YOU time both in avoiding rewriting code and in debugging. And your time is at a premium in a 1-month contest.

Provided you aren't too ambitious ("As the level begins, 100,000 samurai warriors crest the hill, and the sunlight glints off their lovingly modelled, environmentally-reflecting helmets") your game will probably run fast enough. If it doesn't, often it's a matter of optimizing the algorithm- removing the overhead of function calls will probably not speed it up noticeably.

One exception to this is if you have a hotspot in your code. If there is a particular section of code where you are spending 80% of your time, removing a function call from that spot (and any other simplification you can think of) might have an impact. But you probably can't identify such hots spots until the game is already written.

Measure twice, cut once, curse three or four times.
Quote this message in a reply
Moderator
Posts: 529
Joined: 2003.03
Post: #5
FWIW, TNT source files are one huge text file. Breaking it into procedures will let you jump to the start of a procedure in the IDE. So, performance issues aside, it will at least make your code easier to navigate and read.

"Yes, well, that's the sort of blinkered, Philistine pig-ignorance I've come to expect from you non-creative garbage."
Quote this message in a reply
Apprentice
Posts: 17
Joined: 2008.01
Post: #6
TNT basic does compile into native code, so its not a text file anymore at that point. I wasnt planning on doing anything like that, NASA learned that lesson for me when they lost that satellite like 20 years ago haha. Just wondering, if it ever came down to it, if it would help
Quote this message in a reply
Moderator
Posts: 529
Joined: 2003.03
Post: #7
I know it compiles. My point was that it would be easier to navigate while you're still coding.

The IDE can jump to the starts of procedures (like bookmarks.)

"Yes, well, that's the sort of blinkered, Philistine pig-ignorance I've come to expect from you non-creative garbage."
Quote this message in a reply
Apprentice
Posts: 17
Joined: 2008.01
Post: #8
ah ok I thought you meant it would jump around like that while being interpreted Smile

looking over your post again, that was painfully obvious. apologies
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Coding A Card Game Jerm #1 3 5,020 Apr 11, 2010 03:05 PM
Last Post: TimMcD
  Advice on coding of On-Screen Controls ( Joystick and multiple buttons) Elphaba 5 3,110 Aug 10, 2009 11:02 PM
Last Post: Elphaba
  Coding efficiently (pygame) perks 10 4,297 Sep 11, 2007 08:09 AM
Last Post: Blacktiger
  Coding a Tic Tac Toe game in C dongski19 5 6,928 Aug 21, 2006 01:17 PM
Last Post: Jones