Why is this a good practice?

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

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

#1 travesty  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 67
  • Joined: 04-June 13

Why is this a good practice?

Posted 12 August 2013 - 09:47 PM

I seen this picture on Facebook, and this one really has me stumped. I'm sure the answer is somewhere, but I honestly don't know what to google to find it. Someone on Facebook said "left is a good practice, but both will run", and it had 6 likes and no one argued against it. So why is left a good practice? Just wondering if i should change my ways.

Posted Image

Is This A Good Question/Topic? 3
  • +

Replies To: Why is this a good practice?

#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4307
  • View blog
  • Posts: 12,085
  • Joined: 18-April 07

Re: Why is this a good practice?

Posted 12 August 2013 - 10:07 PM

Neither are a better practice than the other, it is just a joke on the matter of style. Some programmers put the opening curly brace on its own line and others do not. For instance, I do not. I am the "right". But neither is wrong or more right than the other. It is just a matter of coding style.

Some "official" coding standards out there (for instance like Microsoft) encourage programmers to use the left in attempt to make things more "readable" and be consistent with other code they have already written.

But you will find many programmers do either style. Several of us here on DIC actually are "righties" and some are "lefties". But again, it is just a style and a matter of taste. Neither is worse than the other and don't let them tell you any different. You will see both in books too.

:)

This post has been edited by Martyr2: 12 August 2013 - 10:07 PM

Was This Post Helpful? 4
  • +
  • -

#3 axel1994  Icon User is offline

  • D.I.C Head

Reputation: 83
  • View blog
  • Posts: 167
  • Joined: 27-May 13

Re: Why is this a good practice?

Posted 13 August 2013 - 02:10 AM

I also am a "rightie".

I find it more readable. When I look at code, I find it easier to see which brackets belong to which statement when the "right" is used.
Was This Post Helpful? 0
  • +
  • -

#4 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6033
  • View blog
  • Posts: 23,414
  • Joined: 23-August 08

Re: Why is this a good practice?

Posted 13 August 2013 - 03:09 AM

Indent style

Left is Allman, right is K&R.

I prefer Allman, but the quirks of Javascript sort of demand the use of K&R.
Was This Post Helpful? 0
  • +
  • -

#5 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 13 August 2013 - 05:27 AM

I prefer the right (K&R)
I find it easier to read and code looks more compact.

This post has been edited by BlueMelon: 13 August 2013 - 05:27 AM

Was This Post Helpful? 0
  • +
  • -

#6 xclite  Icon User is offline

  • LIKE A BOSS
  • member icon


Reputation: 894
  • View blog
  • Posts: 3,153
  • Joined: 12-May 09

Re: Why is this a good practice?

Posted 13 August 2013 - 06:08 AM

For Java, I go left. For C, right, though usually this is a matter of following project convention.

For languages like ruby with word delimiters, right.
Was This Post Helpful? 0
  • +
  • -

#7 lordofduct  Icon User is offline

  • I'm a cheeseburger
  • member icon


Reputation: 2528
  • View blog
  • Posts: 4,630
  • Joined: 24-September 10

Re: Why is this a good practice?

Posted 13 August 2013 - 07:00 AM

I'm an Allman/Leftie.

I will use what is required by the project if needed.

Personally I find it more readable, my brain picks up on the bracket symbols a lot better than words. So I see it as an opening rather easily; while still only having to read the first character of a line. Words to me mean variables/constants/etc. It's mainly because of my math background where the alphabet are usually used for the variables and constants, and other symbols for operators.

It's one of my only issues in having to write VB.Net for my job, everything uses english text. So I have to actually READ the damn text to know what's going on, as opposed to just looking for simple symbols. Which is why I prefer C# (as well as C-like languages in general). Coming from a math background is mainly why. Even the functions in math match C-style, where it's alphabet followed by parens with inputs comma delimited:

f(x,y)

This post has been edited by lordofduct: 13 August 2013 - 07:02 AM

Was This Post Helpful? 1
  • +
  • -

