Transport Tycoon Forums

The place to talk about Transport Tycoon
It is currently Tue Jul 25, 2017 2:56 pm

All times are UTC




Post new topic  Reply to topic  [ 54 posts ]  Go to page Previous 1 2 3 Next
Author Message
 Post subject:
PostPosted: Tue Aug 22, 2006 2:41 pm 
Offline
Route Supervisor
Route Supervisor
User avatar

Joined: Sun Apr 24, 2005 9:21 pm
Posts: 387
Location: Torquay, England
Quote:
FunctionsLookLikeThis(int i_am_a_variable)
{
code...
}


Any reason for the line break before the "{"? IMO, it looks ugly and wastes space.


Top
   
 Post subject:
PostPosted: Tue Aug 22, 2006 2:44 pm 
Offline
TTDPatch Developer
TTDPatch Developer

Joined: Wed Feb 18, 2004 3:06 am
Posts: 10285
Because that's what the style says. Live with it.

_________________
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 2:44 pm 
Offline
Tycoon
Tycoon
User avatar

Joined: Wed Oct 15, 2003 10:00 pm
Posts: 2566
Location: Jarrow, UK
iNVERTED wrote:
Quote:
FunctionsLookLikeThis(int i_am_a_variable)
{
code...
}


Any reason for the line break before the "{"? IMO, it looks ugly and wastes space.

It lines up with the } a the other end. You might think it's ugly, and it wouldn't work in a language with LISP-like syntax, but it's the chosen coding style. Changing the coding style with this much code already in the base is never a good idea, so don't pin your hopes on seeing it change. It won't.

If you dislike it, code in your own preferred manner, then convert it with indent before submitting it.

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


Top
   
 Post subject:
PostPosted: Tue Aug 22, 2006 3:01 pm 
Offline
OpenTTD Developer
OpenTTD Developer

Joined: Mon May 31, 2004 9:21 am
Posts: 1292
Brianetta wrote:
iNVERTED wrote:
Quote:
FunctionsLookLikeThis(int i_am_a_variable)
{
code...
}


Any reason for the line break before the "{"? IMO, it looks ugly and wastes space.

It lines up with the } a the other end. You might think it's ugly, and it wouldn't work in a language with LISP-like syntax, but it's the chosen coding style. Changing the coding style with this much code already in the base is never a good idea, so don't pin your hopes on seeing it change. It won't.

If you dislike it, code in your own preferred manner, then convert it with indent before submitting it.


And we like it. Period.

Brianetta: indent sucks ass :p Never makes indents like I want it :(


Top
   
 Post subject:
PostPosted: Tue Aug 22, 2006 4:24 pm 
Offline
Route Supervisor
Route Supervisor
User avatar

Joined: Sun Apr 24, 2005 9:21 pm
Posts: 387
Location: Torquay, England
Brianetta wrote:
It lines up with the } a the other end.


Well, that's inconsistent. You never have things like:

if (blah)
{

}

while (blah)
{

}


Top
   
 Post subject:
PostPosted: Tue Aug 22, 2006 6:10 pm 
Offline
Tycoon
Tycoon
User avatar

Joined: Mon May 02, 2005 11:05 am
Posts: 15415
Skype: XeryusTC
Location: localhost
iNVERTED wrote:
Brianetta wrote:
It lines up with the } a the other end.


Well, that's inconsistent. You never have things like:
*snip*

First of all, it isn't inconsistent, it makes the code more consistent as lines have their own brackets.
Second, it exists, I don't know if the (old) OTTD source has this kind of things but TRoS does it that way.

_________________
Don't panic - My YouTube channel - Follow me on twitter (@XeryusTC) - Play Tribes: Ascend - Tired of Dropbox? Try SpiderOak (use this link and we both get 1GB extra space)
Image
OpenTTD: manual #openttdcoop: blog | wiki | public server | NewGRF pack | DevZone
Image Image Image Image Image Image Image


Top
   
 Post subject:
PostPosted: Tue Aug 22, 2006 7:34 pm 
Offline
Route Supervisor
Route Supervisor
User avatar

Joined: Sun Apr 24, 2005 9:21 pm
Posts: 387
Location: Torquay, England
XeryusTC wrote:
iNVERTED wrote:
Brianetta wrote:
It lines up with the } a the other end.


Well, that's inconsistent. You never have things like:
*snip*

First of all, it isn't inconsistent, it makes the code more consistent as lines have their own brackets.
Second, it exists, I don't know if the (old) OTTD source has this kind of things but TRoS does it that way.


