The 1 true style

Please compose all posts in Emacs.

Moderators: phlip, Prelates, Moderators General

The 1 true style

Postby OfficiallyHaphazard » Fri Nov 16, 2007 5:35 pm UTC

I was debating whether I should eve post this topic, because clearly there is no battle to fight.

Everyone know k&r is the way to go. Who needs a new line for a brace? Not us.

Allman is annoying and Whitesmith is just strange.

Having said this, I bet this topic will be deleted, due to the fact that nobody could ever argue with my aforementioned convictions
Code: Select all
private void determineBestStyle(int styleChoice)
{
    if(styleChoice == K_R){
          println("Obviously!");
    } else {
          throw new ErrorException("This could never be the case");
    }
}





edit: fixed some things..
Last edited by OfficiallyHaphazard on Fri Nov 16, 2007 5:55 pm UTC, edited 1 time in total.
"Who are you, how did you get in my house?" - Donald Knuth
User avatar
OfficiallyHaphazard
Age=postcount/60
 
Posts: 209
Joined: Tue Aug 28, 2007 2:56 pm UTC

Re: The 1 true style

Postby Robin S » Fri Nov 16, 2007 5:37 pm UTC

I don't do that, because when I first started programming the sources I taught myself from all used the "open and close your braces vertically above each other" paradigm (for want of a better word). I guess I just got used to it.
This is a placeholder until I think of something more creative to put here.
Robin S
 
Posts: 3579
Joined: Wed Jun 27, 2007 7:02 pm UTC
Location: London, UK

Re: The 1 true style

Postby pieaholicx » Fri Nov 16, 2007 5:39 pm UTC

I mostly use K&R, but I've had to use Allman style for a lot of projects. I don't have a problem with either of them, however I will say that Allman style defines blocks of code better than K&R does.
It's okay, I'm Chaotic Neutral. I can kill him over the loot.
Overexposure to pieaholicx may, in semi-rare cases, emancipate dental fillings, crowns, tooth enamel, and teeth.
User avatar
pieaholicx
The cake is a lie!
 
Posts: 531
Joined: Mon Oct 22, 2007 12:51 pm UTC

Re: The 1 true style

Postby joeframbach » Fri Nov 16, 2007 5:43 pm UTC

I read the thread title and I was really hoping this would be a discussion about #define TRUE 1
I was disappointed.

I like to use 0 for FALSE and >0 for true. If I want to see if an int is not 0, I use
if (!!myint) {
...
}
xxv/♂/♫
User avatar
joeframbach
 
Posts: 1478
Joined: Sun Nov 05, 2006 12:49 am UTC
Location: The City of Steel

Re: The 1 true style

Postby Hammer » Fri Nov 16, 2007 5:49 pm UTC

For myself, I like Allman. However, my main requirement for style is that, whatever you decide to do, do it consistently! I regularly get handed code from beginners whose reaction to suggestions to maintain a consistent style is "Do I haaaaave to?" Then, after listening to them whine, I get to plow through code that uses three different indenting styles selected at random when they bother to indent at all. Grrrrrrrrr...
"What's wrong with you mathematicians? Cake is never a problem."
User avatar
Hammer
Because all of you look like nails.
 
Posts: 5489
Joined: Thu May 03, 2007 7:32 pm UTC

Re: The 1 true style

Postby OfficiallyHaphazard » Fri Nov 16, 2007 5:51 pm UTC

Hammer wrote:For myself, i like Allman. However, my main requirement for style is that, whatever you decide to do, do it consistently! I regularly get handed code from beginners whose reaction to suggestions to maintain a consistent style is "Do I haaaaave to?" Then, after listening to them whine, I get to plow through code that uses three different indenting styles selected at random when they bother to indent at all. Grrrrrrrrr...



I hate when people hand me inconsistent code....Grr as well :P
"Who are you, how did you get in my house?" - Donald Knuth
User avatar
OfficiallyHaphazard
Age=postcount/60
 
Posts: 209
Joined: Tue Aug 28, 2007 2:56 pm UTC

