Page 3 of 3

Re: OpenTTD Coding Style and Guidelines

Posted: 15 May 2009 07:31
by ColdIce
it`s time for me to learn some c++. right now I don`t know nothing about coding. I don`t even know what program I must use to create a program/patch etc, so can you tell me what program I must use to begin? thank you

I have a book, something like C++ for dummies :P

Re: OpenTTD Coding Style and Guidelines

Posted: 15 May 2009 12:33
by Roujin
What OS are you running?

Re: OpenTTD Coding Style and Guidelines

Posted: 15 May 2009 12:39
by planetmaker
Whatever, you should definitely read that page which answers those questions http://wiki.openttd.org/Development

Re: OpenTTD Coding Style and Guidelines

Posted: 15 May 2009 13:18
by ColdIce
@ Roujin : Windows Xp SP3

@planetmaker: yes, I know that page. Right now i don`t want to know from the start how to make a patch, right now I need to know the name of the program(s) where I will put those lines. You can call me idiot, stupid or whatever, I just don`t know even that simple thing for you, but I want to learn, ok? All I need right is just a straight answer and that`s the name of the program.. and maybe an informative link. If you can help me with that please leave an answer.

thank you.

Re: OpenTTD Coding Style and Guidelines

Posted: 15 May 2009 13:42
by Hirundo
ColdIce wrote:... and maybe an informative link...
http://wiki.openttd.org/Microsoft_Visua ... s_Editions

Re: OpenTTD Coding Style and Guidelines

Posted: 17 May 2009 11:03
by Roujin
Yup, that's what I would also recommend if you're on windows.

here's the corresponding wiki page: http://wiki.openttd.org/Microsoft_Visua ... s_Editions

Re: OpenTTD Coding Style and Guidelines

Posted: 05 Sep 2009 10:51
by adf88
I wrote some time ago a regular expression to find some common coding style mistakes in MSVC using search tool. Probably someone will find it useful (MS syntax):

