The 1 true style

Please compose all posts in Emacs.

Moderators: phlip, Moderators General, Prelates

User avatar
quintopia
Posts: 2906
Joined: Fri Nov 17, 2006 2:53 am UTC
Location: atlanta, ga

Re: The 1 true style

Postby quintopia » Wed Apr 09, 2008 5:24 pm UTC

Rysto wrote:
d3adf001 wrote:
EvanEd wrote:Me fail English? That's unpossible!

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

EvanED was making fun of himself for misreading a post...


Incidentally, he was also quoting the archetypal idiot's idiot.

JamesObscura
Posts: 69
Joined: Tue Mar 11, 2008 3:58 am UTC
Contact:

Re: The 1 true style

Postby JamesObscura » Fri Apr 11, 2008 8:02 am UTC

wallotext style.

Code: Select all

public void suckit(boolean foobar, int yourMomsAge)
{
if (foobar == true &&
yourMomsAge > 9000)
{
System.out.print(Fail)
// Fail is a giant 5000 line ascii mural of lemonparty)
}
else
{
System.out.print(epicFail());
}
}
public void epicFail();
{
for(;;)
{
System.out.print(Fail);
}
}


(I prefer allman's)
Contraceptives?

I recommend an inverse tachyon beam.

User avatar
Ephphatha
Posts: 625
Joined: Sat Sep 02, 2006 9:03 am UTC
Location: Bathurst, NSW, Australia

Re: The 1 true style

Postby Ephphatha » Sat Apr 12, 2008 4:11 pm UTC

Allman, indented four spaces for each level. I don't like tab characters because when I look at my code on my DS the tab is an unsupported character. (I hate using Visual Studio on the uni machines for that reason.)
I'm not lazy, I'm just getting in early for Christmas is all...

EvanED
Posts: 4314
Joined: Mon Aug 07, 2006 6:28 am UTC
Location: Madison, WI
Contact:

Re: The 1 true style

Postby EvanED » Sat Apr 12, 2008 7:10 pm UTC

Ephphatha wrote:(I hate using Visual Studio on the uni machines for that reason.)

You can change what VS uses for it's indent.

qbg
Posts: 586
Joined: Tue Dec 18, 2007 3:37 pm UTC

Re: The 1 true style

Postby qbg » Sun Apr 13, 2008 1:02 am UTC

EvanED wrote:Oh yes, now it's coming back. Another issue was that, because lines often closed parens from previous lines, even if there was a "logically distinct line" you couldn't necessarily just comment it out. For instance, if you were dealing with a let:

Code: Select all

(let ((a (bar))
      (b (baz)))
  ...)

and think that there may be a computation problem in b, you can just comment out line 2 because then it's syntactically invalid.

Preceding a form with #+(or) or #+t (assuming that you don't have T in *features*) in Common Lisp will effectively comment the form out....

Anyways, in Java I use Java style, and in Lisp I use the standard style...

User avatar
Øsse
Posts: 51
Joined: Tue Jul 31, 2007 5:54 am UTC
Location: Bergen, Norway
Contact:

Re: The 1 true style

Postby Øsse » Mon Apr 28, 2008 10:40 pm UTC

I have no idea what the different conventions are called, but i like spaces around conditions - but not before function parameters for some reason - and no newline for opening braces but newlines for closing braces and elses:

Code: Select all

if (world == FUBAR ) {
    runToBombShelter();
}
else {
    int roundsFired = 0;
    while (!lastManStanding) {
        roundsFired++;
        cout << Cliche.getRandOneLiner();
    }
}

Also, all blocks get braces, but if there's just one statement I might write

Code: Select all

else {return false;}

int addInts(a,b) {return a+b;}

for instance. Aligned braces waste line numbers and look horrific. Am I a bad person?

User avatar
Berengal
Superabacus Mystic of the First Rank
Posts: 2707
Joined: Thu May 24, 2007 5:51 am UTC
Location: Bergen, Norway
Contact:

Re: The 1 true style

Postby Berengal » Tue Apr 29, 2008 12:23 am UTC

Øsse wrote:I have no idea what the different conventions are called, but i like spaces around conditions - but not before function parameters for some reason - and no newline for opening braces but newlines for closing braces and elses:

Code: Select all

if (world == FUBAR ) {
    runToBombShelter();
}
else {
    int roundsFired = 0;
    while (!lastManStanding) {
        roundsFired++;
        cout << Cliche.getRandOneLiner();
    }
}


That's basically java style. Where you put extra whitespace is unimportant in most styles. At least that's what I suspect from the lack of significant commentary about it.
I also separate conditions from their keywords but not function arguments from the function. Makes sense to me, as the arguments to a function is an essential part of that argument and should be read as a single "word", while conditional keywords and their statements are two "words".
Oh, and I use java style as well, since, well, I'm writing java, and eclipse already has the formatting set up like that. In python I use python style. Anything else would raise a SyntaxError.

Also, has anyone else noticed how incredibly annoying the java standard library is indented? Excerpt from the ArrayList class:

Code: Select all

    public void ensureCapacity(int minCapacity) {
   modCount++;
   int oldCapacity = elementData.length;
   if (minCapacity > oldCapacity) {
       Object oldData[] = elementData;
       int newCapacity = (oldCapacity * 3)/2 + 1;
           if (newCapacity < minCapacity)
      newCapacity = minCapacity;
            // minCapacity is usually close to size, so this is a win:
            elementData = Arrays.copyOf(elementData, newCapacity);
   }
    }

    public ArrayList(int initialCapacity) {
   super();
        if (initialCapacity < 0)
            throw new IllegalArgumentException("Illegal Capacity: "+
                                               initialCapacity);
   this.elementData = new Object[initialCapacity];
    }

Notice the incomprehensible mix between tabs* and spaces. Sometimes there's a tab, sometimes there's four spaces, sometimes there's eight spaces, all the time it's horrible. They mix tabs and spaces in ways you shouldn't, like spaces-tab or even spaces-tab-spaces. It's utterly impossible to read, I tell you!
*The forum converts tabs to three spaces, so EVERYTHING'S fucked. On my pc at least half the time it's right.
It is practically impossible to teach good programming to students who are motivated by money: As potential programmers they are mentally mutilated beyond hope of regeneration.

User avatar
aleflamedyud
wants your cookies
Posts: 3307
Joined: Tue Oct 09, 2007 7:50 pm UTC
Location: The Central Bureaucracy

Re: The 1 true style

Postby aleflamedyud » Tue May 06, 2008 8:58 pm UTC

OfficiallyHaphazard wrote: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..

Why did you put the private keyword there? There's no class definition.
"With kindness comes naïveté. Courage becomes foolhardiness. And dedication has no reward. If you can't accept any of that, you are not fit to be a graduate student."

Rysto
Posts: 1458
Joined: Wed Mar 21, 2007 4:07 am UTC

Re: The 1 true style

Postby Rysto » Tue May 06, 2008 9:00 pm UTC

That's Java code...

User avatar
aleflamedyud
wants your cookies
Posts: 3307
Joined: Tue Oct 09, 2007 7:50 pm UTC
Location: The Central Bureaucracy

Re: The 1 true style

Postby aleflamedyud » Wed May 07, 2008 1:59 am UTC

Could have been C++.
"With kindness comes naïveté. Courage becomes foolhardiness. And dedication has no reward. If you can't accept any of that, you are not fit to be a graduate student."

EvanED
Posts: 4314
Joined: Mon Aug 07, 2006 6:28 am UTC
Location: Madison, WI
Contact:

Re: The 1 true style

Postby EvanED » Wed May 07, 2008 3:02 am UTC

aleflamedyud wrote:Could have been C++.

That's not legal C++; public and private are always followed by a colon. And C++ code isn't likely to use a "println" function.

(Could also be C#, but this is unlikely. It's probably called PrintLine there, and is definitely not capitalized in a .NET convention.)

User avatar
aleflamedyud
wants your cookies
Posts: 3307
Joined: Tue Oct 09, 2007 7:50 pm UTC
Location: The Central Bureaucracy

Re: The 1 true style

Postby aleflamedyud » Wed May 07, 2008 4:09 am UTC

What I meant was, it could have been C++ written by someone far too used to Java.

Damn Java monkeys they train in the schools nowadays...
"With kindness comes naïveté. Courage becomes foolhardiness. And dedication has no reward. If you can't accept any of that, you are not fit to be a graduate student."

afarnen
Posts: 157
Joined: Mon May 05, 2008 12:12 pm UTC

Re: The 1 true style

Postby afarnen » Thu May 08, 2008 5:06 am UTC

As for me..

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 alot more readable.

Except for the fact that I DON'T use java (or C++, for that matter). I use C. Good ol' plain C. And if I every find myself wanting to do object-oriented, I'll go with Objective-C: the object-oriented STRICT superset to C (All C programs can be compiled and work the same with Objective-C).

P.S. I guess that's GNU style, not Allman. And, I do use emacs.

masher
Posts: 821
Joined: Tue Oct 23, 2007 11:07 pm UTC
Location: Melbourne, Australia

Re: The 1 true style

Postby masher » Thu May 08, 2008 5:33 am UTC

aleflamedyud wrote:
OfficiallyHaphazard wrote:

Code: Select all

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

Why did you put the private keyword there? There's no class definition.


It's a private function that belongs to whatever class it's defined in. Basically, it can only be used in that class.

For example, I may use private functions if I've got several constructors that do the same thing except for some optional flags:

Code: Select all

public class ConstructMe
{
   public ConstructMe(String str)
   {
      useMe(str, false);
   }
   
   public ConstructMe(String str, boolean flag)
   {
      useMe(str, flag);
   }
   
   private void useMe(String str, boolean flag)
   {
      //code that uses str and flag
   }
}


This way, I've only got to maintain useMe(), not two sets of ConstructMe().

.

edit: grammar.
Last edited by masher on Thu May 08, 2008 6:38 am UTC, edited 1 time in total.

User avatar
1337geek
Posts: 551
Joined: Mon Oct 01, 2007 4:21 am UTC

Re: The 1 true style

Postby 1337geek » Thu May 08, 2008 6:29 am UTC

Honestly, I've never really understood K&R. Allman just makes more sense. It's cleaner, neater, and a lot easier to keep track of. With K&R, it's a lot harder to tell where loops and ifs start and end.
"Duct tape is like the Force. It has a light side, a dark side, and it holds the universe together." --Carl Zwanzig

Rysto
Posts: 1458
Joined: Wed Mar 21, 2007 4:07 am UTC

Re: The 1 true style

Postby Rysto » Thu May 08, 2008 3:00 pm UTC

masher wrote:

Code: Select all

public class ConstructMe
{
   public ConstructMe(String str)
   {
      useMe(str, false);
   }
   
   public ConstructMe(String str, boolean flag)
   {
      useMe(str, flag);
   }
   
   private void useMe(String str, boolean flag)
   {
      //code that uses str and flag
   }
}


This way, I've only got to maintain useMe(), not two sets of ConstructMe().

.

edit: grammar.

Don't do this. Instead, do the following:

Code: Select all

public class ConstructMe
{
   public ConstructMe(String str)
   {
      this(str, false);
   }
   
   public ConstructMe(String str, boolean flag)
   {
      //code that uses str and flag
   }
}


Obviously the preceeding doesn't apply if the functionality that used to be in useMe() is needed in methods as well as in constructors.

masher
Posts: 821
Joined: Tue Oct 23, 2007 11:07 pm UTC
Location: Melbourne, Australia

Re: The 1 true style

Postby masher » Fri May 09, 2008 2:18 am UTC

Rysto wrote:do the following:

Code: Select all

public class ConstructMe
{
   public ConstructMe(String str)
   {
      this(str, false);
   }
   
   public ConstructMe(String str, boolean flag)
   {
      //code that uses str and flag
   }
}


Obviously the preceeding doesn't apply if the functionality that used to be in useMe() is needed in methods as well as in constructors.


Ah! I didn't realise you could use "this" in that fashion.

Much neater...

User avatar
Berengal
Superabacus Mystic of the First Rank
Posts: 2707
Joined: Thu May 24, 2007 5:51 am UTC
Location: Bergen, Norway
Contact:

Re: The 1 true style

Postby Berengal » Fri May 09, 2008 3:59 am UTC

Am I a bad person for doing it the other way around sometimes?

Code: Select all

class Foo{
  public Foo(int arg){
    this.arg = arg;
  }

  public Foo(int arg, int arg2){
    this(arg);
    this.arg2 = arg2;
  }
}

I've done that when I've found I need to add a new member that doesn't have to be set.
It is practically impossible to teach good programming to students who are motivated by money: As potential programmers they are mentally mutilated beyond hope of regeneration.

User avatar
phlip
Restorer of Worlds
Posts: 7535
Joined: Sat Sep 23, 2006 3:56 am UTC
Location: Australia
Contact:

Re: The 1 true style

Postby phlip » Fri May 09, 2008 4:24 am UTC

Berengal wrote:Am I a bad person for doing it the other way around sometimes?

Yes.

When you do it the right way around, the one-parameter version sets the second parameter to a (presumably) sane default.
When you do it your way around, the one-paramater version doesn't set the second parameter at all, and it will end up with some random value.

Code: Select all

enum ಠ_ಠ {°□°╰=1, °Д°╰, ಠ益ಠ╰};
void ┻━┻︵​╰(ಠ_ಠ ⚠) {exit((int)⚠);}
[he/him/his]

User avatar
Berengal
Superabacus Mystic of the First Rank
Posts: 2707
Joined: Thu May 24, 2007 5:51 am UTC
Location: Bergen, Norway
Contact:

Re: The 1 true style

Postby Berengal » Fri May 09, 2008 4:39 am UTC

It's Java so it'll end up null, which is what the default value would've been anyway.
It is practically impossible to teach good programming to students who are motivated by money: As potential programmers they are mentally mutilated beyond hope of regeneration.

User avatar
TomBot
Posts: 228
Joined: Sun Jul 29, 2007 1:17 am UTC
Location: Illinois (UIUC)
Contact:

Re: The 1 true style

Postby TomBot » Fri May 09, 2008 4:40 am UTC

I think they're talking Java, in which case, uninitialized references are null and native types are zero.

Edit: ninja'd

masher
Posts: 821
Joined: Tue Oct 23, 2007 11:07 pm UTC
Location: Melbourne, Australia

Re: The 1 true style

Postby masher » Fri May 09, 2008 4:47 am UTC

Berengal wrote:It's Java so it'll end up null, which is what the default value would've been anyway.


That just sounds ... wrong.

And what if you want the default value to be not 0? (Yes, I know you can declare int j = 5;, but I don't really like that either)

What happens if this is done:

Code: Select all

class Test
{
   int i;
   int j;

   public Test(int arg1)
   {
      i = arg1;
   }

   public Test(int arg1, int arg2)
   {
      this(arg1);
      j = arg2;
   }

   int getI()
   {
      return i;
   }

   int getJ()
   {
      return j;
   }

   public static void main(String[] args) throws Exception
   {
      Test t = new Test(1);
      System.out.println(t.getJ());
   }
}


It should fail in a great big ball of fire, but it silently works.

User avatar
Ephphatha
Posts: 625
Joined: Sat Sep 02, 2006 9:03 am UTC
Location: Bathurst, NSW, Australia

Re: The 1 true style

Postby Ephphatha » Fri May 09, 2008 5:11 am UTC

masher wrote:
Rysto wrote:do the following:

Code: Select all

public class ConstructMe
{
   public ConstructMe(String str)
   {
      this(str, false);
   }
   
   public ConstructMe(String str, boolean flag)
   {
      //code that uses str and flag
   }
}


Obviously the preceeding doesn't apply if the functionality that used to be in useMe() is needed in methods as well as in constructors.


Ah! I didn't realise you could use "this" in that fashion.

Much neater...


Am I a bad person for doing constructors like so? (In C++, which might make this point moot as C++ and Java are two different languages.)

Code: Select all

class ConstructMe
{
public:
        ConstructMe(String str, bool flag = false);
};


I just find one constructor with optional arguments to be much neater.
I'm not lazy, I'm just getting in early for Christmas is all...

User avatar
phlip
Restorer of Worlds
Posts: 7535
Joined: Sat Sep 23, 2006 3:56 am UTC
Location: Australia
Contact:

Re: The 1 true style

Postby phlip » Fri May 09, 2008 5:22 am UTC

Ephphatha wrote:(In C++, which might make this point moot as C++ and Java are two different languages.)

C++ doesn't have chained constructors, so you couldn't do it the Java way even if you wanted to. And Java, last time I checked, didn't have optional parameters, so you couldn't do it the C++ way even if you wanted to.

So yes, a bit of a moot point...

(As for the uninitialised variable thing... I could've sworn that Java had uninitialised vars have random values, like C/C++ does... I guess it's been too long since I used Java.)

Code: Select all

enum ಠ_ಠ {°□°╰=1, °Д°╰, ಠ益ಠ╰};
void ┻━┻︵​╰(ಠ_ಠ ⚠) {exit((int)⚠);}
[he/him/his]

User avatar
TomBot
Posts: 228
Joined: Sun Jul 29, 2007 1:17 am UTC
Location: Illinois (UIUC)
Contact:

Re: The 1 true style

Postby TomBot » Fri May 09, 2008 6:22 am UTC

Java's philosophy is to keep you as far away from the system as possible, so they would never let you see a "random" variable that might confirm to you that there is some sort of stack.

User avatar
phlip
Restorer of Worlds
Posts: 7535
Joined: Sat Sep 23, 2006 3:56 am UTC
Location: Australia
Contact:

Re: The 1 true style

Postby phlip » Fri May 09, 2008 6:41 am UTC

True... and I guess it's important that Object references always come out as null by default... if they could be pointing to random places in memory, then Bad Things would happen... which is less of an issue in C/C++, since you have the tools there to cope with dangling pointers.

And if you're automatically initialising references, you may as well automatically initalise everything.

Code: Select all

enum ಠ_ಠ {°□°╰=1, °Д°╰, ಠ益ಠ╰};
void ┻━┻︵​╰(ಠ_ಠ ⚠) {exit((int)⚠);}
[he/him/his]

User avatar
Berengal
Superabacus Mystic of the First Rank
Posts: 2707
Joined: Thu May 24, 2007 5:51 am UTC
Location: Bergen, Norway
Contact:

Re: The 1 true style

Postby Berengal » Fri May 09, 2008 7:41 am UTC

The rationale for allowing objects to be constructed with uninitialized variables was that anyone who needed those variables would've initialized them anyway, and initializing them to null would've made no difference anyway. (I think I went "private Foo f = null;" in the declaration too).

Although, yes, I agree it's bad form. It was just a quick hack to see if my design solution was viable before implementing it properly. I wasn't going to reorder all my constructor statements if I had to undo that later on anyway (and a good thing it was too, because I had to make some changes).
It is practically impossible to teach good programming to students who are motivated by money: As potential programmers they are mentally mutilated beyond hope of regeneration.

EvanED
Posts: 4314
Joined: Mon Aug 07, 2006 6:28 am UTC
Location: Madison, WI
Contact:

Re: The 1 true style

Postby EvanED » Fri May 09, 2008 5:17 pm UTC

phlip wrote:True... and I guess it's important that Object references always come out as null by default... if they could be pointing to random places in memory, then Bad Things would happen... which is less of an issue in C/C++, since you have the tools there to cope with dangling pointers.

?

What tools? Unless you're talking about Valgrind and such...

Rysto
Posts: 1458
Joined: Wed Mar 21, 2007 4:07 am UTC

Re: The 1 true style

Postby Rysto » Fri May 09, 2008 5:18 pm UTC

phlip wrote:if they could be pointing to random places in memory, then Bad Things would happen.

You can't write a copying garbage collector if you allow pointers to point to random pieces of memory, either.

User avatar
phlip
Restorer of Worlds
Posts: 7535
Joined: Sat Sep 23, 2006 3:56 am UTC
Location: Australia
Contact:

Re: The 1 true style

Postby phlip » Sat May 10, 2008 12:59 am UTC

EvanED wrote:?

What tools? Unless you're talking about Valgrind and such...

I was just referring to the fact that you can do direct pointer manipulation in C/C++, and you can't in Java... I guess I worded it a bit badly.

Code: Select all

enum ಠ_ಠ {°□°╰=1, °Д°╰, ಠ益ಠ╰};
void ┻━┻︵​╰(ಠ_ಠ ⚠) {exit((int)⚠);}
[he/him/his]

User avatar
TheOrangeMan
Posts: 25
Joined: Wed Feb 27, 2008 4:29 am UTC
Location: Directlly above you... IN THE FOURTH DIMENSION :O
Contact:

Re: The 1 true style

Postby TheOrangeMan » Mon Mar 23, 2009 12:05 am UTC

I use whitesmiths style because it makes sense. I honestly don't understand people who use allman style. It's like having a calendar where the days of the week are listed alphabetically. I mean, you could probably find any day just as fast but doesn't it make just a little more sense to put them in chronological order?

Of course, I also have a few quirks with my style that some people disagree with.

Code: Select all

// If I chain if-else's and the statements are short, I usually do this

     if (condition) ...;
else if (condition) ...;
else                ...;

// I align nested for loops.
// I think of them as a single, two-dimensional iteration instead of n, one-dimensional ones.

for (unsigned i = 0; i < n; i++)
for (unsigned j = 0; j < m; j++)
    {
    ...;
    }

// I put the brace on the same line for try and do statements...
// but only because they fit without messing up alignment!

try {
    ...;
    }
catch (...)
    {
    ...;
    }

do  {
    ...;
    }
while (condition);

// I also try to align similar lines of code whenever possible.

Something      = 10;
SomethingElse  =  5;

// In classes, I put underscores after the variable names in the constructor,
// as opposed to the usual practice of making all the private data have underscores,
// which I find annoying as all hell to work with.

class Class
    {
    private:
        int Data;

    public:
         Class(int Data_);
    };



There are a lot of other things. I've gotten a reputation for being super anal about how I write my code :P
I am, however, consistent, and my code is usually quite readable.
Science is like math turned inside out.

masher
Posts: 821
Joined: Tue Oct 23, 2007 11:07 pm UTC
Location: Melbourne, Australia

Re: The 1 true style

Postby masher » Mon Mar 23, 2009 12:33 am UTC

TheOrangeMan wrote:

Code: Select all

// I align nested for loops.
// I think of them as a single, two-dimensional iteration instead of n, one-dimensional ones.

for (unsigned i = 0; i < n; i++)
for (unsigned j = 0; j < m; j++)
    {
    ...;
    }



I've started doing this now.

It makes my code much easier to read....

User avatar
rrwoods
Posts: 1509
Joined: Mon Sep 24, 2007 5:57 pm UTC
Location: US

Re: The 1 true style

Postby rrwoods » Mon Mar 23, 2009 1:47 pm UTC

TheOrangeMan wrote:

Code: Select all

// I align nested for loops.
// I think of them as a single, two-dimensional iteration instead of n, one-dimensional ones.

for (unsigned i = 0; i < n; i++)
for (unsigned j = 0; j < m; j++)
    {
    ...;
    }



I don't do this myself (mostly because I'm mostly writing Java using Eclipse right now and it's formatter doesn't support it), but I do like it. A lot.
31/M/taken/US
age/gender/interest/country

Belial wrote:The sex card is tournament legal. And I am tapping it for, like, six mana.

0xBADFEED
Posts: 687
Joined: Mon May 05, 2008 2:14 am UTC

Re: The 1 true style

Postby 0xBADFEED » Mon Mar 23, 2009 1:56 pm UTC

TheOrangeMan wrote:

Code: Select all

// I align nested for loops.
// I think of them as a single, two-dimensional iteration instead of n, one-dimensional ones.

for (unsigned i = 0; i < n; i++)
for (unsigned j = 0; j < m; j++)
    {
    ...;
    }



That's awful... just awful.
Last edited by 0xBADFEED on Mon Mar 23, 2009 6:16 pm UTC, edited 1 time in total.

User avatar
Xanthir
My HERO!!!
Posts: 5157
Joined: Tue Feb 20, 2007 12:49 am UTC
Location: The Googleplex
Contact:

Re: The 1 true style

Postby Xanthir » Mon Mar 23, 2009 6:09 pm UTC

Agreed. That's eye-straining. What's wrong with:

Code: Select all

for(foo){
    for(bar){
        baz;}}
(defun fibs (n &optional (a 1) (b 1)) (take n (unfold '+ a b)))

User avatar
ash.gti
Posts: 404
Joined: Thu Feb 07, 2008 1:18 am UTC
Location: Probably a coffee shop.

Re: The 1 true style

Postby ash.gti » Mon Mar 23, 2009 7:28 pm UTC

How many people here leave a space after keywords with '('? like:

Code: Select all

if(true) || for(ever)
vs
if (true) || for (ever)


I personally always do a space for the keywords (so i can more easily tell them apart from functions).
# drinks WAY to much espresso

User avatar
Xanthir
My HERO!!!
Posts: 5157
Joined: Tue Feb 20, 2007 12:49 am UTC
Location: The Googleplex
Contact:

Re: The 1 true style

Postby Xanthir » Mon Mar 23, 2009 8:13 pm UTC

I find the distinction between keywords and functions to be horrendous, so I've never even thought to do that.

However, I do put a space *inside* my parens on either side, so I get:

Code: Select all

if( true ) || for( ever )
(defun fibs (n &optional (a 1) (b 1)) (take n (unfold '+ a b)))

Vempele
Posts: 69
Joined: Wed Nov 14, 2007 8:05 am UTC

Re: The 1 true style

Postby Vempele » Mon Mar 23, 2009 8:52 pm UTC

Who puts spaces after commas like this?

Code: Select all

some_func(a, b, c, d, e);
It's much harder to read and looks horrible.
const int ALMOST_FIFTY = 80;

User avatar
Berengal
Superabacus Mystic of the First Rank
Posts: 2707
Joined: Thu May 24, 2007 5:51 am UTC
Location: Bergen, Norway
Contact:

Re: The 1 true style

Postby Berengal » Mon Mar 23, 2009 9:10 pm UTC

Vempele's sig wrote:auto fib = series!("a[n-1] + a[n]")(1, 1);

Emphasis mine.
It is practically impossible to teach good programming to students who are motivated by money: As potential programmers they are mentally mutilated beyond hope of regeneration.

User avatar
ash.gti
Posts: 404
Joined: Thu Feb 07, 2008 1:18 am UTC
Location: Probably a coffee shop.

Re: The 1 true style

Postby ash.gti » Mon Mar 23, 2009 9:22 pm UTC

Adding a space after the comma gives it a bit more visual distinction between variables, I always put a space after the comma in function arguments. I personally think it helps.

my code would look something like:

Code: Select all

# its ruby btw
def foo numbers, words
  longest = words.inject do |memo, word|
    memo.length > word.length ? memo : word
  end << " and " << numbers.inject(0) do |sum, t|
    sum + t
  end.to_s
end

p foo [1, 4, 6, 2], %w{one two three} # => "three and 13"


I think its a pretty clean example of how the spaces can help keep the various arguments separate visually to help prevent confusion.
# drinks WAY to much espresso


Return to “Religious Wars”

Who is online

Users browsing this forum: No registered users and 3 guests