Re: The 1 true style

Postby Rysto » Fri Nov 16, 2007 5:52 pm UTC

OfficiallyHaphazard wrote:
Code: Select all
private void determineBestStyle(int styleChoice){
    if(style choice == K_R){
          println("Obviously!");
    } else {
          throw new ErrorException("This could never be the case");
    }
}

This is not K&R style. This is Java style. K&R style is this:

Code: Select all
private void determineBestStyle(int styleChoice)
{
    if(style choice == K_R){
          println("Obviously!");
    } else {
          throw new ErrorException("This could never be the case");
    }
}


I used to use Allman style but several jobs programming Java converted me to Java style. The ease I had switching has convinced me that it mostly doesn't matter, although Whitesmiths style is weird. Can we all agree that GNU style sucks, though?
Rysto
 
Posts: 1442
Joined: Wed Mar 21, 2007 4:07 am UTC

Re: The 1 true style

Postby davean » Fri Nov 16, 2007 5:55 pm UTC

Style is a meaningless convention. No one who can actually code cares.
User avatar
davean
Site Ninja
 
Posts: 2436
Joined: Sat Apr 08, 2006 7:50 am UTC

Re: The 1 true style

Postby OfficiallyHaphazard » Fri Nov 16, 2007 5:58 pm UTC

>.>
Whoops... well then, I like java style. But I fixed the OP

http://en.wikipedia.org/wiki/Indent_style


Hmmm, if these are religious wars, then davean is an atheist. I never knew how to argue with atheists :P
"Who are you, how did you get in my house?" - Donald Knuth
User avatar
OfficiallyHaphazard
Age=postcount/60
 
Posts: 209
Joined: Tue Aug 28, 2007 2:56 pm UTC

Re: The 1 true style

Postby pieaholicx » Fri Nov 16, 2007 6:00 pm UTC

OfficiallyHaphazard wrote:Hmmm, if these are religious wars, then davean is an atheist. I never knew how to argue with atheists :P

That's the problem with them, you just can't.

To be honest, davean is perfectly right. Except in Python. You can't mess with Python's style. They enforce it.
It's okay, I'm Chaotic Neutral. I can kill him over the loot.
Overexposure to pieaholicx may, in semi-rare cases, emancipate dental fillings, crowns, tooth enamel, and teeth.
User avatar
pieaholicx
The cake is a lie!
 
Posts: 531
Joined: Mon Oct 22, 2007 12:51 pm UTC

Re: The 1 true style

Postby davean » Fri Nov 16, 2007 6:03 pm UTC

pieaholicx wrote:Except in Python. You can't mess with Python's style. They enforce it.


Nothing a small bit of LISP and Emacs can't fix ...
User avatar
davean
Site Ninja
 
Posts: 2436
Joined: Sat Apr 08, 2006 7:50 am UTC

Re: The 1 true style

Postby pieaholicx » Fri Nov 16, 2007 6:04 pm UTC

davean wrote:
pieaholicx wrote:Except in Python. You can't mess with Python's style. They enforce it.


Nothing a small bit of LISP and Emacs can't fix ...

Fuck. I lose.
It's okay, I'm Chaotic Neutral. I can kill him over the loot.
Overexposure to pieaholicx may, in semi-rare cases, emancipate dental fillings, crowns, tooth enamel, and teeth.
User avatar
pieaholicx
The cake is a lie!
 
Posts: 531
Joined: Mon Oct 22, 2007 12:51 pm UTC

Re: The 1 true style

Postby rrwoods » Fri Nov 16, 2007 6:26 pm UTC

