Massassi Forums Logo

This is the static archive of the Massassi Forums. The forums are closed indefinitely. Thanks for all the memories!

You can also download Super Old Archived Message Boards from when Massassi first started.

"View" counts are as of the day the forums were archived, and will no longer increase.

ForumsDiscussion Forum → A poll for the programmers
A poll for the programmers
2005-04-28, 11:48 PM #1
Since Massassi is freaking chock full of coders, I figured it might be fun to post a little poll. Which styles do you prefer with your brackets/code blocks?

1. How do you prefer your code blocks?

I don't like the begin and end way. I do like it like this:
Code:
while (i < 100) {
    doThings(i);
    i++;
}

// I think this is ugly
while(i < 100)
{
    doThings(i);
    i++;
}


2. How do you prefer your if - else if - else blocks?

Personally, I like them like this:
Code:
if(something) {
    doStuff();
    doMoreStuff();
}
else {
    doOtherStuff();
    break;
}

// I can't stand this trash:
if(something) {
    doStuff();
    doMoreStuff();
} else {
    doOtherStuff();
    break;
}

// this is okay, I guess
if(something)
{
    doStuff();
    doMoreStuff();
}
else
{
    doOtherStuff();
    break;
}


3. Do you use curly braces for clarity even if you don't need them?

I don't. For example, do you go like this:
Code:
if(something)
    index++;

// or like this:

if(something) {
    index++;
}


4. What is your capitalization style for identifiers?

I learned Java first, and it corrupted me, so I tend to start everything lowercase and capitalize trailing words, for both function names and variables. Sample identifiers:
Code:
int size;
int numberOfPenguins;
doSomethingReallyNeat();
// etc.


5. Do you use any more in-depth naming conventions, such as Hungarian notation, denoting type in the identifier itself, etc.?

Personally, I don't. I find it gets kind of cluttered and it makes programs hell for other people to read. I've come across a lot of people who like to put an underscore in front of member variables, and that drives me up the wall.

6. What is your preference with whitespace in general?

I like spaces. I use them everywhere. For example:
Code:
for(int i = 0; i < 100; i++)

// instead of
for(int i=0;i<100;i++)


All of my operators are usually surrounded by spaces. It's 1 + i, not 1+i. I also like to put spaces around paranthesis, for clarity. while( (line = br.readLine() ) != null), for example. I generally don't put a space between keywords and parenthesis, though, so it's if(something) instead of if (something), etc. Finally, I also put spaces between arguments, so it's new Color(255, 255, 255) instead of new Color(255,255,255).

7. What kind of comments do you use and how? If you have a complex/well-defined commenting style, describe it.

I use C-style comments with unnecessary but nice-looking asterisks at the start of every line to describe functions and classes. I use C++ style comments for comments within functions and very short comments after a line of code. For example, I tend to write comments like this:
Code:
/*
 * This class does a bunch of stuff. Blah blah blah
 * blah blah blah blah blah.
 */
public class Foo {

    int numberOfMonkeys; // monkeylicious!

    /*
     * This function kills the specified monkey!
     */
    public void killMonkey(int monkey) {
    ...
    }
}


8. Continuing with the idea of whitespace, what does the layout of your code usually look like? Is it all clumped together, do you try to have some blank lines here and there?

Sometimes, if I find there is a lot of code without any blank lines, I'll try to categorize 'like' code, that kind of fits together, and I'll stick an arbitrary blank line, just to break things up. I generally like to stick 3 or 4 lines between functions and stuff, too.

9. Post anything else you can think of that further defines your style, or your annoyances with other peoples' code.

One of my pet peeves is people who see two perfectly good lines of clear code and merge it into one line, making one, long, esoteric line of code. I try to have one line of code do one distinct thing, even though of course that's difficult to do at times. I'm just saying something like this gets old after a while:
Code:
String thing = (String) ( (int) (Character) list.get( getIndex(i % offset) ) >> 3 );


I don't like people who abuse line delimeters and stick 4 lines of code on a single line. Stuff like int i = 0; doStuff(); int index = word.lastIndex(ID); doMoreStuff(); all on one line makes me want to kill. People who do this in switch statements really piss me off.

People who are working on a project with you and intentionally write obfuscated code just so it looks impressive, then forgets it 2 days later, meanwhile leaving you no chance in hell to figure out what the hell he was trying to do.

Again, this spot is for other misc. things that either further define your style or your pet peeves.

Anyway, it would be neat for whoever can participate in this poll to do so. I'm kind of interested in how other people like to do things.
"it is time to get a credit card to complete my financial independance" — Tibby, Aug. 2009
2005-04-29, 12:16 AM #2
Code:
% ZERO APPLIED FORCES

a=1;
b=1;

