Why is this a good practice?

  • (4 Pages)
  • +
  • 1
  • 2
  • 3
  • 4

52 Replies - 4807 Views - Last Post: 23 September 2013 - 07:07 AM

#31 jon.kiparsky  Icon User is online

  • Pancakes!
  • member icon


Reputation: 8001
  • View blog
  • Posts: 13,710
  • Joined: 19-March 11

Re: Why is this a good practice?

Posted 14 August 2013 - 01:17 AM

View Postcfoley, on 14 August 2013 - 03:08 AM, said:

Are you crazy enough to reconfigure your code formatter?



No, I'm crazy enough to flame you for making a satirical suggestion. Or at least, I'm adopting the posture of such madness for ironic effect.
Was This Post Helpful? 0
  • +
  • -

#32 cfoley  Icon User is offline

  • Cabbage
  • member icon

Reputation: 2069
  • View blog
  • Posts: 4,307
  • Joined: 11-December 07

Re: Why is this a good practice?

Posted 14 August 2013 - 01:35 AM

I am no longer sure who you are trolling at, sir.
Was This Post Helpful? 0
  • +
  • -

#33 jon.kiparsky  Icon User is online

  • Pancakes!
  • member icon


Reputation: 8001
  • View blog
  • Posts: 13,710
  • Joined: 19-March 11

Re: Why is this a good practice?

Posted 14 August 2013 - 01:58 AM

View Postcfoley, on 14 August 2013 - 03:35 AM, said:

I am no longer sure who you are trolling at, sir.



I was making fun of LoD's little spasm of nerd rage, but I guess it misfired, probably due to scope ambiguity - it was not obvious what "that" referred to in "'Cause I was totally going to do that".

Sigh. I will try to do better next time.
Was This Post Helpful? 0
  • +
  • -

#34 cfoley  Icon User is offline

  • Cabbage
  • member icon

Reputation: 2069
  • View blog
  • Posts: 4,307
  • Joined: 11-December 07

Re: Why is this a good practice?

Posted 14 August 2013 - 02:15 AM

Well, that's what happens when you leave out the curly brackets. You of all people should know better.
Was This Post Helpful? 2
  • +
  • -

#35 depricated  Icon User is offline

  • RISC Architecture is going to change everything.

Reputation: 918
  • View blog
  • Posts: 2,996
  • Joined: 13-September 08

Re: Why is this a good practice?

Posted 14 August 2013 - 06:24 AM

TIL I'm a Leftist

I prefer Allman
Was This Post Helpful? 0
  • +
  • -

#36 cfoley  Icon User is offline

  • Cabbage
  • member icon

Reputation: 2069
  • View blog
  • Posts: 4,307
  • Joined: 11-December 07

Re: Why is this a good practice?

Posted 14 August 2013 - 06:41 AM

I didn't know there were so many lefties here. The place is becoming quite sinister.

This post has been edited by cfoley: 14 August 2013 - 06:59 AM

Was This Post Helpful? 1
  • +
  • -

#37 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9572
  • View blog
  • Posts: 36,253
  • Joined: 12-June 08

Re: Why is this a good practice?

Posted 14 August 2013 - 06:51 AM

View Postcfoley, on 14 August 2013 - 03:08 AM, said:

Are you crazy enough to reconfigure your code formatter?

I can barely configure the time on my laser disc player let alone change a hundred settings to format my code in some esoteric fashion.

Spoiler

Was This Post Helpful? 0
  • +
  • -

#38 depricated  Icon User is offline

  • RISC Architecture is going to change everything.

Reputation: 918
  • View blog
  • Posts: 2,996
  • Joined: 13-September 08

Re: Why is this a good practice?

Posted 14 August 2013 - 06:52 AM

Chicks dig my leftist dialectic.
Was This Post Helpful? 0
  • +
  • -

#39 bflosabre91  Icon User is offline

  • go sabres

Reputation: 105
  • View blog
  • Posts: 1,439
  • Joined: 22-February 08

Re: Why is this a good practice?

Posted 14 August 2013 - 12:00 PM

I never really thought about this but now I realize I do both. When I'm doing c# in visual studio, I go lefty. With Java in Eclipse, I go righty. No idea how I ended up this way. Maybe I was born this way.
Was This Post Helpful? 0
  • +
  • -