I'm in the "I don't care as long as it's consistent" camp; although, when I code I prefer to use the Allman style, the reason being that this:
Code: Select all
if(condition) {
   statement();

to me looks too similar to this:
Code: Select all
if(condition)
    statement();

but a decent editor with brace highlighting (or better: format-on-save (thanks Eclipse!)) will take care of this anyway.
26/M/taken/US
age/gender/interest/country

Belial wrote:The sex card is tournament legal. And I am tapping it for, like, six mana.
User avatar
rrwoods
 
Posts: 1507
Joined: Mon Sep 24, 2007 5:57 pm UTC
Location: US

Re: The 1 true style

Postby EvanED » Fri Nov 16, 2007 6:37 pm UTC

Rysto wrote:Can we all agree that GNU style sucks, though?

YES.

"First off, I'd suggest printing out a copy of the GNU coding standards, and NOT read it. Burn them, it's a great symbolic gesture."
- Linus Torvalds

As for me, I used to use Allman, but I've switched to K&R after being forced to use it for an project. I don't particularly care between those.

Some "peculiarities" to my personal style:
All blocks get braces, even if they consist of only a single statement

If the condition on a branch is multi-line, the opening brace gets it's own line. In other words,
Code: Select all
if(foo
   || foo)
{
    ...
}
rather than
Code: Select all
if(foo
   || foo) {
    ...
}


However, such conditions are a smell and should be avoided if practical. (I waffle on whether operators such as the || in the above example go at the end of the first line or beginning of the second.)
EvanED
 
Posts: 4120
Joined: Mon Aug 07, 2006 6:28 am UTC
Location: Madison, WI

Re: The 1 true style

Postby d3adf001 » Fri Nov 16, 2007 7:13 pm UTC

i find allmen by far the easiest on the eye and finding blocks. also the lines for brackets doesnt bother me much since they make screens that have 80+ rows.
User avatar
d3adf001
 
Posts: 1000
Joined: Thu Mar 29, 2007 4:27 pm UTC
Location: State College, PA

Re: The 1 true style

Postby Lothar » Fri Nov 16, 2007 8:21 pm UTC

I'm a fan of the Allman style, but I don't mind the K&R style either. After looking at the Wikipedia article on indent style, I am surprised that I don't really mind the Whitesmiths-type styles. I find the GNU style impractical though.

As long as it's consistent, I guess I'm fine with it. I'll use the Allman style for now, though.
Always program as if the person who will be maintaining your program is a violent psychopath that knows where you live.

If you're not part of the solution, you're part of the precipitate.

1+1=3 for large values of 1.
User avatar
Lothar
 
Posts: 61
Joined: Sat Dec 23, 2006 11:37 am UTC
Location: Berlin, Germany

Re: The 1 true style

Postby EvanED » Fri Nov 16, 2007 10:16 pm UTC

d3adf001 wrote:i find allmen by far the easiest on the eye and finding blocks. also the lines for brackets doesnt bother me much since they make screens that have 80+ rows.

YES! Coding standards that prohibit lines above 80 characters really bug me.
EvanED
 
Posts: 4120
Joined: Mon Aug 07, 2006 6:28 am UTC
Location: Madison, WI

Re: The 1 true style

Postby d3adf001 » Fri Nov 16, 2007 11:31 pm UTC

EvanED wrote:
d3adf001 wrote:i find allmen by far the easiest on the eye and finding blocks. also the lines for brackets doesnt bother me much since they make screens that have 80+ rows.

YES! Coding standards that prohibit lines above 80 characters really bug me.


I was talking about rows. my laptop is somewhere around 165x70 and i know they make higher resolution monitors. I think that if you are getting 80+ chars per line its getting kind of long unless its a function definition
User avatar
d3adf001
 
Posts: 1000
Joined: Thu Mar 29, 2007 4:27 pm UTC
Location: State College, PA

Re: The 1 true style

Postby EvanED » Fri Nov 16, 2007 11:45 pm UTC

d3adf001 wrote:I was talking about rows. my laptop is somewhere around 165x70 and i know they make higher resolution monitors. I think that if you are getting 80+ chars per line its getting kind of long unless its a function definition

Me fail English? That's unpossible!
EvanED
 
Posts: 4120
Joined: Mon Aug 07, 2006 6:28 am UTC
Location: Madison, WI

Re: The 1 true style

Postby photosinensis » Sat Nov 17, 2007 7:08 am UTC

I neither have nor desire style. My code is always in one line. ALWAYS.

Well, except for the preprocessor directives in C/C++. Or when I'm in a language with syntactically significant whitespace (Python, Ruby, I'm looking at you). For loops don't work quite as well.