for a=1:n
	d(a).fx = 0;
	d(a).fy = 0;
end

% CONTACT DETECTION CODE
% PART 1 - Disc to Disc

for a = 1:n
	for b = 1:n
		if 	 isequal(a,b) == 1
			 continue
		else dist = norm([d(a).x d(a).y] - [d(b).x d(b).y],2);
		end
		if dist <= (d(a).r + d(b).r)
			d(a).c(b) = b;
			d(b).c(a) = a;
			d(a).c = nonzeros(d(a).c).';
			d(b).c = nonzeros(d(b).c).';
		elseif dist > (d(a).r + d(b).r)
			d(a).c(b) = 0;
			d(b).c(a) = 0;
			d(a).c = nonzeros(d(a).c).';
			d(b).c = nonzeros(d(b).c).';
		end
	end
end


Does that answer your question? It's pretty much a standard chunk of how I lay my code out in MATLAB.
2005-04-29, 12:35 AM #3
Let's See:
1.) I used to do all braces on their own lines, but now I trail the first brace.

Actually, I don't feel like answering all these questions, so I'm going to say that I usually use a lot of whitespace but it depends on the nature of the project. If I'm doing a quick and dirty app, it's quick and dirty, but itf it's big I space everythign out.
Ban Jin!
Nobody really needs work when you have awesome. - xhuxus
2005-04-29, 12:55 AM #4
1. How do you prefer your code blocks?
Code:
while(i < 100)
{
    doThings(i);
    i++;
}

Have to vote for that style. I find it easier to match up braces when the closing brace is in line with the opening brace. Along with indentation of course.

2. How do you prefer your if - else if - else blocks?

Personally, I like them like this:
Code:
if(something)
{
    doStuff();
    doMoreStuff();
}
else
{
    doOtherStuff();
    break;
}

I don't like anything to be on the line after a closing brace. Except sometimes a comment if its a long code block to say which conditional statement it is closing.

3. Do you use curly braces for clarity even if you don't need them?

Yes. For single line blocks, thogh, I put the braces and statement all on one line.
Code:
if(something)
{ index++; }


4. What is your capitalization style for identifiers?

I don't have a particular style I conciously use, although I guess if you looked at my code you'd spot one fairly quickly.

5. Do you use any more in-depth naming conventions, such as Hungarian notation, denoting type in the identifier itself, etc.?

Member variables of a class always have a m_ prefix. I occasionally use a type prefix where it will add to clarity, but it's not always.

6. What is your preference with whitespace in general?

I like to have a space infront of parentheses where it is not a function's parameter list. Functions don't have a space between their name and the opening parenthesis.
I don't like to put spaces after the opening or before the closing parenthesis.
I do put a space between arguments.
Spaces around infix operators.

Code:
for (i = 0; i < 10; i++) {}
examplefunction(arg1, arg2);

That example reminds of my third case for braces. When it's an empty code block (which I've only used twice - it's a rare construct) they both live at the end of the line and there is no space between them. Unless I write a comment that it is explicitly doing nothing in that code block or the language has a NULL statement. In that case it's like a single line block.

7. What kind of comments do you use and how? If you have a complex/well-defined commenting style, describe it.

Single line comments within blocks and functions.

Multi line comments at the top of files.

If a function needs an explanation, then it is a multi line block directly above the function.

With multi line comments then I also use asterisks down the side of it.

Code:
/* File name
 * =========
 * Brief explanation
 */

/* function
 * ========
 * This function does stuff
 */
function(arg1, arg2)
{
  // do something
  arg1 operator arg2;
}


8. Continuing with the idea of whitespace, what does the layout of your code usually look like? Is it all clumped together, do you try to have some blank lines here and there?

I like to group related functions together separated by a single line, and separate those groups of functions with a double line.

9. Post anything else you can think of that further defines your style, or your annoyances with other peoples' code.

Annoyances:
Code:
if (var == true)


Also, structuring functinos so that you perform a single staement and then call another function to do the rest of the work. And that function performs one statement and then calls another function to do the rest of the work. And that function performs one statement and then calls another function to do the rest of the work...
Seriously, one of the guys I work with does that. Code review of his code is the worst job in the department. Fortunately, he takes so long to deliver the code that it's a rare occurence that it's necessary. And generally it's so bug-ridden that it's easier to just rewrite the damn thing.
2005-04-29, 1:47 AM #5
Quote:
Originally posted by Freelancer
Since Massassi is freaking chock full of coders, I figured it might be fun to post a little poll. Which styles do you prefer with your brackets/code blocks?

1. How do you prefer your code blocks?

K&R all the way:
Code:
while (i < 100) {
    doThings(i);
    i++;
}


Quote:
2. How do you prefer your if - else if - else blocks?