#8 Switters  Icon User is offline

  • D.I.C Head

Reputation: 25
  • View blog
  • Posts: 110
  • Joined: 03-June 12

Re: Why is this a good practice?

Posted 13 August 2013 - 07:52 AM

I'm a leftie. Don't listen to anyone who argues for the style on the right. Studies have shown that 98% of people who prefer the K&R indentation style were dropped frequently as children and have a high tendency towards deviant behavior.[1]

[1]Requires citation.

This post has been edited by Switters: 13 August 2013 - 07:53 AM

Was This Post Helpful? 1
  • +
  • -

#9 cfoley  Icon User is offline

  • Cabbage
  • member icon

Reputation: 1937
  • View blog
  • Posts: 4,022
  • Joined: 11-December 07

Re: Why is this a good practice?

Posted 13 August 2013 - 08:25 AM

I was dropped as a child and have a strong preference for K&R.

It's compactness gives it a slight advantage when typesetting books. Since most of us don't write books, it really doesn't matter.

This post has been edited by cfoley: 13 August 2013 - 09:27 AM

Was This Post Helpful? 1
  • +
  • -

#10 daydr3am3r  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 101
  • Joined: 10-April 09

Re: Why is this a good practice?

Posted 13 August 2013 - 09:22 AM

I'm a leftie. Can't stand the right alternative and I cannot follow the brackets, no matter what.
But there is no right or wrong here.

K&R gives compact code but the Allman style makes the code easier to follow (or it should but it's not available for everybody) since all brackets are on the same "column" so you will always new the closing bracket is somewhere straight below.

Also, you shouldn't worry much about this since most editors offer the possibility to set the style you like, no matter how others code.
Was This Post Helpful? 0
  • +
  • -

#11 cfoley  Icon User is offline

  • Cabbage
  • member icon

Reputation: 1937
  • View blog
  • Posts: 4,022
  • Joined: 11-December 07

Re: Why is this a good practice?

Posted 13 August 2013 - 09:26 AM

Quote

the Allman style makes the code easier to follow


I think whichever you are used to is easier to follow.
Was This Post Helpful? 1
  • +
  • -

#12 daydr3am3r  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 101
  • Joined: 10-April 09

Re: Why is this a good practice?

Posted 13 August 2013 - 09:29 AM

View Postcfoley, on 13 August 2013 - 10:26 AM, said:

Quote

the Allman style makes the code easier to follow


I think whichever you are used to is easier to follow.

I said it's my own opinion, not that this is how it should be.
Was This Post Helpful? 0
  • +
  • -

#13 travesty  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 67
  • Joined: 04-June 13

Re: Why is this a good practice?

Posted 13 August 2013 - 01:06 PM

Ok, they both seem to be the same for ease of following, so I might just stay with right for now.
Was This Post Helpful? 0
  • +
  • -

#14 andrewsw  Icon User is offline

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3177
  • View blog
  • Posts: 10,638
  • Joined: 12-December 12

Re: Why is this a good practice?

Posted 13 August 2013 - 01:47 PM

My two cents: I'm a rightie, particularly coming from JS. I don't believe having brackets running down a column is easier to spot matches - our eyes don't work that way :) In fact, I don't think it is possible for our eyes to follow, without detour, a vertical line down a screen. With the second version I can scan down and see the matching bracket on the right :online2long:.

But, again, just an opinion :bigsmile:. It doesn't really bother me though, I've left C# with the default indent style.

This post has been edited by andrewsw: 13 August 2013 - 01:52 PM

Was This Post Helpful? 0
  • +
  • -

#15 mojo666  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 352
  • View blog
  • Posts: 769
  • Joined: 27-June 09

Re: Why is this a good practice?

Posted 13 August 2013 - 01:53 PM

In simple code, it really doesn't matter. In code that has large blocks of commands with very little nesting, left tends to be slightly more readable. When you have so many nested code blocks that compactness becomes a serious issue (in functional languages for example), right is more or less required.
Was This Post Helpful? 0
  • +
  • -

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