Now, if someone could only explain to me why we're using the damn semicolon all the time, I'd be, well, maybe not happy, but you get the idea.
While I clicked my fav'rite bookmark, suddenly there came a warning,
And my heart was filled with mournng, mourning for my dear amour.
"'Tis not possible!" I uttered, "Give me back my free hardcore!"
Quoth the server: 404.
photosinensis
 
Posts: 163
Joined: Wed Aug 22, 2007 6:17 am UTC

Re: The 1 true style

Postby Embryo » Sat Nov 17, 2007 1:29 pm UTC

I use Allman, but I'm in the "Who cares" camp.

In my experience, code's readability or lack thereof bears very little connecting to which style you consistently use.
Embryo
 
Posts: 31
Joined: Thu Oct 18, 2007 2:15 am UTC
Location: SF Bay Area

Re: The 1 true style

Postby d3adf001 » Sat Nov 17, 2007 7:54 pm UTC

EvanED wrote:
d3adf001 wrote:I was talking about rows. my laptop is somewhere around 165x70 and i know they make higher resolution monitors. I think that if you are getting 80+ chars per line its getting kind of long unless its a function definition

Me fail English? That's unpossible!


that makes perfect sense to me. i even read it twice
User avatar
d3adf001
 
Posts: 1000
Joined: Thu Mar 29, 2007 4:27 pm UTC
Location: State College, PA

Re: The 1 true style

Postby Rysto » Sat Nov 17, 2007 7:59 pm UTC

d3adf001 wrote:that makes perfect sense to me. i even read it twice

EvanED was making fun of himself for misreading a post...
Rysto
 
Posts: 1442
Joined: Wed Mar 21, 2007 4:07 am UTC

Re: The 1 true style

Postby Number » Sun Nov 18, 2007 3:01 am UTC

Proper coding conventions follow this guy's suggestions for unmaintainable code.

Seriously though, I'm on board for vertically aligned braces.
You live and learn. At any rate, you live.
User avatar
Number
 
Posts: 63
Joined: Thu Aug 02, 2007 5:42 am UTC
Location: Earth. supposedly

Re: The 1 true style

Postby wing » Sun Nov 18, 2007 4:19 am UTC

Vertically aligned. THERE IS NO OTHER.

Code: Select all
if(true)
{
     for(;;)
     {
          try
          {
               foo();
          }
          catch(Exception fail)
          {
               bar();
          }
     }
}


However, if your bracket-tree extends more than one line on a standard issue console, you'd better fucking comment your close brackets.
I AM A SEXY, SHOELESS GOD OF WAR!
Akula wrote:Our team has turned into this hate-fueled juggernaut of profit. It's goddamn wonderful.
User avatar
wing
the /b/slayer
 
Posts: 1876
Joined: Tue May 29, 2007 5:56 am UTC

Re: The 1 true style

Postby d3adf001 » Sun Nov 18, 2007 4:44 am UTC

wing im pretty sure thats allman
User avatar
d3adf001
 
Posts: 1000
Joined: Thu Mar 29, 2007 4:27 pm UTC
Location: State College, PA

Re: The 1 true style

Postby notzeb » Sun Nov 18, 2007 4:55 am UTC

Code: Select all
if (blah) {
    stuff1;
    stuff2;
} else if (stuff) blah;
    else while (hmm) if (hungry) hmm /= 2;
        else {
            --hmm;
            goto label;
        }