I agree:
Code:
if(something) {
    doStuff();
    doMoreStuff();
}
else {
    doOtherStuff();
    break;
}


Quote:
3. Do you use curly braces for clarity even if you don't need them?


Nope.

Quote:
4. What is your capitalization style for identifiers?


Same way as Freelancer. Much more efficient than using underscores.

Quote:
5. Do you use any more in-depth naming conventions, such as Hungarian notation, denoting type in the identifier itself, etc.?


Not usually, but I tend to put underscores in front of private variables in a class. However, I am a C coder at heart.

Quote:
6. What is your preference with whitespace in general?


I space the same way as Freelancer.

Quote:
7. What kind of comments do you use and how? If you have a complex/well-defined commenting style, describe it.


I always use C++ style comments out of habit. C99 allows for them too, allowing me to continue the trend with my C code as well. In PHP, I tend to use an octothorpe for no particular reason.

Quote:
8. Continuing with the idea of whitespace, what does the layout of your code usually look like? Is it all clumped together, do you try to have some blank lines here and there?


I seperate functions with only one blank line. Any more seems like a waste. I tend to space out blocks of code in order to logically seperate multiple lines of code used to do one action.

Quote:
9. Post anything else you can think of that further defines your style, or your annoyances with other peoples' code.


I hate people that use spaces instead of tabs. Use tabs with a tabstop setting to keep it from side scrolling, not spaces which make writing code a tad more painful.

I hate uncommented code. I used to write code first and comment later, but I've since given up the habit. I am sick and tired of reading ****ty, uncommented code.

I hate people who won't agree with me on some sort of coding style for a project and make code which looks completely wacky when examined with the rest of the code.

I hate people who squish a lot of stuff onto one line and refuse to use whitespace. Whitespace is for our benefit, use it.

When I declare multiple variables, I tend to space them out so they are like so:
Code:
char
  name[40],
  type[11],
  *banana;

I find it is easier to read and insert comments about variables this way.

My tabstop is always 2. Makes it easier to read deeply nested code, but is still big enough to show proper indentation with my code blocks.

I hate people who write code more that 80-88 characters wide. I don't want lines to wrap in vi, so stop that. I tend to break lines just to prevent a line wrap.

I hate useless comments. Yeah, we all have our fair share of crappy commenting, but if i see another person comment main with "// Main function" I'm going to stab their eyes out.

I don't like Java too much. I can code it, but I prefer not to. Way too much class bloat.

I hate people who hate C because there aren't any booleans. For some reason, using ints for this purpose is too hard for them to grasp.

I hate "if (something == true)". Its just not necessary.

For the most part, my style is very similar to Freelancer's. I need people like him to work on group projects with me. :)
[This message has been edited. Deal with it.]
2005-04-29, 1:57 AM #6
Actually, i pretty much do everything the way you described as being Good, Freelancer.

Back in my days as an obsessive cogger, i went absolutely batty reading most people's code, as it was so massively contrary generally to how i organized and structure mine. I went for a very readable very clean and somewhat neurotically delimited format usually.

I do quite approve of and use the If(bool_foo == true) style, myself as well.

Though, the only place i do vary is that i do very strongly tend towards the, what was it, Hungarian? No idea why it is called that.
That is, i consistantly labbelled variables and such as int_eggsinbasket or str_nameofeasterbunny or suchlike, so i could tell at a glance without having to read the whole name what it was. Sort of like the determinants used in hieroglyphic which allows rapid categorization of meaning.

Also, i tend to avoid mixed-case names as much as possible, particularly once i started using linux where case is highly sensitive.

Maybe i have one or two cogs lying around somewhere that i can show off. Though i suspect theyve all long since decayed.
Also, I can kill you with my brain.
2005-04-29, 4:54 AM #7
Quote:
Originally posted by Freelancer
Since Massassi is freaking chock full of coders, I figured it might be fun to post a little poll. Which styles do you prefer with your brackets/code blocks?

1. How do you prefer your code blocks?

I don't like the begin and end way. I do like it like this:
Code:
while (i < 100) {
    doThings(i);
    i++;
}

// I think this is ugly
while(i < 100)
{
    doThings(i);
    i++;
}


When you have a known number of loops you should use for. Other than that, i do it the first way. Puttin the begin after the statement just makes your code unneccesary long.

Quote:
2. How do you prefer your if - else if - else blocks?

Personally, I like them like this:
Code:
if(something) {
    doStuff();
    doMoreStuff();
}
else {
    doOtherStuff();
    break;
}

// I can't stand this trash:
if(something) {
    doStuff();
    doMoreStuff();
} else {
    doOtherStuff();
    break;
}

// this is okay, I guess
if(something)
{
    doStuff();
    doMoreStuff();
}
else
{
    doOtherStuff();
    break;
}


Same as you.

Quote:
3. Do you use curly braces for clarity even if you don't need them?

I don't. For example, do you go like this:
Code:
if(something)
    index++;

// or like this:

if(something) {
    index++;
}


No, and if i've got something with just one statement, I put it all one one line.

if (condition) index++;

Quote:
4. What is your capitalization style for identifiers?

I learned Java first, and it corrupted me, so I tend to start everything lowercase and capitalize trailing words, for both function names and variables. Sample identifiers:
Code:
int size;
int numberOfPenguins;
doSomethingReallyNeat();
// etc.


Strangely, I actually do it differently in different languages. In java i follow the convention of capitalising trailing words, putting constants in capitals because that's now the in build function names are. Integer.toString()

In Delphi I give every word a capital letter. MyIntegerVariable.

I do it to make the program have some sort of consistency with the language. It just makes it easier to read in general.

Quote:
5. Do you use any more in-depth naming conventions, such as Hungarian notation, denoting type in the identifier itself, etc.?


Unless i'm having the same thing as two types, e.g. having a function return a string, then show that string to the user but it may also be needed as an integer, i dont. If i need the same thing as two types I generally do this:

int myVarInt;
String myVarStr;

Quote:
6. What is your preference with whitespace in general?

I like spaces. I use them everywhere. For example:
Code:
for(int i = 0; i < 100; i++)

// instead of
for(int i=0;i<100;i++)



All of my operators are usually surrounded by spaces. It's 1 + i, not 1+i. I also like to put spaces around paranthesis, for clarity. while( (line = br.readLine() ) != null), for example. I generally don't put a space between keywords and parenthesis, though, so it's if(something) instead of if (something), etc. Finally, I also put spaces between arguments, so it's new Color(255, 255, 255) instead of new Color(255,255,255).



For readability, i do as you do. It makes it much easier to read, so quicker to debug generally.

I dont however, put them between the brackets

if (myVar == true);
instead of
if ( myVar == true );

Quote:
7. What kind of comments do you use and how? If you have a complex/well-defined commenting style, describe it.

I use C-style comments with unnecessary but nice-looking asterisks at the start of every line to describe functions and classes. I use C++ style comments for comments within functions and very short comments after a line of code. For example, I tend to write comments like this:
Code:
/*
 * This class does a bunch of stuff. Blah blah blah
 * blah blah blah blah blah.
 */
public class Foo {

    int numberOfMonkeys; // monkeylicious!

    /*
     * This function kills the specified monkey!
     */
    public void killMonkey(int monkey) {
    ...
    }
}


unless i have more than two or 3 lines of comments i just use a single line comment. For the same reason you put a * there. So when scanning over the lines you can see it's a comment. Although this isnt as important when you have syntax hilighting :p

Quote:
8. Continuing with the idea of whitespace, what does the layout of your code usually look like? Is it all clumped together, do you try to have some blank lines here and there?

Sometimes, if I find there is a lot of code without any blank lines, I'll try to categorize 'like' code, that kind of fits together, and I'll stick an arbitrary blank line, just to break things up. I generally like to stick 3 or 4 lines between functions and stuff, too.


I usually use correct indentation. One tab when something is in a block.

e.g.
Code:
while (myCondition) {
    if (anotherConidition == 5) {
        doThis();
        andThis();
    }
    else {
        doSomethingElse();
        if (yetAnotherCondition == "correct") {
            doAnotherThing();
        }
    }
}


if i have two functions, i'll seperate them with one line of whitespace. e.g. in Java (since that's what you've been using)

Code:
public void firstFunction() {
//...
}

public void secondFunction() {
//...
}


Quote:
9. Post anything else you can think of that further defines your style, or your annoyances with other peoples' code.

One of my pet peeves is people who see two perfectly good lines of clear code and merge it into one line, making one, long, esoteric line of code. I try to have one line of code do one distinct thing, even though of course that's difficult to do at times. I'm just saying something like this gets old after a while:
Code:
String thing = (String) ( (int) (Character) list.get( getIndex(i % offset) ) >> 3 );


Funnily enough, I prefer it when people do that. It saves decalaring and using extra variables. You should only need to create a variable when you need to access the data again later when you're doing something like this, you dont need 2 varaibles:

Code:
double myVarInPercent = marks/totalmarks;
int finalPercent = (int) myVarInPercent*100;

I'd much rather see that done like this:

Code:
int finalPercent = (int) ((double) (marks/totalmarks)*100);



Quote:
I don't like people who abuse line delimeters and stick 4 lines of code on a single line. Stuff like int i = 0; doStuff(); int index = word.lastIndex(ID); doMoreStuff(); all on one line makes me want to kill. People who do this in switch statements really piss me off.

Heh, switch statements are the only time i'd ever do that.
But not if theres more than one line + the break

e.g.

Code:
switch (i) {
case 1: doThis(); break;
//if it has more than one thing to do i'd put it on multiple 
case 2: 
doThis();
thenThis();
break;
}


I also try to avoid repeated code and tend to use lots of small procedures/functions than a few large ones. For most projects I try to keep object oriented, and use the "programming by difference" idea to minimize the code.
TheJkWhoSaysNiTheJkWhoSaysNiTheJkWhoSaysNiTheJkWho
SaysNiTheJkWhoSaysNiTheJkWhoSaysNiTheJkWhoSaysNiTh
eJkWhoSaysNiTheJkWhoSaysNiTheJkWhoSaysNiTheJkWhoSa
ysNiTheJkWhoSaysNiTheJkWhoSaysNiTheJkWhoSaysNiTheJ
k
WhoSaysNiTheJkWhoSaysNiTheJkWhoSaysNiTheJkWhoSays
N
iTheJkWhoSaysNiTheJkWhoSaysNiTheJkWhoSaysNiTheJkW
2005-04-29, 5:56 AM #8
I was going to answer this, but one thing caught my attention.

Brace? wtf.

The word is bracket.

( and ) are brackets.
[ and ] are square brackets.
{ and } are curly brackets.

Now what the hell is a brace?
"The trouble with the world is that the stupid are cocksure and the intelligent are full of doubt. " - Bertrand Russell
The Triumph of Stupidity in Mortals and Others 1931-1935
2005-04-29, 5:58 AM #9
1. How do you prefer your code blocks?

Code:
while(i < 100)
{
    doThings(i);
    i++;
}


2. How do you prefer your if - else if - else blocks?

Code:
if(something)
{
    doStuff();
    doMoreStuff();
}
else
{
    doOtherStuff();
    break;
}


3. Do you use curly braces for clarity even if you don't need them?

Nope.

4. What is your capitalization style for identifiers?

Capitalized, with Hungarian notation:

Code:
int nSomeValue;
int* pSomeValue;


5. Do you use any more in-depth naming conventions, such as Hungarian notation, denoting type in the identifier itself, etc.?

I use Hungarian notation.

6. What is your preference with whitespace in general?

I use whitespace all the time, especially in mathematical expressions:

Code:
i = ( 12 / x ) + y;



7. What kind of comments do you use and how? If you have a complex/well-defined commenting style, describe it.

I almost always use the // style comments. I never really use the other kind. If theres a lot to be described, i usually do it like this:

Code:
//-----------------------
//Lots of stuff here
//More stuff here
//-----------------------


8. Continuing with the idea of whitespace, what does the layout of your code usually look like? Is it all clumped together, do you try to have some blank lines here and there?

I usually group relevant things together, like variable declarations and function declarations. But generally, i have an empty line after things.

9. Post anything else you can think of that further defines your style, or your annoyances with other peoples' code.

Unnecessary things, like:
Code:
if (bool == true) // == true is not needed
   {
   DoOnlyOneThingButStillUseBrackets();
   }
2005-04-29, 6:01 AM #10
My responses to said questions:

1. How do you prefer your code blocks?

I agree with you on this one:
Code:
while (i < 100) {
    doThings(i);
    i++;
}


2. How do you prefer your if - else if - else blocks?

I like what you call "trash":
Code:
if(something) {
    doStuff();
    doMoreStuff();
}else{
    doOtherStuff();
    break;
}


3. Do you use curly braces for clarity even if you don't need them?

I don't use them superfluously either. Preferred way:
Code:
if(something) index++;


4. What is your capitalization style for identifiers?

Well, my first language was Visual Basic (which sadly seems to have so many flaws now that I have worked w/ Java and C++).
Every variable name had a 3 letter prefix to denote its type--ex. str for Strings--, but I don't do this anymore. It's pointless. Back to identifiers, I don't like capitalizing at all. Also, I prefer short names. My methods are always single word verbs. If I have to use multiple words, I use underscores.
Code:
int size;
int quantity_penguins;
perform();
// etc.


5. Do you use any more in-depth naming conventions, such as Hungarian notation, denoting type in the identifier itself, etc.?

I don't know any specific naming conventions . . .

6. What is your preference with whitespace in general?

Similarly, I like spaces. I use them a lot. For example:
Code:
for(int i = 0; i < 100; i++)


I agree on all your spacing except that of parentheses. For example:
Code:
P.setLayout(new FlowLayout(FlowLayout.CENTER, 0, 40));\

//Instead of . . . 
P.setLayout( new FlowLayout(FlowLayout.CENTER, 0, 40) );


7. What kind of comments do you use and how? If you have a complex/well-defined commenting style, describe it.

I prefer the one liner markup (//). If there are two lines of comments, I will use the one liner on both lines. If there are three or more, I use the /* */, usually along with an * on each line.

8. Continuing with the idea of whitespace, what does the layout of your code usually look like? Is it all clumped together, do you try to have some blank lines here and there?

I will usually use a single blank line to separate different groups of related instructions. I don't like clutter though. I will just add blank lines to improve the appearance. :p I also like to tab in lines one tab to the right of the above method signature or loop header.

9. Post anything else you can think of that further defines your style, or your annoyances with other peoples' code.

Yeah, I am not a fan of merging lines of code. If there is more than one ; on the line, drop the statement to the next line.

I also don't like how some people use one line for a brace when the don't have too. Then again, it depends on what the above line contains.

I was glad to participate in this interesting poll!
2005-04-29, 6:02 AM #11
Quote:
Originally posted by Mort-Hog
I was going to answer this, but one thing caught my attention.

Brace? wtf.

The word is bracket.

( and ) are brackets.
[ and ] are square brackets.
{ and } are curly brackets.

Now what the hell is a brace?

( and ) are parentheses.
[ and ] are brackets.
{ and } are braces.
2005-04-29, 6:06 AM #12
Quote:
Originally posted by Evil_Giraffe
( and ) are parentheses.
[ and ] are brackets.
{ and } are braces.


Right on!
2005-04-29, 9:52 AM #13
OP: how come you have a space after your while () but not after your if() ?

I'm not going to answer the questions one by one but I will give you an example (and I always indent with tabs not spaces):

Code:
while($something) {
    do_something();
}

if($something == $something_else) {
    do_something_else();
}

$my_variable = 'some value';
$my_other_variable = "$my_variable again"; // only double quotes when needed

if($something) do_something(); // is fine on one line, but in perl it looks like this:

do_something() if $something;

class MyClass extends MyOtherClass {
    function MyClass() {
        // constructor
    }

    function my_member_function($arg1, $arg2) {
        // notice I don't use stupidCase except in class names
    }
}
2005-04-29, 9:54 AM #14
Oh in regards to comments, in perl which I code most there is only one, # some comment.

In PHP I use // for one line comments, and I use /* */ for multi-line comments, but I make them look like this:

[php]
/**
* This is a multi-line comment
* and it rocks your box
*/
function whatever($arg1, $arg2) {
// do something
}
[/php]

If I'm commenting something out temporarily in PHP, I always use a # to indicate to myself that it's not a permanent state.
2005-04-29, 10:37 AM #15
I better not see Yoshi post here. His code is the hardest to read, ever!

My habits are pretty much the same as Evil_Giraffe. Everything (or almost) on its own line. I don't see the point in ultra-condensing everything, the compiler is going to spit out the same thing anyways, so I might as well take the space I need to make my stuff readable.
2005-04-29, 10:58 AM #16
1. How do you prefer your code blocks?

Code:
while (x < 6) {

     x++;
     x--;

}

if (x > 7) {

     x++;
     return;

}


2. How do you prefer your if - else if - else blocks?

Code:
if (x != 3) {\

    return false;

}

else if (x > 3) {

    return true;

}

else {

     return null;

}


3. Do you use curly braces for clarity even if you don't need them?

Yes. It makes it SO much easier to read!

4. What is your capitalization style for identifiers?

Code:
Comparable compObj = new String();
int numberOfBlocks = 0;


5. Do you use any more in-depth naming conventions, such as Hungarian notation, denoting type in the identifier itself, etc.?

Not familiar with the material discussed in this question.

6. What is your preference with whitespace in general?

Code:
for (int i = 0; i < array.length; i++) {}
if (x = 7) {}


7. What kind of comments do you use and how? If you have a complex/well-defined commenting style, describe it.

Code:
/**
*   This is JavaDoc.  I use it for any methods or classes.
*   @param parameter
*   @return return value
*/

// This is in-method commenting.


8. Continuing with the idea of whitespace, what does the layout of your code usually look like? Is it all clumped together, do you try to have some blank lines here and there?

An example of my VBasic code (this is how I code everything):

Code:
Private Sub cmdDetail_MouseDown(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)

    If Button = vbRightButton Then
        If currentDetailIndex(Index) < detailMax(Index) Then
            currentDetailIndex(Index) = currentDetailIndex(Index) + 1
            cmdDetail(Index).Picture = Graphics.DetailImg(currentDetailIndex(Index)).Picture
        Else
            currentDetailIndex(Index) = originalDetailIndex(Index)
            cmdDetail(Index).Picture = Graphics.DetailImg(currentDetailIndex(Index)).Picture
        End If
    End If
    
    Call cmdDetail_Click(Index)

End Sub


9. Post anything else you can think of that further defines your style, or your annoyances with other peoples' code.

When people don't friggin' comment. And when they have everything lined up against the left side of the window. It's damn near impossible to read and understand.
the idiot is the person who follows the idiot and your not following me your insulting me your following the path of a idiot so that makes you the idiot - LC Tusken
2005-04-29, 11:21 AM #17
Wow, this has been very interesting. And Wolfy, I think you get the prize for having the most different style so far. :p Keep 'em coming!
"it is time to get a credit card to complete my financial independance" — Tibby, Aug. 2009
2005-04-29, 11:25 AM #18
Seeing as I just finished up an AVL tree for one of my CS classes, ill just post one of the methods from that and let you see for yourselves.

Code:
    private AVLNode rotateLeft(AVLNode node){
        AVLNode newBranch = node.right;
        node.right = null;
        if(node == root){
            root = newBranch;
            newBranch.parent = null;
        }else{
            if(!node.IsRight){
                node.parent.left = newBranch;
                newBranch.IsRight = false;
            }else{
                node.parent.right = newBranch;
                newBranch.IsRight = true; 
            }
        }
        if(newBranch.left != null){
           node.right = newBranch.left;
           node.right.IsRight = true;
           node.right.parent = node;
           newBranch.left = null;
        }
        newBranch.left = node;
        node.IsRight = false;
        newBranch.parent = node.parent;
        node.parent=newBranch;
        if(newBranch.balance >= 0 ) node.balance = node.balance -1 - newBranch.balance;
        else node.balance = node.balance - 1;
        if(node.balance <= 0) newBranch.balance = newBranch.balance - 1 + node.balance;
        else newBranch.balance = newBranch.balance - 1;
        return newBranch;
    }


WHEN I comment (which is not nearly as often as i should), I usually fall back on:

Code:
// TITLE FOR COMMENT
//
// comment stuff
// more comment stuff


I’m actually a CPE (hardware) major, and I probably have some pretty bad coding habits.
"Well, if I am not drunk, I am mad, but I trust I can behave like a gentleman in either
condition."... G. K. Chesterton

“questions are a burden to others; answers a prison for oneself”
2005-04-29, 11:45 AM #19
Quote:
Originally posted by West Wind
Seeing as I just finished up an AVL tree for one of my CS classes, ill just post one of the methods from that and let you see for yourselves.

Code:
    private AVLNode rotateLeft(AVLNode node){
        AVLNode newBranch = node.right;
        node.right = null;
        if(node == root){
            root = newBranch;
            newBranch.parent = null;
        }else{
            if(!node.IsRight){
                node.parent.left = newBranch;
                newBranch.IsRight = false;
            }else{
                node.parent.right = newBranch;
                newBranch.IsRight = true; 
            }
        }
        if(newBranch.left != null){
           node.right = newBranch.left;
           node.right.IsRight = true;
           node.right.parent = node;
           newBranch.left = null;
        }
        newBranch.left = node;
        node.IsRight = false;
        newBranch.parent = node.parent;
        node.parent=newBranch;
        if(newBranch.balance >= 0 ) node.balance = node.balance -1 - newBranch.balance;
        else node.balance = node.balance - 1;
        if(node.balance <= 0) newBranch.balance = newBranch.balance - 1 + node.balance;
        else newBranch.balance = newBranch.balance - 1;
        return newBranch;
    }


WHEN I comment (which is not nearly as often as i should), I usually fall back on:

Code:
// TITLE FOR COMMENT
//
// comment stuff
// more comment stuff


I’m actually a CPE (hardware) major, and I probably have some pretty bad coding habits. [/B]


It could use some line breaks, but not bad at all.

Another pet peeve is colored syntax. You don't need colored syntax if you write clean code, so stop shoving vim, kate, or anything else of the sort in my face.
[This message has been edited. Deal with it.]
2005-04-29, 11:51 AM #20
1. How do you prefer your code blocks?

Code:
if(GetCurMeal(person) == "beans")
{
   print("Mmmm... beans!");
   gas++;
}


2. How do you prefer your if - else if - else blocks?

Code:
if(GetCurMeal(person) == "beans")
{
   print("Mmmm... beans!");
   gas++;
}
else if(GetCurMeal(person) == "chineseFood")
{
   print("Mmmm... Chinese Food!");
   indigestion++;
}


3. Do you use curly braces for clarity even if you don't need them?

I only use them if there are more than one algorithem. So, the result would be...

Code:
if(GetCurMeal(person) != "beans") Print("Phew... don't have to worry about gas!");


4. What is your capitalization style for identifiers?

I use the usual method that most people use. Example: var nameOfSomeVariable = "dude?";

5. Do you use any more in-depth naming conventions, such as Hungarian notation, denoting type in the identifier itself, etc.?

It depends on what I'm coding. Variables that share something in common usually are named similar to another. Example:

Code:
var playerHealth = 100;
var playerMaxHealth = 200;

var monsterHealth = 25;
var monsterMaxHealth = 50;


6. What is your preference with whitespace in general?

I use white space when I think its necessary. For example, when I create or modify variables, I make sure I put in spaces around the equals so it doesn't looked all smashed up. However, when it comes to for loops, I usually do it like this:

Code:
if(i=0; i<5; i++)
{
  print("Arf!!!")
}


7. What kind of comments do you use and how? If you have a complex/well-defined commenting style, describe it.

I have a tendency to get lazy and not use comments when writing a script but when I do, I usually do it like this:

Code:
//Player's health
var playerHealth = 100;
var playerMaxHealth = 200;

//monster's health
var monsterHealth = 25;
var monsterMaxHealth = 50;


8. Continuing with the idea of whitespace, what does the layout of your code usually look like? Is it all clumped together, do you try to have some blank lines here and there?

I use blank lines to help seperate lines of code to help organize it a bit. Example:

Code:
var playerHealth = 100;
var playerMaxHealth = 200;

var monsterHealth = 25;
var monsterMaxHealth = 50;


As you can see, I put a blank line to help seperate the player's stuff from the monter's stuff. I also do that same thing with functions and selection (if/else) code blocks.

9. Post anything else you can think of that further defines your style, or your annoyances with other peoples' code.

I can't really think of anything at the moment that I do differently than others that I haven't already explained.
The cake is a lie... THE CAKE IS A LIE!!!!!
2005-04-29, 1:11 PM #21
I'll just post some of me code to give an indication of my style.
Code:
void CSim3DWindow::ResizeGL()
{
	if (height==0)									// Prevent A Divide By Zero By
		height=1;									// Making Height Equal One

	glViewport(0,0,width,height);						// Reset The Current Viewport

	glMatrixMode(GL_PROJECTION);						// Select The Projection Matrix
	glLoadIdentity();									// Reset The Projection Matrix

	// Calculate The Aspect Ratio Of The Window
	gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,1000.0f);

	glMatrixMode(GL_MODELVIEW);							// Select The Modelview Matrix
	glLoadIdentity();
}


There are more switch statements on this one but I did only one case to give an idea...and not make this 24,315 lines long :P
Code:
void CSim3DWindow::OnKeyUp(int nVirtKey)
{
	switch (nVirtKey)
	{
	case VK_F1: //Set lighting mode or CG mode.
		if (m_bIsLit)
		{
			glDisable(GL_LIGHTING);
			m_pCG->ToggleCG(true);
			m_bIsLit=false;
		}
		else
		{
			glEnable(GL_LIGHTING);
			m_pCG->ToggleCG(false);
			m_bIsLit=true;
		}
		break;
	}
}
Code to the left of him, code to the right of him, code in front of him compil'd and thundered. Programm'd at with shot and $SHELL. Boldly he typed and well. Into the jaws of C. Into the mouth of PERL. Debug'd the 0x258.
2005-04-29, 4:34 PM #22
1:
I prefer my code blocks like this...
Code:
while(i < 100)
{
    doThings(i);
    i++;
}


2:
I like my if else blocks like so...
Code:
if(something)
{
    doStuff();
    doMoreStuff();
}
else
{
    doOtherStuff();
    break;
}


3:
I do use braces even when i dont need them.. like this.. its kinda weird...
Code:
if(something)
{ index++; }


4:
I do mine about the same.. but i capitolize every word in my functions...
Code:
int size;
int numberOfPenguins;
DoSomethingReallyNeat();


5:
The only thing I do different for naming conventions is like i might relate it to the data type like different handles in Win32...
Code:
HWND hMain;
HBITMAP hPicture;
// and so on..


6:
I with you as far as whitespace goes.. im with you.. i like things spaced apart.. easier to read...

7:
I dont comment to much.. although is should.. but anyways i just do it however i feel.. i do it different sometimes than others.. and sometimes it just depends how bored i am..

8:
My code structure looks like this....
[http://www.makstudios3d.com/code.jpg]

9:
I agree with you fully on this.. you shouldnt jam too much on one line.. like you should never have to scroll over in you IDE to see the rest of one line of code..

so yeah.. thats about it...
2005-04-29, 4:36 PM #23
I like your programs Freelancer. :o
Skateboarding is not a crime.
2005-04-29, 4:45 PM #24
I always thought this was cool:
Code:
int sweetass;

int main()
  {
     somethingCool(sweetass)
       {
          Hell yeah!! I rock;
       }
     return 0;
  }
NOTE: I can't actually program. :(
"When it's time for this planet to die, you'll understand that you know absolutely nothing." — Bugenhagen

↑ Up to the top!