FAQ Search
Memberlist Usergroups
Profile
  Forum Statistics Register
 Log in to check your private messages
Log in to check your private messages
Moonpod Homepage Starscape Information Mr. Robot Information Free Game Downloads Starscape Highscore Table
Maintainable code
Post new topic   Reply to topic    Discussion Pod Forum Index -> Independent Game Development View previous topic :: View next topic  
 Author
Message
BluePhoenix



Joined: 08 Jun 2004
Posts: 96
Location: Between Georgia and Cuba



PostPosted: Fri Mar 16, 2007 8:27 pm    Post subject: Maintainable code Reply with quote

I'm wondering, what with all the updates and what not you've done with your game(s) and the website and all, I'm wondering what steps - if any - you guys take to make your life easier in case you have to change some code later?
Back to top
View user's profile AIM Address Yahoo Messenger
Poo Bear
Pod Team
Pod Team


Joined: 14 Oct 2002
Posts: 4121
Location: Sheffield, UK



PostPosted: Mon Mar 19, 2007 12:55 pm    Post subject: Reply with quote

With all the good intentions in the world we've ended up doing very little future proofing and paying a high price. We tend to be crushed by ridiculous deadlines resulting from our over ambitious game designs and then just rushing to get things done. So Starscape uses a different engine and shares almost nothing with MrRobot, which itself isn't really in a position to be reused with core components rushed or written by someone who doesn't work here anymore, some things not really finished and no real documentation.

Sad

Writing legible code with strong engineering and design takes, skill, extra time, a good problem specification, peer review and research. You should certainly aspire to it even when the schedule is trying to crush you.

My advice:

1. Try - the easiest approach is to just throw something together and get it done, resist that urge. Good design, thought and documentation is important.

2. Don't put yourself in a position where you have to rush everything, that is paramount. Any good intentions you might have had can be killed by lack of time.

3. Consider using open source libraries where you can. I'm sure this will cause immense problems, but at least it has been designed and put together by people who should have had the time to do it right and get it peer reviewed. If nothing else you can get help from other programmers with any problems - which is one of the few ways you'll grow as a programmer.

4. Humility - read a wide range of programming books and show your work to other programmers (see point3). Don't act like you know it all because you don't and never will. Programmers tend to have poor social skills and an almost autistic personality, work on this.
Back to top
View user's profile Visit poster's website
Weeble
Starscape Jedi
Starscape Jedi


Joined: 25 Apr 2003
Posts: 1143
Location: Glasgow, Scotland



PostPosted: Mon Mar 19, 2007 1:57 pm    Post subject: Reply with quote

For the writing of the code itself, I'd recommend making it as self-documenting as possible. This means:
  • Use sensible, consistent identifiers. Duh.
  • Each function (or method) should have a single task to do, which is expressed in its name. Don't add in extra stuff that doesn't need to be there. (Enforcing class constraints does need to be there. Don't write functions that leave your data structures in temporarily inconsistent states.) Make another function instead. (This can be awkward in some situations. I hate it when I have a data structure and want to do several independent tasks on it that all involve iterating over it in one way or another. How to do this really depends on your efficiency, maintainability and deadline priorities, I think.)
  • Keep functions short. The longer a function gets, the more likely it is to be doing more than its name suggests, and the harder it is to verify what it's doing.
  • Make constraints clear with assertions. If you just use comments, you might accidentally later break those constraints, and if nothing goes too wrong you may rely on the constraints being broken without realising. When it comes to maintaining the original code, you will have a headache because it doesn't quite do what it says it should, but stuff breaks if you fix it. When looking at a piece of existing code with assertions, you have reliable information about the code—far more reliable than comments or a separate document.
  • If you're programming in C++, make classes to enforce constraints. A friend recently showed me a piece of code he was working on, and the owner had since gone away. There was a map from (I think) 64-bit integers to pairs of booleans and 64-bit integers. There were few hints what this data structure was used to represent. Every so often the code would insert or look up elements. Even if he'd written the code himself, it would take a good while looking through all the uses of this structure to determine what it represents and what are legal operations on it. If instead it was inside a wrapper class, the class interface could enforce integrity constraints on all uses of the data, give useful names to the operations, and let anyone looking at the code know for sure how it might or might not be used.
  • Documents lie. Comments lie. This doesn't mean you shouldn't have them—assertions and strong typing can stop you from trying to do nonsensical things, but not from trying to reasonable but nevertheless wrong things—but you shouldn't rely on them. With the best will in the world they will become out of date. When you come across them, treat them like an archeologist or an historian would treat ancient murals or books: they are valuable source material about what somebody once thought or wanted people to think, but there is no guarantee that they tell the truth, here and now.
Back to top
View user's profile Visit poster's website MSN Messenger
Weeble
Starscape Jedi
Starscape Jedi


Joined: 25 Apr 2003
Posts: 1143
Location: Glasgow, Scotland



PostPosted: Mon Mar 19, 2007 2:08 pm    Post subject: Reply with quote

PS - I recommend the code review part, just make sure it's with somebody you trust and respect, and who respects you back. A code review is not an test, nor is it a competition. It's about cooperation to make the code as good as possible, to spot the silly mistakes that we all make and are far easier to see in someone else's work than in your own, to share ideas and hopefully learn a thing or two. Also, bear in mind how much time you spend actually writing code, compared to planning it, building it, running it, diagnosing it, rewriting it. A code review for what you've been working on for the last few weeks probably won't take as long as you think. (Good source control tools with clear diff views will help a lot!) (Trying to review a long-running project from scratch, though, might take quite a while.)
Back to top
View user's profile Visit poster's website MSN Messenger
Weeble
Starscape Jedi
Starscape Jedi


Joined: 25 Apr 2003
Posts: 1143
Location: Glasgow, Scotland



PostPosted: Tue Mar 20, 2007 11:19 pm    Post subject: Reply with quote

PPS - I'm just an opionated programmer and despite working for a games company don't really have any significant experience directly related to game development. Do tell me to shut up if I keep rambling on. ;)
Back to top
View user's profile Visit poster's website MSN Messenger
BluePhoenix



Joined: 08 Jun 2004
Posts: 96
Location: Between Georgia and Cuba



PostPosted: Sat Mar 24, 2007 3:35 am    Post subject: Reply with quote

Thanks for thoughts guys. I'm having to rewrite alot of PHP code I did previously, so I'm definately going to keep your suggestions in mind as I try to do this right this time.
Back to top
View user's profile AIM Address Yahoo Messenger
Display posts from previous:   
Post new topic   Reply to topic    Discussion Pod Forum Index -> Independent Game Development All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group