Huh?

In OTTD source, the only place where { goes on a line by itself is in functions. The if/while/whatever all had the { on the same line as the statement. Or maybe my memory just sucks. :P


Top
   
 Post subject:
PostPosted: Tue Aug 22, 2006 8:17 pm 
Offline
Tycoon
Tycoon
User avatar

Joined: Mon Feb 24, 2003 6:45 pm
Posts: 3051
Location: Hong Kong
iNVERTED wrote:
In OTTD source, the only place where { goes on a line by itself is in functions. The if/while/whatever all had the { on the same line as the statement. Or maybe my memory just sucks. :P


Yes, that is consistent. For all functions the braces are on a new line, for all else it's on the same line. Consistent.

_________________
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: Tue Aug 22, 2006 9:21 pm 
Offline
Tycoon
Tycoon
User avatar

Joined: Wed Oct 15, 2003 10:00 pm
Posts: 2566
Location: Jarrow, UK
TrueLight wrote:
Brianetta: indent sucks ass :p Never makes indents like I want it :(

I shall have to knock up an indent config for you...

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


Top
   
 Post subject:
PostPosted: Wed Aug 23, 2006 7:53 pm 
Offline
Tycoon
Tycoon
User avatar

Joined: Fri Mar 26, 2004 1:27 am
Posts: 1628
Location: Netherlands, Enschede
Darkvater wrote:
iNVERTED wrote:
In OTTD source, the only place where { goes on a line by itself is in functions. The if/while/whatever all had the { on the same line as the statement. Or maybe my memory just sucks. :P


Yes, that is consistent. For all functions the braces are on a new line, for all else it's on the same line. Consistent.

it's indeed consistent, but still... yuck :P

_________________
Creator of the Openttd Challenge Spinoff, Town Demand patch
The path to riches, a report on playing on a daylength server on ultra hard mode.


Top
   
 Post subject:
PostPosted: Wed Aug 23, 2006 10:14 pm 
Offline
Route Supervisor
Route Supervisor
User avatar

Joined: Sun Apr 24, 2005 9:21 pm
Posts: 387
Location: Torquay, England
Darkvater wrote:
iNVERTED wrote:
In OTTD source, the only place where { goes on a line by itself is in functions. The if/while/whatever all had the { on the same line as the statement. Or maybe my memory just sucks. :P


Yes, that is consistent. For all functions the braces are on a new line, for all else it's on the same line. Consistent.


*smacks forehead*


Top
   
 Post subject:
PostPosted: Wed Jan 17, 2007 1:17 pm 
Offline
Tycoon
Tycoon
User avatar

Joined: Mon Feb 24, 2003 6:45 pm
Posts: 3051
Location: Hong Kong
With the addition of C++ code to OpenTTD we will update the coding styles for C++ style constructs (overload, member variable, visibility, parameter, etc.).

Expect an updated opening post in the near future.

_________________
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
   
PostPosted: Tue Jan 22, 2008 8:37 pm 
Offline
Engineer
Engineer
User avatar

Joined: Fri Mar 12, 2004 6:14 pm
Posts: 13
Hi!

Found a goto while reading openttds code, so yesterday i searched the code for goto statements.... found 147!!! I hope you all know that using goto produces really really messy and bad bad code. Now there's 3 possibilities:
1. You didn't notice.
2. You don't care about bad code.
3. You don't have time for fixing it.
So, could you tell me which of these applies? ;)

Remember: Knowing what goto does is fine, but do not actually use it!

knuff

_________________
http://sf.net/projects/openttd


Top
   
PostPosted: Tue Jan 22, 2008 8:50 pm 
Offline
OpenTTD Developer
OpenTTD Developer

Joined: Thu Feb 09, 2006 7:15 pm
Posts: 3815
It's #3 that applies and "if it ain't broke, don't fix it".


Top
   
PostPosted: Tue Jan 22, 2008 9:32 pm 
Offline
TTDPatch Developer
TTDPatch Developer

Joined: Wed Feb 18, 2004 3:06 am
Posts: 10285
Knuff wrote:
So, could you tell me which of these applies? ;)
None of the above. Gotos are occasionally the best way to do things. Blind adherence to the rules causes code just as bad as blind flaunting of the rules. They even appear in the Linux kernel.

_________________
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
   
PostPosted: Tue Jan 22, 2008 11:58 pm 
Offline
Tycoon
Tycoon
User avatar

Joined: Wed Jun 06, 2007 9:07 pm
Posts: 1710
Location: Czech Republic
DaleStan wrote:
Gotos are occasionally the best way to do things.


For example if you have 3 nested for cycles and you want to break out of two inner levels. Without goto impossible ("break;" will only break one level), or at least impossible without setting some flags and issuing things like if (break_flag) break; at more levels. Which is ineffective. Though these situations hapen relatively rarely.

_________________
If you need something, do it yourself or it will be never done.

My patches: Extra large maps (1048576 high, 1048576 wide) (FS#1059), Vehicle + Town + Industry console commands (FS#1060), few minor patches (FS#2820, FS#1521, FS#2837, FS#2843), AI debugging facility

Other: Very large ships NewGRF, Bilbo's multiplayer patch pack v5 (for OpenTTD 0.7.3)


Top
   
PostPosted: Wed Jan 23, 2008 3:49 am 
Offline
TTDPatch Developer
TTDPatch Developer

Joined: Wed Feb 18, 2004 3:06 am
Posts: 10285
Another case, which actually can be done without any extra variables, is this:
Code:
while (true) {
   // code
      // more code
         // with lots and lots of nesting
            if (rare_condition_requiring_restart) continue;  // This happens maybe 1% of the time.
      // still more code
   // and some more
   break;
}
Using a label instead of the while and a goto instead of the continue means I can leave off the whole "while (true) { /*do stuff*/ break; }" thing. Is that insanity really preferable to a goto, Knuff?

_________________
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
   
PostPosted: Wed Jan 23, 2008 1:00 pm 
Offline
Tycoon
Tycoon
User avatar

Joined: Wed Jun 06, 2007 9:07 pm
Posts: 1710
Location: Czech Republic
DaleStan wrote:
Using a label instead of the while and a goto instead of the continue means I can leave off the whole "while (true) { /*do stuff*/ break; }" thing. Is that insanity really preferable to a goto, Knuff?


Not to mention if the "rare_condition_requiring_restart" would be nested in some for or while cycles, then the continue won't work, as it will "restart" only the inner cycle. Then you'll need either goto or something really horrible to handle that without goto. I guess goto would be fine in that case :)

_________________
If you need something, do it yourself or it will be never done.

My patches: Extra large maps (1048576 high, 1048576 wide) (FS#1059), Vehicle + Town + Industry console commands (FS#1060), few minor patches (FS#2820, FS#1521, FS#2837, FS#2843), AI debugging facility

Other: Very large ships NewGRF, Bilbo's multiplayer patch pack v5 (for OpenTTD 0.7.3)


Top
   
PostPosted: Fri Jan 25, 2008 12:52 am 
Offline
Engineer
Engineer

Joined: Thu Jul 29, 2004 11:47 pm
Posts: 15
Location: London
Knuff wrote:
I hope you all know that using goto produces really really messy and bad bad code.

Really really messy and bad code is produced by programmers, not the goto. Generally people will try to avoid gotos because they can make code harder to read and maintain, but as DaleStan says, occasionally they are the best way to do something.

I have seen an example of throwing an exception as a means of avoiding the use of a goto. Now that is.. let's say "creative".

DaleStan wrote:
Using a label instead of the while and a goto instead of the continue means I can leave off the whole "while (true) { /*do stuff*/ break; }" thing. Is that insanity really preferable to a goto, Knuff?

"continue" and "break" are effectively restricted goto statements anyway, so not really that much cleaner even if the example hadn't been this extreme.

_________________
When it is not necessary to make a decision, it is necessary not to make a decision - Lord Falkland (1610 - 1643)


Top
   
PostPosted: Sat Dec 13, 2008 7:56 pm 
Offline
Tycoon
Tycoon

Joined: Sun Dec 09, 2007 9:28 pm
Posts: 1919
It's like anything else, use it badly and it screws things up. Use it badly enough and people avoid it when it should really be used.

As an example, many programmers shy away from PHP because there are so many bad, insecure systems made with it. It's not that PHP is bad, in fact you can build things as good or better than any comparable language, but it's a mental thing.

Gotos, breaks and continues are at times the best way to do something. In functions, if I have the choice of an if(condition) break; twice, or a double nested if-else, I'll take the break.

When working as a community, consistent is more important than right.

_________________
Jon


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

All times are UTC


Who is online

Users browsing this forum: Google Feedfetcher 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.