(:b$)|(^\t* [^*])|([^\t]\t)|(^:b*(([^/*:b]|(/[^/*]))([^/]|(/[^/*]))* )|()((if)|(while)|(for)|(switch))(([^{]\n:b*\{)|(\()))|(XXX)|(^\t*//)|(^\t*[^#\t].*/\*)

With this expression you can find:
- whitespace at the end of line
- tabs that are not at the beginning of line
- spaces before first non-whitespace character in the line, except one space before asterisk "*" (multiline comments)
- some mistakes in comments (I can't remember exactly)
- left brace "{" in wrong place after if/while/for/switch directive
- newline after if/while/for/switch directive without left brace "{" after
- no space after if/while/for/switch keyword
(inspired by Alberths expression):
- "XXX" string
- c comment "/*" after line with text, but not including preprocessor directives (hash "#" at the beginning)
- cpp comment "//" without text before

... and probably something more that I can't remember, I won't analyse this creepy expression till it works well.

If you have any concrete, real suggestions to improve expression - write them here.

Re: OpenTTD Coding Style and Guidelines

Posted: 05 Sep 2009 11:22
by Alberth
I have been using a python program for some time.
Usage:

Code: Select all

python chk_patch.py <name of patch-file>
Your checks are somewhat different, maybe they can be merged in some way. (Feel free to do so and post an update.)

Re: OpenTTD Coding Style and Guidelines

Posted: 05 Sep 2009 13:17
by DaleStan
adf88 wrote:(:b$)|(^\t* [^*])|([^\t]\t)|(^:b*(([^/*:b]|(/[^/*]))([^/]|(/[^/*]))* )|()((if)|(while)|(for)|(switch))(([^{]\n:b*\{)|(\()))
Are you quite sure that's not line noise? :p

(Sorry. This isn't a suggestion. I'm just impressed.)

Re: OpenTTD Coding Style and Guidelines

Posted: 05 Sep 2009 13:23
by adf88
DaleStan wrote:Are you quite sure that's not line noise? :p
I know this looks like ASCII-spaghetti :p but works well and I don't have to touch it.

BTW, my expression can find a lot of code that brakes coding style rules in whole OTTD project. In the current trunk search tool found 757 lines. More then 50% of them is not properly formatted code. The rest is some exceptions to coding style rules.

Re: OpenTTD Coding Style and Guidelines

Posted: 26 Sep 2009 11:04
by adf88
I updated coding style wiki, indentation has been inconsistent. One time it has been made with tabs, another with two spaces, another with three spaces... some snippets have had one space before each line ...

Now it's the same as in properly formatted source code.

I have a proposition - maybe replace all tabs with:

Code: Select all

(space, right arrow, space)

and spaces with:

Code: Select all

·
(middle dot)

so people could see exactly which, where and how many whitespace characters are used?

Re: OpenTTD Coding Style and Guidelines

Posted: 30 Mar 2011 07:01
by adf88
What about reference template arguments? i.e.

Code: Select all

template <const int &Tvar> ... 
Are they considered as not supported by some compilers thus forbidden?
What are the guides for variable/function/member references as template arguments?

Re: OpenTTD Coding Style and Guidelines

Posted: 08 Oct 2011 20:09
by Korenn
The link is broken, it links to http://wiki.openttd.org/Index.php/Coding_style

where it should link to: http://wiki.openttd.org/Coding_style

url rewrite, I guess ;)

Re: OpenTTD Coding Style and Guidelines

Posted: 21 Jul 2013 00:43
by xtifr
I wish to register a complaint. I wish to complain about this parrot, what I purchased not half an hour ago from this very boutique....

Oh, wait, sorry, wrong sketch. No, my complaint, which I freely admit may be too little too late, is about this portion of the style guideline:
Global variables are preceded by an underscore. ("_")
This is a violation of the relevant ISO standards, which say that identifiers which start with an underscore are reserved for the implementation (compiler and standard libraries) at the global scope, and that identifiers which start with an underscore followed by a capital letter are reserved everywhere. Application programs are not allowed to use these names for globals.

Now, I admit that you've gotten away with it so far, and that fixing it at this late date may be more trouble than it's worth, but I think you should at least know that you're essentially relying on undefined behavior here. The compiler is perfectly within it's rights to translate every reference to any such global into system("/usr/local/games/nethack").

(In fact, one early version of gcc actually did that last with any #pragma it saw, simply to emphasize that a 100%-compiler-dependent "standard" feature gives you no guarantees of anything. I admit that it's unlikely that they'd do the same with identifiers that happen to start with underscore, but they could do so and still claim to have a standards-compliant compiler.)

Anyway, I guess I don't really object to you violating the international standards for the language, but I think it's important that you know you're violating the international yada yada. So, consider yourself informed. What you do with that knowledge is up to you.

references:
* Bjarne Stroustrup, The C++ Programming Language, Third Edition, Addison Wesley, 1997, pg 81.
* Ray Lischner, C++ in a Nutshell, O'Reilly & Associates, 2003, pg 3.

cheers

Re: OpenTTD Coding Style and Guidelines

Posted: 09 May 2019 18:14
by SciFurz
It would be nice to see an explanation of the purpose of each filename type (on the development pages), namely what goes in/what use are the _base, _func, _type, _cmd, _gui, etcetera files.
Some are pretty obvious like _cmd and _gui, and of course .h and .cpp, but the other ones are not so clear.

Re: OpenTTD Coding Style and Guidelines

Posted: 16 May 2019 09:44
by orudge
If you haven't seen this guide, it's very interesting and worth a read.

Re: OpenTTD Coding Style and Guidelines

Posted: 16 May 2019 20:46
by SciFurz
orudge wrote:If you haven't seen this guide, it's very interesting and worth a read.
That looks very useful, will be digging through it in the coming days.