Style guide

Get help with programming issues.

Moderator: PPS-Leaders

User avatar
patrick
Baron Vladimir Harkonnen
Posts: 350
Joined: Mon Oct 02, 2006 6:03 pm
Location: Bern

Post by patrick » Mon Nov 05, 2007 12:36 pm

Nice work guys! I agree to your ideas and comments.

User avatar
1337
Baron Vladimir Harkonnen
Posts: 521
Joined: Wed Oct 10, 2007 7:59 am

Post by 1337 » Tue Nov 27, 2007 8:45 pm

As of now, I have created a namespace for every subproject (like namespace "weapon" for my little project).

If nobody complains, I'm going to change that and simply create one namespace: orxonox.
And I'm also going to change the styleguide then. But I'll give it a little time...

Oh, there's something else: What is so important about keeping the code size to 80 characters, if almost everyone is using an IDE anyway?
I mean I wouldn't exactly agree to 200 characters, but 120 would be extremely more comfortable.
For instance it is now very common to use full names for variables and functions which makes them quite long. And then for a longer argument list you have to make line breaks and in order to improve readability you indent 2 or 3 tabs. All that within a namespace, function and "if" --> 68 characters left. And in a worst case scenario you can write two or three words per line because the next word is already too long to fit in.
I'm sorry to say that for all those who program with an 80 char console..
http://www.xkcd.com/
A webcomic of romance, sarcasm, math, and language.

User avatar
beni
Baron Vladimir Harkonnen
Posts: 949
Joined: Tue Oct 03, 2006 9:15 am
Location: Zurich
Contact:

Post by beni » Tue Nov 27, 2007 10:19 pm

1337 wrote:I'm sorry to say that for all those who program with an 80 char console..
Whoever that is...
"I'm Commander Shepard and this is my favorite forum on the internet."

User avatar
1337
Baron Vladimir Harkonnen
Posts: 521
Joined: Wed Oct 10, 2007 7:59 am

Post by 1337 » Tue Nov 27, 2007 10:59 pm

beni wrote:
1337 wrote:I'm sorry to say that for all those who program with an 80 char console..
Whoever that is...
When I was doing the exercises for informatics I, I used to code with vim and the console. And consoles were or are (don't know) limited to 80 characters. Which is why programmers got used to not writing more than 80 chars on one line.
http://www.xkcd.com/
A webcomic of romance, sarcasm, math, and language.

User avatar
beni
Baron Vladimir Harkonnen
Posts: 949
Joined: Tue Oct 03, 2006 9:15 am
Location: Zurich
Contact:

Post by beni » Wed Nov 28, 2007 8:19 am

Yeah I know. I remember my first year where I got minus points in my info exercises when the lines where longer.

What I meant: Who still writes with a console? Nearly everybody has an IDE and those who don't have at least a text editor like kate, kwrite, gedit or something. Even with nano it's possible to write lines longer than 80 characters.

I dunno.. but I don't think that anyone would even notice that, if the code was wider than 80 characters.
"I'm Commander Shepard and this is my favorite forum on the internet."

User avatar
patrick
Baron Vladimir Harkonnen
Posts: 350
Joined: Mon Oct 02, 2006 6:03 pm
Location: Bern

Post by patrick » Sun Dec 02, 2007 11:07 am

I expected someone to come up with this line-width-80 question :D I know that the code might look crapier and needs more time to format. But there are lots of people that use standard 80char consoles to code. For example I often look at code withvim/emacs in a console conected over ssh, in this case you will never have to worry about resizing your console.

But I know, there is no very strong reason to limit it to 80chars. Decide yourselfs if you want to go with the old fashioned 80 chars. But I suggest to have a line width limit otherwise, people with 24" screens will have a big advantage :D

User avatar
1337
Baron Vladimir Harkonnen
Posts: 521
Joined: Wed Oct 10, 2007 7:59 am

Post by 1337 » Sun Dec 02, 2007 11:34 am

Since I myself use vim, when I am in need of an editor, I think I'll stick to these 80-chars limit mostly, for instance for all comments. There you have to make line breaks anyway...

What about placing header files in header files?
I have compiled a list with all my class prototypes and called it "orxonox_prequisites". The entries are simply class BaseWeapon; class OrxonoxShip; class BarrelGun; etc.
We only have to make a few of these files and when someone adds a new class, he can edit the right file.
The advantage is, that whenever you want to use object pointers in class declarations (only works for pointers) in header files, eg. BarrelGun *myGun_; or in an argument list of a function, you can simply include the files with all the prototypes.
This way you can save a lot of compile time: Imagine you include "asdf.h" in your *.cc file and asdf itself includes "foo.h" and "bar.h". Now you have to compile 3 header files though you only need one: "asdf.h".
Of course right now this isn't a problem, but when the project grows, compile time grows too.

What do you think?
(This idea by the way, is from the Ogre source code)
http://www.xkcd.com/
A webcomic of romance, sarcasm, math, and language.

User avatar
1337
Baron Vladimir Harkonnen
Posts: 521
Joined: Wed Oct 10, 2007 7:59 am

Post by 1337 » Sat Dec 15, 2007 4:59 pm

SO WHAT IS IT NOW?

2, or 4 spaces per tab? We really need to agree to a standard!

The style guide says 2..
http://www.xkcd.com/
A webcomic of romance, sarcasm, math, and language.

User avatar
x3n
Baron Vladimir Harkonnen
Posts: 810
Joined: Mon Oct 30, 2006 5:40 pm
Contact:

Post by x3n » Sat Dec 15, 2007 7:35 pm

I don't care about the 80 char limit. Of course I understand the reason, but 99% of the users don't have a problem with larger lines and that's enough.

@2 or 4 spaces per tab: I can hardly read code with 2 space tabs, that's why I'm using 4 in my code, but it's only a personal preference. Is there a good reason for using 2 spaces?

User avatar
beni
Baron Vladimir Harkonnen
Posts: 949
Joined: Tue Oct 03, 2006 9:15 am
Location: Zurich
Contact:

Post by beni » Sun Dec 16, 2007 12:08 pm

x3n wrote:Is there a good reason for using 2 spaces?
You don't exceed the 80 char limit too quickly ;)
"I'm Commander Shepard and this is my favorite forum on the internet."

User avatar
1337
Baron Vladimir Harkonnen
Posts: 521
Joined: Wed Oct 10, 2007 7:59 am

Post by 1337 » Sun Dec 16, 2007 1:22 pm

beni wrote:
x3n wrote:Is there a good reason for using 2 spaces?
You don't exceed the 80 char limit too quickly ;)
Actually you do, but never mind me saying that...

#x3n: I totally agree with you. I once had 3 or 4 spaces as a tab, since it really brings more readability into the code. Anyway, I had to change. So, if I can make things finally compile under VC8, and if I have to edit the WorldEntity, I will adapt your file to 2 tabs ;)
But as of right now, I'm still having trouble (at least one more with the getMouseState()) compiling the project. And I really doubt it will run in the first attempt.
http://www.xkcd.com/
A webcomic of romance, sarcasm, math, and language.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest