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:
2. How do you prefer your if - else if - else blocks?
Personally, I like them like this:
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:
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:
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:
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:
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:
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.
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