Hilbert's Hotel

Diskussionsforum zur Unendlichkeit: Theismus, Atheismus, Primzahlen, Unsterblichkeit, das Universum...
Discussing Infinity: theism and atheism, prime numbers, immortality, cosmology, philosophy...

Gamestudio Links
Zorro Links
Newest Posts
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (AndrewAMD, Ayumi), 1,405 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 2 of 2 1 2
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 Offline
Senior Expert
Machinery_Frank  Offline
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":

Code:
displayNumber( arg, 14, 23 );
  
  if( arg < 10 ) { ...



should consequently be:

Code:
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.

Code:
if a>b then begin
  a:=...
end else a:=0;



reads better than:

Code:
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 wink


Models, Textures and Games from Dexsoft
Re: Coding practices - Arghh [Re: Machinery_Frank] #281739
07/28/09 12:03
07/28/09 12:03
Joined: Feb 2009
Posts: 2,154
Damocles_ Offline
Expert
Damocles_  Offline
Expert

Joined: Feb 2009
Posts: 2,154
I think a lot of the

if(...){
...
}

type of using bracket is from
the times when screensizes where small.
So The programmer saw maybe only 15 Lines of code at once
in the small window.

I prefer to see the code-list as long as possible nowerdays.

More importantly than the formatation is the
NAMING and COMMENTS in the code.

using too short and non-meaning variable / class names is
terrible.
Modern IDEs also have helpers to find attribute and function names of classes quickly, so even long names can be insterted quickly. (Eclipse etc.)

And I also wonder, when obsering code of other, how
little comments they add to it.

There is no reason to leave out comments about what the code is
dooing and what it is for. Having to "parse" the code manually
every time when looking at others code is an unnessesary waste of time.
The comments are usually shown in another color, so they dont really distract from reading
the doe itself.

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 Offline
Serious User
DJBMASTER  Offline
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 Offline
Expert
Joozey  Offline
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 grin

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 Offline
Senior Expert
Michael_Schwarz  Offline
Senior Expert

Joined: Aug 2003
Posts: 7,439
Red Dwarf
Originally Posted By: Machinery_Frank
Hm, Joozey and Michael, if you love spaces then you should be consequent and use them after every bracket and after tags like "if":

Code:
displayNumber( arg, 14, 23 );
  
  if( arg < 10 ) { ...



should consequently be:

Code:
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.

Originally Posted By: DJBMASTER
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:

Code:
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
J
JibbSmart Offline
Expert
JibbSmart  Offline
Expert
J

Joined: Mar 2006
Posts: 3,538
WA, Australia
Quote:
Code:
if( arg < 10 ) {
    arg = test( arg + 1 );
  }

Do you guys ever omit the brackets?:
Code:
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:
Code:
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: JibbSmart] #281869
07/29/09 05:43
07/29/09 05:43
Joined: Oct 2005
Posts: 4,771
Bay City, MI
lostclimate Offline
Expert
lostclimate  Offline
Expert

Joined: Oct 2005
Posts: 4,771
Bay City, MI
Code:
variables:

type varName;

Functions:
function/type DoWhatever (arg1, arg2.... )
{
   return CallOtherFunction();
}


Conditionals:

if(someThing >= 0)
{
    DoWhatever(42,42);
}
else
{
    youSuck=True;
}




also I like to keep my variables classes, functions and objects declared in the .h file and the processes in the .c file, but that is just so that I don't get myself confused switching back and forth from vc++

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 Offline
Senior Expert
Machinery_Frank  Offline
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:

Code:
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 Offline
Senior Expert
PHeMoX  Offline
Senior Expert

Joined: Sep 2002
Posts: 8,177
Netherlands
Quote:
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.


PHeMoX, Innervision Software (c) 1995-2008

For more info visit: Innervision Software
Page 2 of 2 1 2

Moderated by  jcl, Lukas, old_bill, Spirit 

Kompaktes W�rterbuch des UnendlichenCompact Dictionary of the Infinite


Powered by UBB.threads™ PHP Forum Software 7.7.1