Hey facepunch.
When I first started programming I would put my brackets on the same line as my symbols and loops and shit.
[code]if (foo) {
[indent]foo->bar();[/indent]
}[/code]
Now I do it like:
[code]if (foo)
{
[indent]foo->bar();[/indent]
}[/code]
This dude told me you should never have anything on the same line as a bracket...what do you do facepunch?
I throw a dice. A two sided one.
[cpp]if(foo)
{
foo->bar();
}
[/cpp]
It doesn't matter but I have it on a new line.
I put it on a new line, I like a ton of white space in my code. And I keep similar stuff blocked together seperated by a blank line. Like if I declare a class and then have to set properties and stuff with it, I have that all together and then for the next class or whatever I put a blank line then start the next stuff.
[cpp]if (foo)
{
foo->bar();
}[/cpp]
Am I the only one who does it K&R style (same line)?
My coding style is a mutated one.
I use tabs as whitespace and use one line if statements.
[cpp]bool COSLayerWin32::init(void)
{
// Create the window with the properties for the OS layer.
if(createWindow(properties->windowTitle, properties->width, properties->height, properties->bits, properties->fullscreen,
properties->cursorVisibleWindowed, properties->cursorVisibleFullscreen) == true) // If creating the window had an error.
return true;
return false;
}[/cpp]
What is this foo bar stuff?
[QUOTE=Pj The Dj;16720708]What is this foo bar stuff?[/QUOTE]
Just well used programming words. It's like "hello world".
It's just a thing people do.
I do it brackets-on-their-own-line.
[QUOTE=godihatefacepun;16719759]
This dude told me you should never have anything on the same line as a bracket...what do you do facepunch?[/QUOTE]
That's retarded
[code]
if (foo==bar) $fb='bar';
[/code]
[code]
foo() {
bar = 1;
}
[/code]
looks retarded
I use a newline in functions, but for everything else, on the same line.
[QUOTE=NovembrDobby;16721129][code]
foo() {
bar = 1;
}
[/code]
looks retarded[/QUOTE]
Thats pretty much the standard for Java. I do Java at work, so that's what I do.
For C and C++ I do
[code]
foo()
{
bar = 1;
}
[/code]
I like to do all my coding on one line.
[cpp]
for(int i = 0; i < foo.size(); i++){ if(foo[i]){foo[i].bar(i);};};return 0;
[/cpp]
hardcore
For functions and class definitions, I always do a new line. For loops and conditionals and stuff (brackets nested beyond the first level) I do same line. It just helps me associate the code with the conditional better.
[code]
foo()
{
for(bar = 0; bar < 8; bar++) {
baz += bar;
}
}
[/code]
It doesn't matter at all where the bracket is but I prefere coding stuff like this
[code]int main(){
//do some stuff
for(int i=1;i <= 2;i++){
call_this_function("hi","no space between arguments","which is good");
}
return 0;
}[/code]
Instead of
[code]int main()
{
//So much freaking wasted space everywhere
for(int i = 1 ; i <= 2; i++ )
}
call_this_function("hi" , "so much inconsistent spaces between function arguments", "which sucks" );
}
return 0;
}[/code]
How you see I prefere the first method for the following reasons
[list]
[*]It saves space
[*]Starting new lines for every shit you add (e.g. opening brackets) blows up the code and makes it harder to read
[*]Adding spaces between functionarguments sucks because you may sometimes forget to add them so the code looks not everywhere the same
[/list]
This is why I code like in my first example. Anyway, it doesn't matter how you code. It's just a personal thing.
Anyway, what I hate more are people using spaces instead of tabs or adding spaces/tabs at the end of a line (because of stupid copy & paste or similar).
[code]
int foo(int a) {
int temp = 5;
mutate(a);
callShit(a,temp)
return doShit(temp);
}
[/code]
I still can't find what to do with the end brace. I hate it on it's own line, yet it gives whitespace, yet there's nowhere else to really put it..
I do the same line thing. The way I conceptualize it, it makes more sense. I see it as the function starts right there, so the bracket comes right after I start the function. putting it on a new line makes it's seem like they are separate to me.
Also, does anyone else put spaces between parenthesis? I can't stand having "))", so I will always breaks them up into ") )".
[QUOTE=jivemasta;16719995]I put it on a new line, I like a ton of white space in my code. And I keep similar stuff blocked together seperated by a blank line. Like if I declare a class and then have to set properties and stuff with it, I have that all together and then for the next class or whatever I put a blank line then start the next stuff.[/QUOTE]
I am the same way. :)
It really doesn't matter, but I do the same thing aVoN does. When I first viewed tutorials on the internet the author wrote the brackets on the same line, so I did the same thing and got into a habit of doing it.
I do:
[cpp]
void myFunction()
{
int aNumber = 0;
MyClass instance;
if( instance.getIndex() == aNumber )
{
aNumber += 1
}
else
{
aNumber -= 1
}
}
[/cpp]
I used to do the style that most people are using in this thread
[cpp]
void func()
{
}
[/cpp]
But Code Complete convinced me to change to my current style, I prefer it.
I change my coding style every 4-5 lines because I'm an arsehole :P
Usually
[cpp]
void MyFunc()
{
// code stuff here
}
[/cpp]
brackets on another line
its cleaner
[lua]void foo( int bar )
{
if ( foo == bar ) {
foobar( );
}
}[/lua]
[cpp]
void foo(int b, int a, int r)
{
if(foo == b + a + r && b + a + r == fight)
{
doshit();
doshit2();
}
else if(ReallyLongAndAnnoyingConditionalStatementIsTrue)
OneFunctionForConditional();
else if(PrettyShortConditional) IntVar = 0;
}
[/cpp]
That's how I do it.
Sorry, you need to Log In to post a reply to this thread.