Edit: obviously, real tabs. And there's nothing I hate more than the "smart tabs" I keep being force-fed :x
Last edited by notzeb on Sun Nov 18, 2007 7:59 am UTC, edited 1 time in total.
Zµ«V­jÕ«ZµjÖ­Zµ«VµjÕ­ZµkV­ZÕ«VµjÖ­Zµ«V­jÕ«ZµjÖ­ZÕ«VµjÕ­ZµkV­ZÕ«VµjÖ­Zµ«V­jÕ«ZµjÖ­ZÕ«VµjÕ­ZµkV­ZÕ«ZµjÖ­Zµ«V­jÕ«ZµjÖ­ZÕ«VµjÕ­Z
User avatar
notzeb
Without Warning
 
Posts: 566
Joined: Thu Mar 08, 2007 5:44 am UTC
Location: a series of tubes

Re: The 1 true style

Postby trickster721 » Sun Nov 18, 2007 6:50 am UTC

Code: Select all
function a()
      {
      if (b > c) {...;}
      else
            {
            ...;
            ...;
            }
      }

People look at me weird, but I have trouble reading it any other way.

Real tabs, not spaces. And none of this arguments split up onto multiple lines buisness.
trickster721
 
Posts: 282
Joined: Tue Nov 13, 2007 4:26 am UTC

Re: The 1 true style

Postby Dingbats » Sun Nov 18, 2007 10:53 am UTC

K&R with spaces. I guess there's no rational reason not to use real tabs, though.
User avatar
Dingbats
 
Posts: 921
Joined: Tue Mar 20, 2007 12:46 pm UTC
Location: Sweden

Re: The 1 true style

Postby davean » Sun Nov 18, 2007 11:33 am UTC

wing wrote:Vertically aligned. THERE IS NO OTHER.


There is another and it is the false god who's temptation (can you actually be tempted by something so vile?) must be resisted.
User avatar
davean
Site Ninja
 
Posts: 2436
Joined: Sat Apr 08, 2006 7:50 am UTC

Re: The 1 true style

Postby Rysto » Sun Nov 18, 2007 5:32 pm UTC

Dingbats wrote:K&R with spaces. I guess there's no rational reason not to use real tabs, though.

Yes, there is. Too many people editors don't understand how to properly mix tabs and spaces to indent and align code without depending on a particular tab width.
Rysto
 
Posts: 1442
Joined: Wed Mar 21, 2007 4:07 am UTC

Re: The 1 true style

Postby trickster721 » Sun Nov 18, 2007 6:07 pm UTC

Rysto wrote:
Dingbats wrote:K&R with spaces. I guess there's no rational reason not to use real tabs, though.

Yes, there is. Too many people editors don't understand how to properly mix tabs and spaces to indent and align code without depending on a particular tab width.

What the hell does that even mean? Why are we mixing tabs and spaces? Why does it matter how wide a tab is?

Wait, are you one of those people who make a function call into a ten-line peice of ASCII art? Because I thought my Master destroyed the last of your wicked style in the Battle of the Jade Swan. Not a rational reason.
trickster721
 
Posts: 282
Joined: Tue Nov 13, 2007 4:26 am UTC

Re: The 1 true style

Postby OfficiallyHaphazard » Sun Nov 18, 2007 6:10 pm UTC

person aove me wrote: What the hell does that even mean? Why are we mixing tabs and spaces? Why does it matter how wide a tab is?


Agreed!
"Who are you, how did you get in my house?" - Donald Knuth
User avatar
OfficiallyHaphazard
Age=postcount/60
 
Posts: 209
Joined: Tue Aug 28, 2007 2:56 pm UTC

Re: The 1 true style

Postby Amnesiasoft » Mon Nov 19, 2007 9:48 am UTC

I use Java style (though I despise the language itself :P). I just think the code looks cleaner that way. No wasted lines on a single bracket. And spacing things out using a combination of tabs and spaces is great, if only people knew how to do it properly...TABS are for indents, SPACES are for alignment, it's not that hard. And now we need a religious wars thread on this (or do we have onle already? Or could this thread take care of it too?)

Though looking at that wiki article...I'm kind of liking Pico style.
User avatar
Amnesiasoft
 
Posts: 2575
Joined: Tue May 15, 2007 4:28 am UTC
Location: Colorado

Re: The 1 true style

