Transport Tycoon Forums

The place to talk about Transport Tycoon
It is currently Tue May 23, 2017 6:46 pm

All times are UTC




Post new topic  Reply to topic  [ 54 posts ]  Go to page 1 2 3 Next
Author Message
PostPosted: Sun May 23, 2004 10:00 am 
Offline
OpenTTD Developer
OpenTTD Developer
User avatar

Joined: Sun Mar 07, 2004 9:28 am
Posts: 35
Coding Style can be found at http://wiki.openttd.org/Coding_style. To avoid duplication of text, this post has been removed -- TrueLight.

_________________
http://sf.net/projects/openttd/
Post all your patches and feature requests here.


Top
   
 Post subject:
PostPosted: Mon Oct 31, 2005 3:04 pm 
Offline
Tycoon
Tycoon
User avatar

Joined: Wed Oct 15, 2003 10:00 pm
Posts: 2566
Location: Jarrow, UK
What's the style for loops? I'm assuming it's like that of if in the example above. Am I correct?

_________________
PGP fingerprint: E66A 9D58 AA10 E967 41A6 474E E41D 10AE 082C F3ED


Top
   
 Post subject:
PostPosted: Mon Oct 31, 2005 10:59 pm 
Offline
Tycoon
Tycoon
User avatar

Joined: Mon Feb 24, 2003 6:45 pm
Posts: 3051
Location: Hong Kong
Brianetta wrote:
What's the style for loops? I'm assuming it's like that of if in the example above. Am I correct?


yes.

Code:
for (i = 0; i != 10; i++) {
  bla;
  bla;
}

_________________
TrueLight: "Did you bother to read any of the replies, or you just pressed 'Reply' and started typing?"
<@[R-Dk]FoRbiDDeN> "HELP, this litte arrow thing keeps following my mouse, and I can't make it go away."


Top
   
 Post subject:
PostPosted: Fri Nov 18, 2005 11:06 am 
Offline
Engineer
Engineer
User avatar

Joined: Thu Nov 17, 2005 8:56 pm
Posts: 84
Location: Netherlands
I think the style for switch-statements is still missing, which seems a rather important one to me because that's one that can be done in many different ways.


Top
   
 Post subject:
PostPosted: Wed Feb 15, 2006 3:14 am 
Offline
Engineer
Engineer
User avatar

Joined: Wed Feb 02, 2005 7:03 pm
Posts: 124
Location: Now in North Dakota
I'm partial to blocking my code as it was intended...

Code:
if (*v->Blahness() == Blah())
{
  *v->Jiggles++;
}



That way stuff really is "blocked" as it should. Plus the extra linebreak and carriage return doesn't bloat the filesize. :wink:

_________________
-Buggi
Programmer and TTD fan...


Top
   
 Post subject:
PostPosted: Wed Feb 15, 2006 5:58 am 
Offline
TTDPatch Developer
TTDPatch Developer

Joined: Wed Feb 18, 2004 3:06 am
Posts: 10285
I'm partial to blocking my code as it was intended...
Code:
if(a)for(b=0;b<10;i++)while(c){doit();dootherthing();}
And the saved vertical space means that you can get so much more code on a single screen.

This is why we have a coding style. It helps forestall holy wars. And, unless you want to reformat something like 10 MB of source, the current style is the way it will stay.
Even if you do reformat all the code, I still don't think the style will change.

_________________
To get a good answer, ask a Smart Question. Similarly, if you want a bug fixed, write a Useful Bug Report. No TTDPatch crashlog? Then follow directions.
Projects: NFORenum (download) | PlaneSet (Website) | grfcodec (download) | grfdebug.log parser


Top
   
 Post subject:
PostPosted: Wed Feb 15, 2006 6:33 pm 
Offline
Tycoon
Tycoon
User avatar

Joined: Wed Oct 15, 2003 10:00 pm
Posts: 2566
Location: Jarrow, UK
Dalestan, I'm sure you could have saved still more space on the semicolon near the end.

Buggi, if the coding style really bugs you, and you can't work with such offensive style rules, you can always use indent with two sets of rules. One to format the code so that you like working on it, and one to change it back to the OpenTTD style before you commit changes/submit patches/whatever.

_________________
PGP fingerprint: E66A 9D58 AA10 E967 41A6 474E E41D 10AE 082C F3ED


