OpenTTD Coding Style and Guidelines
Moderator: OpenTTD Developers
Re: OpenTTD Coding Style and Guidelines
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
I have a book, something like C++ for dummies
The rest is confetti!
Re: OpenTTD Coding Style and Guidelines
What OS are you running?
- planetmaker
- OpenTTD Developer
- Posts: 9432
- Joined: 07 Nov 2007 22:44
- Location: Sol d
Re: OpenTTD Coding Style and Guidelines
Whatever, you should definitely read that page which answers those questions http://wiki.openttd.org/Development
OpenTTD: manual | online content | translations | Wanted contributions and patches
#openttdcoop: blog | wiki | public server | DevZone | NewGRF web translator
DevZone - home of the free NewGRFs: OpenSFX | OpenMSX | OpenGFX | Swedish Rails | OpenGFX+ Trains|RV|Industries|Airports|Landscape | NML
Re: OpenTTD Coding Style and Guidelines
@ 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.
@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.
The rest is confetti!
Re: OpenTTD Coding Style and Guidelines
http://wiki.openttd.org/Microsoft_Visua ... s_EditionsColdIce wrote:... and maybe an informative link...
Create your own NewGRF? Check out this tutorial!
Re: OpenTTD Coding Style and Guidelines
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
here's the corresponding wiki page: http://wiki.openttd.org/Microsoft_Visua ... s_Editions
Re: OpenTTD Coding Style and Guidelines
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.
(: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.
Last edited by adf88 on 25 Sep 2009 07:38, edited 10 times in total.
don't worry, be happy and checkout my patches
Re: OpenTTD Coding Style and Guidelines
I have been using a python program for some time.
Usage:Your checks are somewhat different, maybe they can be merged in some way. (Feel free to do so and post an update.)
Usage:
Code: Select all
python chk_patch.py <name of patch-file>
- Attachments
-
- chk_patch.py.txt
- Python file to check patch files for coding mistakes (drop the .txt extension).
- (1.47 KiB) Downloaded 344 times
Re: OpenTTD Coding Style and Guidelines
Are you quite sure that's not line noise?adf88 wrote:(:b$)|(^\t* [^*])|([^\t]\t)|(^:b*(([^/*:b]|(/[^/*]))([^/]|(/[^/*]))* )|()((if)|(while)|(for)|(switch))(([^{]\n:b*\{)|(\()))
(Sorry. This isn't a suggestion. I'm just impressed.)
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
Projects: NFORenum (download) | PlaneSet (Website) | grfcodec (download) | grfdebug.log parser
Re: OpenTTD Coding Style and Guidelines
I know this looks like ASCII-spaghetti but works well and I don't have to touch it.DaleStan wrote:Are you quite sure that's not line noise?
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.
don't worry, be happy and checkout my patches
Re: OpenTTD Coding Style and Guidelines
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:(space, right arrow, space)
and spaces with:(middle dot)
so people could see exactly which, where and how many whitespace characters are used?
Now it's the same as in properly formatted source code.
I have a proposition - maybe replace all tabs with:
Code: Select all
→
and spaces with:
Code: Select all
·
so people could see exactly which, where and how many whitespace characters are used?
don't worry, be happy and checkout my patches
Re: OpenTTD Coding Style and Guidelines
What about reference template arguments? i.e.Are they considered as not supported by some compilers thus forbidden?
What are the guides for variable/function/member references as template arguments?
Code: Select all
template <const int &Tvar> ...
What are the guides for variable/function/member references as template arguments?
don't worry, be happy and checkout my patches
Re: OpenTTD Coding Style and Guidelines
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
where it should link to: http://wiki.openttd.org/Coding_style
url rewrite, I guess
Creator of the Openttd Challenge Spinoff, Town Demand patch
After action reports: The path to riches, A dream of skyscrapers
After action reports: The path to riches, A dream of skyscrapers
Re: OpenTTD Coding Style and Guidelines
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:
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
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:
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.Global variables are preceded by an underscore. ("_")
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
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.
Some are pretty obvious like _cmd and _gui, and of course .h and .cpp, but the other ones are not so clear.
Tinkering in the code in between writing mostly naughty stuff.
See http://scifurz.wordpress.com/
See http://scifurz.wordpress.com/
- orudge
- Administrator
- Posts: 25137
- Joined: 26 Jan 2001 20:18
- Skype: orudge
- Location: Banchory, UK
- Contact:
Re: OpenTTD Coding Style and Guidelines
If you haven't seen this guide, it's very interesting and worth a read.
Re: OpenTTD Coding Style and Guidelines
That looks very useful, will be digging through it in the coming days.orudge wrote:If you haven't seen this guide, it's very interesting and worth a read.
Tinkering in the code in between writing mostly naughty stuff.
See http://scifurz.wordpress.com/
See http://scifurz.wordpress.com/
Who is online
Users browsing this forum: No registered users and 17 guests