1 registered members (AndrewAMD),
1,248
guests, and 6
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: Coding practices - Arghh
[Re: Joozey]
#281689
07/28/09 06:56
07/28/09 06:56
|
Joined: Nov 2004
Posts: 7,121 Potsdam, Brandenburg, Germany
Machinery_Frank
Senior Expert
|
Senior Expert
Joined: Nov 2004
Posts: 7,121
Potsdam, Brandenburg, Germany
|
Hm, Joozey and Michael, if you love spaces then you should be consequent and use them after every bracket and after tags like "if":
displayNumber( arg, 14, 23 );
if( arg < 10 ) { ...
should consequently be:
displayNumber ( arg, 14, 23 );
if ( arg < 10 ) { ...
I personally think that it does not help and the eye has to move too much to get the info. But I also prefer the pascal style and the "begin, end" commands instead of brackets. It is better readable for a human being.
if a>b then begin
a:=...
end else a:=0;
reads better than:
if (a>b) {
a=...
} else a=0;
But in the end all this does not matter if we can make a job done with each of them
Models, Textures and Games from Dexsoft
|
|
|
Re: Coding practices - Arghh
[Re: Damocles_]
#281743
07/28/09 12:49
07/28/09 12:49
|
Joined: Nov 2007
Posts: 1,143 United Kingdom
DJBMASTER
Serious User
|
Serious User
Joined: Nov 2007
Posts: 1,143
United Kingdom
|
What notation you guys prefer when you're defining variables/functions...
1) foo_bar 2) FooBar 3) fooBar
I prefer the first one for variables, but always use the second one (Pascal notation) for functions.
Also does anyone prefer the ternary operator to if/else? I hardly use it.
Last edited by DJBMASTER; 07/28/09 12:50.
|
|
|
Re: Coding practices - Arghh
[Re: DJBMASTER]
#281777
07/28/09 15:43
07/28/09 15:43
|
Joined: Oct 2004
Posts: 4,134 Netherlands
Joozey
Expert
|
Expert
Joined: Oct 2004
Posts: 4,134
Netherlands
|
My screen is still not large. I see about 30 lines in my screen. Perhaps that's indeed the reason why I prefer brackets in front of statements. @frank: I prefer to attach the ( to an if, because it looks more like the statement is part of the if, like encapulated. I think very visual in these styles. It's like a tiny machine that holds content, and processes it. I wouldn't mind a language made out of ascii art if( a + b = c ) { } [(> a + b = c <)]::> <:: @DJBMASTER There are actually common rules for markup, though not strictly followed. Classes and constants get a capital letter: class HelloYou {}; const int HelloYou; Variables and methods a small letter: int helloYou; void helloYou(); Header definitions all capital: #ifndef __HELLOYOU_HPP__ #define __HELLOYOU_HPP__ and I'm sure there are more which I can't think of right now. I tend to use an underscore _ when names consist of categories and a function description. void playerInventoryItem_create(); void enemyWeapon_remove();
Last edited by Joozey; 07/28/09 15:52.
Click and join the 3dgs irc community! Room: #3dgs
|
|
|
Re: Coding practices - Arghh
[Re: DJBMASTER]
#281789
07/28/09 17:01
07/28/09 17:01
|
Joined: Aug 2003
Posts: 7,439 Red Dwarf
Michael_Schwarz
Senior Expert
|
Senior Expert
Joined: Aug 2003
Posts: 7,439
Red Dwarf
|
Hm, Joozey and Michael, if you love spaces then you should be consequent and use them after every bracket and after tags like "if":
displayNumber( arg, 14, 23 );
if( arg < 10 ) { ...
should consequently be:
displayNumber ( arg, 14, 23 );
if ( arg < 10 ) { ...
I personally think that it does not help and the eye has to move too much to get the info. That would be overkill. I just want variables separated from operators, and arguments separated so you can "count" them quickly. What notation you guys prefer when you're defining variables/functions...
1) foo_bar 2) FooBar 3) fooBar
I prefer the first one for variables, but always use the second one (Pascal notation) for functions.
Also does anyone prefer the ternary operator to if/else? I hardly use it. Depends, as we have no "IntelliSense" in SED like in Visual Studio, I use different naming conventions for c-script than I use in C# using visual studio. example from c-script:
function vDialogReadFrom(sFilename)
{
if(ibDialogInProgress == true){ return; } else { ibDialogInProgress = true; }
sysDialogHandle = file_open_read(sFilename);
while(file_str_readto(sysDialogHandle, sDialogCurIn, sDialogDelimiter, 1000) != -1)
{
the prefixes: v - void s - string sys - something engine internal, like file handles ib - internal boolean etc... helps while reading the code, you know exactly what variable stores what kind of information.
"Sometimes JCL reminds me of Notch, but more competent" ~ Kiyaku
|
|
|
Re: Coding practices - Arghh
[Re: Michael_Schwarz]
#281864
07/29/09 02:13
07/29/09 02:13
|
Joined: Mar 2006
Posts: 3,538 WA, Australia
JibbSmart
Expert
|
Expert
Joined: Mar 2006
Posts: 3,538
WA, Australia
|
if( arg < 10 ) {
arg = test( arg + 1 );
}
Do you guys ever omit the brackets?:
if (arg < 10)
arg = test(arg + 1);
...is how I will do it whenever there's only one line in the "if". I like it clean and minimalist. I know I could go further and have "if (arg < 10) arg = test(arg + 1);" in one line, but I like going down a line and indenting because it means there's always an indented line after my "if"s, whether they're one-liners or not. Also, I like a space between the "if", "else", or "while" and the opening parenthesis, but no space between parentheses and arguments. I would do Joozey's example like this:
void test(int arg) {
displayNumber(arg, 14, 23);
if (arg < 10)
arg = test(arg + 1);
else if (arg == -1 ||
arg == -3 ||
arg == -5)
return -1;
else
return 0;
}
I wish Lite-C supported ternary expressions. I quite like "x = x < 0 ? -x : x;" for finding the absolute value, for example (though since there's a built in function, I'd use "abs" anyway, but that's just an example). Jibb
Formerly known as JulzMighty. I made KarBOOM!
|
|
|
Re: Coding practices - Arghh
[Re: lostclimate]
#281875
07/29/09 07:22
07/29/09 07:22
|
Joined: Nov 2004
Posts: 7,121 Potsdam, Brandenburg, Germany
Machinery_Frank
Senior Expert
|
Senior Expert
Joined: Nov 2004
Posts: 7,121
Potsdam, Brandenburg, Germany
|
I find Jibb's style very comfortable to read. And as far as I can remember I did most typing in a very similar way. But I probably would try to write a short if-command without a break. If you have 10 thousands of lines in your code then you know what I am talking about:
if (arg < 10) arg = test(arg + 1);
This is good to read, compact and does not waste too much space.
Models, Textures and Games from Dexsoft
|
|
|
Re: Coding practices - Arghh
[Re: Damocles_]
#285682
08/19/09 16:53
08/19/09 16:53
|
Joined: Sep 2002
Posts: 8,177 Netherlands
PHeMoX
Senior Expert
|
Senior Expert
Joined: Sep 2002
Posts: 8,177
Netherlands
|
using too short and non-meaning variable / class names is terrible. I tend to use that all the time and it doesn't seem to bother me much. Of course, my code usually is commented properly, so it's actually not meaningless stuff. Short(er) names do make me program a lot faster.
|
|
|
|