Top
   
 Post subject:
PostPosted: Wed Feb 15, 2006 9:22 pm 
Offline
Director
Director

Joined: Tue Jan 03, 2006 8:45 pm
Posts: 560
Location: Netherlands
DaleStan wrote:
(...)
And the saved vertical space means that you can get so much more code on a single screen.
(...)

But that is not necessarily a benefit. Books aren't printed over the full width of the paper because it would be hard to read otherwise (instead you will see a "wall of words"). Some people have shown that the ideal width of a line is about 70 characters. If it is longer or shorter, it is harder to read. For the same reason, newspapers use columns.
Making computer code more compact may cause the legibility to decrease. The use of line wrapping and indentation will make the code more readable. Overuse of those things will destroy legibility again. So you have to find some ideal line length.
Your example could be part of a "wall of computer code".


Top
   
 Post subject:
PostPosted: Wed Feb 15, 2006 11:54 pm 
Offline
Tycoon
Tycoon
User avatar

Joined: Wed Oct 15, 2003 10:00 pm
Posts: 2566
Location: Jarrow, UK
* Brianetta hands hertogjan a replacement sarcasmometer

Yours seems to be failing.

_________________
PGP fingerprint: E66A 9D58 AA10 E967 41A6 474E E41D 10AE 082C F3ED


Top
   
 Post subject:
PostPosted: Thu Feb 16, 2006 12:38 am 
Offline
Engineer
Engineer
User avatar

Joined: Wed Feb 02, 2005 7:03 pm
Posts: 124
Location: Now in North Dakota
I seem to be on the receiving end of most of Dale's anger these days. :(

_________________
-Buggi

Programmer and TTD fan...


Top
   
 Post subject:
PostPosted: Thu Feb 16, 2006 9:10 am 
Offline
TTDPatch Developer
TTDPatch Developer

Joined: Wed Feb 18, 2004 3:06 am
Posts: 10285
I'm afraid I tend to get angry when people suggest that OTTD should lose support for one of my two favourite programming languages.
Or even when I think that people want OTTD to quit supporting that language.

It really didn't help that the first post I specifically noticed was yours was this one. I now see it wasn't intended this way, but my luser-o-meter went off, and first impressions are hard to break. You're doing quite well at forcing me to adjust my opinion (in this case, that's a good thing); keep it up.

_________________
To get a good answer, ask a Smart Question. Similarly, if you want a bug fixed, write a Useful Bug Report. No TTDPatch crashlog? Then follow directions.
Projects: NFORenum (download) | PlaneSet (Website) | grfcodec (download) | grfdebug.log parser


Top
   
 Post subject:
PostPosted: Thu Feb 16, 2006 10:30 am 
Offline
Tycoon
Tycoon
User avatar

Joined: Sat May 21, 2005 3:10 pm
Posts: 1850
Location: Hull, England
i don't think OTTD should stop support of newGRF, even if what i said makes it saound that way, but i do think the 32bpp stuff might need a bit more of a kick than newGRF supports.

_________________
JPG SUX!!! USE PNG!!!
There are times when JPG is useful, TTD screenshots is not one of them. Please use PNG instead.

[/url]


Top
   
 Post subject:
PostPosted: Thu Feb 16, 2006 1:20 pm 
Offline
Tycoon
Tycoon
User avatar

Joined: Wed Oct 15, 2003 10:00 pm
Posts: 2566
Location: Jarrow, UK
How would the graphical bit depth affect the "kick" of newgrf?

_________________
PGP fingerprint: E66A 9D58 AA10 E967 41A6 474E E41D 10AE 082C F3ED


Top
   
 Post subject:
PostPosted: Thu Feb 16, 2006 1:25 pm 
Offline
Tycoon
Tycoon
User avatar

Joined: Sat May 21, 2005 3:10 pm
Posts: 1850
Location: Hull, England
because its actually 34bits, because you require a 32bpp image and a 2bpp CC overlay, which means each sprite requires 2 seperate images.

_________________
JPG SUX!!! USE PNG!!!
There are times when JPG is useful, TTD screenshots is not one of them. Please use PNG instead.

[/url]


Top
   
 Post subject:
PostPosted: Thu Feb 16, 2006 1:29 pm 
Offline
Tycoon
Tycoon
User avatar