Postby EvanED » Mon Nov 19, 2007 1:34 pm UTC

Amnesiasoft wrote:I use Java style (though I despise the language itself :P). I just think the code looks cleaner that way. No wasted lines on a single bracket. And spacing things out using a combination of tabs and spaces is great, if only people knew how to do it properly...TABS are for indents, SPACES are for alignment, it's not that hard. And now we need a religious wars thread on this (or do we have onle already? Or could this thread take care of it too?)

There's one in the coding forum. I'm sure if you revive it the mods will bring it over here. ;-)

Though looking at that wiki article...I'm kind of liking Pico style.

Are you sadistic, man? ;-)
EvanED
 
Posts: 4120
Joined: Mon Aug 07, 2006 6:28 am UTC
Location: Madison, WI

Re: The 1 true style

Postby Pesto » Mon Nov 19, 2007 5:20 pm UTC

I tend to use Allman style with two spaces as an indent.
User avatar
Pesto
 
Posts: 738
Joined: Wed Sep 05, 2007 5:33 pm UTC
Location: Berkeley, CA

Re: The 1 true style

Postby trickster721 » Mon Nov 19, 2007 5:40 pm UTC

No wasted lines on a single bracket. And spacing things out using a combination of tabs and spaces is great, if only people knew how to do it properly...TABS are for indents, SPACES are for alignment, it's not that hard.

Because line feeds are so expensive these days. And I still want to know what "alignment" is and why we're doing it.
trickster721
 
Posts: 282
Joined: Tue Nov 13, 2007 4:26 am UTC

Re: The 1 true style

Postby rrwoods » Mon Nov 19, 2007 5:45 pm UTC

For people that wrap long lines, alignment is getting things to line up like you want. Like

Code: Select all
if(thisIsALongConditional ||
   thisIsALongConditionalToo)
{
   // stuff
}


Or if you (for some reason) like to line up variable declarations:

Code: Select all
double x;
int    y;
long   z;


And I agree that you should use spaces for that.
26/M/taken/US
age/gender/interest/country

Belial wrote:The sex card is tournament legal. And I am tapping it for, like, six mana.
User avatar
rrwoods
 
Posts: 1507
Joined: Mon Sep 24, 2007 5:57 pm UTC
Location: US

Re: The 1 true style

Postby blob » Mon Nov 19, 2007 5:47 pm UTC

Hammer wrote:Then, after listening to them whine, I get to plow through code that uses three different indenting styles selected at random when they bother to indent at all. Grrrrrrrrr...

http://www.gnu.org/software/indent/
Avatar yoinked from Inverloch.

"Unless ... unless they kill us, then animate our corpses as dead zombies to fight for them. Then I suppose they've taken our lives, AND our freedom."
- Elan, OOTS 421.
User avatar
blob
 
Posts: 343
Joined: Thu Apr 05, 2007 8:19 pm UTC

Re: The 1 true style

Postby Pesto » Mon Nov 19, 2007 5:49 pm UTC

trickster721 wrote:
No wasted lines on a single bracket. And spacing things out using a combination of tabs and spaces is great, if only people knew how to do it properly...TABS are for indents, SPACES are for alignment, it's not that hard.

Because line feeds are so expensive these days. And I still want to know what "alignment" is and why we're doing it.

I think this is what is being referred to.

Code: Select all
function someFunction(int someParameter)
{
    // with alignment
    while(someParameter >= someUngodlyLongFunctionCallThatDoesSomethingImportant()
       && someParameter <= someOtherImportantFunctionCall())
    {
        doStuff();
    }

    // without alignment
    while(someParameter >= someUngodlyLongFunctionCallThatDoesSomethingImportant()
    && someParameter <= someOtherImportantFunctionCall())
    {
        doStuff();
    }

}
User avatar
Pesto
 
Posts: 738
Joined: Wed Sep 05, 2007 5:33 pm UTC
Location: Berkeley, CA

Next

Return to Religious Wars

Who is online

Users browsing this forum: No registered users and 3 guests