The International Simutrans Forum

 

Author Topic: How to write good code  (Read 1175 times)

0 Members and 1 Guest are viewing this topic.

Offline jamespetts gb

  • Simutrans-Extended project coordinator
  • Devotee
  • *
  • Posts: 18693
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
How to write good code
« on: January 07, 2011, 09:47:39 PM »
All developers should read this.

Offline VS

  • Senior Plumber (Devotee)
  • Devotee
  • *
  • Posts: 4855
  • Vladimír Slávik
    • VS's Simutrans site
  • Languages: CS,EN
Re: How to write good code
« Reply #1 on: January 07, 2011, 10:38:57 PM »
There is also a highly verbose counterpart... We are already good on a few points:

Quote
Names From Other Languages
Use foreign language dictionaries as a source for variable names. For example, use the German punkt for point. Maintenance coders, without your firm grasp of German, will enjoy the multicultural experience of deciphering the meaning.

Units of Measure
Never document the units of measure of any variable, input, output or parameter. e.g. feet, metres, cartons. (...) If somebody challenges you, tell them you did so that you could use integer rather than floating point arithmetic.

Lower Case l Looks a Lot Like the Digit 1
Use lower case l to indicate long constants. e.g. 10l is more likely to be mistaken for 101 that 10L is. Ban any fonts that clearly disambiguate uvw wW gq9 2z 5s il17|!j oO08 `'" ;,. m nn rn {[()]}. Be creative.
« Last Edit: January 07, 2011, 10:44:23 PM by VS »

Offline Spike

  • *
  • Posts: 1361
  • First Simutrans Developer and Graphics Artist
Re: How to write good code
« Reply #2 on: January 07, 2011, 11:08:12 PM »
All developers should read this.

Hehe :)

You know, from these:

quick - cheap - good

You usually only can have two:

quick and cheap -> won't be good
cheap and good -> won't be quick
quick and good -> won't be cheap



Offline jamespetts gb

  • Simutrans-Extended project coordinator
  • Devotee
  • *
  • Posts: 18693
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: How to write good code
« Reply #3 on: January 07, 2011, 11:25:04 PM »
No prizes for guessing which one that Simutrans doesn't have ;-)

Offline neroden

  • Devotees (Inactive)
  • *
  • Posts: 831
  • Nathanael Nerode
Re: How to write good code
« Reply #4 on: January 08, 2011, 12:15:41 AM »
There is also a highly verbose counterpart... We are already good on a few points:

Heh.  I was trying to fix those, you know, but it is really hard to fix that stuff after the fact.  One of the catches is that major code cleanup patches, particularly the crucial renamings, *do* destabilize everyone else's workflow -- I think the only way to do it would be if everyone agreed to not develop any major new features for (say) a month while people work on code cleanup.