Joined: Wed Oct 15, 2003 10:00 pm
Posts: 2566
Location: Jarrow, UK
Still not sure why you need to handle it any differently from the 8 bit graphics. I was under the impression that newgrf was fairly agnostic toward bit depth and graphics format. Anyway, this is dragging a fairly important sticky off topic, and there are already some threads covering this subject.

_________________
PGP fingerprint: E66A 9D58 AA10 E967 41A6 474E E41D 10AE 082C F3ED


Top
   
 Post subject:
PostPosted: Sat Apr 08, 2006 8:01 am 
Offline
Tycoon
Tycoon
User avatar

Joined: Mon Feb 24, 2003 6:45 pm
Posts: 3051
Location: Hong Kong
*updated starting post with 'coding guidelines'

_________________
TrueLight: "Did you bother to read any of the replies, or you just pressed 'Reply' and started typing?"
<@[R-Dk]FoRbiDDeN> "HELP, this litte arrow thing keeps following my mouse, and I can't make it go away."


Top
   
 Post subject:
PostPosted: Fri Jul 14, 2006 1:35 pm 
Offline
TTDPatch Developer
TTDPatch Developer

Joined: Wed Feb 18, 2004 3:06 am
Posts: 10285
I don't see anything mentioned here about using
Code:
enum {
  FOO = 0,
  BAR = 1,
  BAZ = 2,
  END = 3
};

instead of
Code:
enum {
  FOO,
  BAR,
  BAZ,
  END
};


Most of the enums I've seen in the OpenTTD source are in the former format, not the latter. I can see lots of disadvantages to the former, but no advantages, and the use of the former format has caused bugs that would be complete non-issues were the explicit values not present.

Is it just a matter of someone sitting down with grep, removing all the explicit values, and posting a patch on Flyspray, or is there some reason that the enums must have explicit values?

_________________
To get a good answer, ask a Smart Question. Similarly, if you want a bug fixed, write a Useful Bug Report. No TTDPatch crashlog? Then follow directions.
Projects: NFORenum (download) | PlaneSet (Website) | grfcodec (download) | grfdebug.log parser


Top
   
 Post subject:
PostPosted: Fri Jul 14, 2006 1:43 pm 
Offline
Tycoon
Tycoon

Joined: Thu Jun 05, 2003 4:21 pm
Posts: 2363
Location: Up North
DaleStan wrote:
Is it just a matter of someone sitting down with grep, removing all the explicit values, and posting a patch on Flyspray, or is there some reason that the enums must have explicit values?
I think there are occasions where explicit enums are better; eg. in any list where the value is saved (airport heading states being one). However, yes, in general non-explicit enums are better.

The bug you link to is an awkward one for enumeration; not every item in the graphic list has an enumerated value. So the enumerated values jump with fairly large gaps between them. (These correspond to values in station_land.h). It was a typo, nothing more.

_________________
OTTD NewGRF_ports. Add an airport design via newgrf.Superceded by Yexo's NewGrf Airports 2
Want to organise your trains? Try Routemarkers.
--- ==== --- === --- === ---
Firework Photography


Top
   
 Post subject:
PostPosted: Fri Jul 14, 2006 2:16 pm 
Offline
TTDPatch Developer
TTDPatch Developer

Joined: Wed Feb 18, 2004 3:06 am
Posts: 10285
So just use the explicit values where they are needed, and leave all the others out. If typos can be eliminated by removing code, then I'm of the opinion that said code should be removed posthaste.

Even if only END loses its explicit value, that acheives most of the desired result, while still making it difficult to break the savegames by inserting a value in the middle of the list.

_________________
To get a good answer, ask a Smart Question. Similarly, if you want a bug fixed, write a Useful Bug Report. No TTDPatch crashlog? Then follow directions.
Projects: NFORenum (download) | PlaneSet (Website) | grfcodec (download) | grfdebug.log parser


Top
   
 Post subject:
PostPosted: Tue Aug 22, 2006 9:58 am 
Offline
OpenTTD Developer
OpenTTD Developer

Joined: Mon May 31, 2004 9:21 am
Posts: 1292
Coding Style have been slightly altered. Please do pay attention to them.


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 54 posts ]  Go to page 1 2 3 Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


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 post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000-2017 phpBB Limited

Copyright © Owen Rudge/The Transport Tycoon Forums 2001-2017.
Hosted by Zernebok Hosting.