#40 BlueMelon  Icon User is offline

  • D.I.C Head

Reputation: 40
  • View blog
  • Posts: 187
  • Joined: 27-April 10

Re: Why is this a good practice?

Posted 14 August 2013 - 12:12 PM

View Postbflosabre91, on 14 August 2013 - 07:00 PM, said:

I never really thought about this but now I realize I do both. When I'm doing c# in visual studio, I go lefty. With Java in Eclipse, I go righty. No idea how I ended up this way. Maybe I was born this way.


Some editors by default, try to impose a certain style. This is most likely the reason.
Was This Post Helpful? 0
  • +
  • -

#41 andrewsw  Icon User is online

  • It's just been revoked!
  • member icon

Reputation: 3810
  • View blog
  • Posts: 13,522
  • Joined: 12-December 12

Re: Why is this a good practice?

Posted 14 August 2013 - 12:26 PM

View Postbflosabre91, on 14 August 2013 - 07:00 PM, said:

I never really thought about this but now I realize I do both. When I'm doing c# in visual studio, I go lefty. With Java in Eclipse, I go righty. No idea how I ended up this way. Maybe I was born this way.

I do this as well. Just shows that it doesn't really matter and that it's good to be flexible/adaptable when working with different languages.

( :offtopic: I also switch between my right and left-hand when using the mouse, reducing long-term strain. Sometimes I have the mouse in front of the keyboard facing right, with my arm at a comfortable angle :stuart:)
Was This Post Helpful? 1
  • +
  • -

#42 Sergio Tapia  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1253
  • View blog
  • Posts: 4,168
  • Joined: 27-January 10

Re: Why is this a good practice?

Posted 15 August 2013 - 08:18 AM

I've been working as a front end for almost 9 months now; I used to be a leftie coming from C#, but now I've been working with JS full time and really like the style in the right.

Using a new line for a curly brace just produces more clutter in my visual field now.
Was This Post Helpful? 0
  • +
  • -

#43 superman3275  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 08-September 12

Re: Why is this a good practice?

Posted 15 August 2013 - 08:46 AM

What probably happened was that there was one other programmer in your facebook "circle", they posted that, and then everyone else wanted to seem like a "programmer" (because the media has made it such an -elite- term now) so they liked that.

Or I'm just being cynical.

Either way it doesn't matter because both styles accomplish the same thing and both don't inherently make your code less readable.
Was This Post Helpful? 0
  • +
  • -

#44 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9572
  • View blog
  • Posts: 36,253
  • Joined: 12-June 08

Re: Why is this a good practice?

Posted 15 August 2013 - 08:50 AM

I disagree.

This is serious business. Serially.
Was This Post Helpful? 0
  • +
  • -

#45 stephen.d  Icon User is offline

  • New D.I.C Head

Reputation: 6
  • View blog
  • Posts: 15
  • Joined: 03-August 13

Re: Why is this a good practice?

Posted 15 August 2013 - 10:28 AM

The left is just a little easier for newbies to read. Visually lining up the braces in:

public function void foo (int a)
{
  //pew pew
  if (a == 0)
  {
    //stuff
    return;
  }

  if (a > 1000)
  {
    //stuff
    for (int i = a; a > 0; a--)
    {
      if (a % 2 == 0)
      {
        //stuff
      }
      else if (isPrime(a) == 0)
      {
        //stuff
      }
    }
    
    foo(a - 1);
  }

  if (a <= 100)
  {
    // a lot of code
    foo(a / 2);
  }
}



Is a little easier and quicker than:

public function void foo (int a) {
    //pew pew
    if (a == 0) {
      //stuff
      return;
    }

    if (a > 1000) {
    //stuff
      for (int i = a; a > 0; a--) {
        if (a % 2 == 0) {
          //stuff
        }
        else if (isPrime(a) == 0) {
          //stuff
        }
      }
      
      foo(a - 1);
    }
  
    if (a <= 100) {
      // a lot of code
      foo(a / 2);
    }
  }
}



especially when you have code and complex algorithms (not that the above is either.)
Imagine checking the above code to make sure you have the right number of brackets.
The first one requires less complex eye movements.

Both styles get used, though, and the second style can feel natural after a while.
Was This Post Helpful? 0
  • +
  • -

  • (4 Pages)
  • +
  • 1
  • 2
  • 3
  • 4