Why is this a good practice?

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

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

#16 jon.kiparsky  Icon User is online

  • Pancakes!
  • member icon


Reputation: 7884
  • View blog
  • Posts: 13,400
  • Joined: 19-March 11

Re: Why is this a good practice?

Posted 13 August 2013 - 01:58 PM

There are good arguments for using one style versus another, depending on the language you're using, (always Allman for Java or C, never Allman for Javascript, for example) but it's not worth arguing about in most cases. The most important thing is to use one style for any one codebase, and stick with it. A project should have a style sheet, and sticking to that style sheet is an important part of teamwork.
This covers things where the braces go, it also covers manner of indentation (spaces or tabs? How many spaces to a tab?) and use of whitespace, it covers line length and where you should break lines - basically, you should not be able to tell who write a line based on the way it's formatted. This makes life a lot easier for a collaborative endeavor.
Was This Post Helpful? 0
  • +
  • -

#17 lordofduct  Icon User is online

  • I'm a cheeseburger
  • member icon


Reputation: 2538
  • View blog
  • Posts: 4,639
  • Joined: 24-September 10

Re: Why is this a good practice?

Posted 13 August 2013 - 02:43 PM

View Postandrewsw, on 13 August 2013 - 03:47 PM, said:

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.


Yes that's opinion.

You don't find it more readable.

Others do.

My brain happens to work differently than yours, as it was probably trained with a different background.
Was This Post Helpful? 0
  • +
  • -

#18 jon.kiparsky  Icon User is online

  • Pancakes!
  • member icon


Reputation: 7884
  • View blog
  • Posts: 13,400
  • Joined: 19-March 11

Re: Why is this a good practice?

Posted 13 August 2013 - 03:17 PM

Quote

I don't believe having brackets running down a column is easier to spot matches - our eyes don't work that way />


Actually, it's pretty obvious that lining up open and close braces makes it easier to spot the ones that correspond. Our eyes actually do work that way - things that line up are obviously related. That's more or less graphic design 101, isn't it? That's the basis of spreadsheets, of outlines, and so forth. In fact, that's the whole point of indenting code in the first place! :)


You or some other person might not require that assistance, and prefer to save a few lines here or there, but there's simply no way that you can arrange things in Allman bracing that is not more clear than the equivalent K&R. (as has been stated, the main virtue of K&R is that is saves vertical space - so if you're printing a book or using a 24-line monitor, it's a big help)

(and granted, Allman bracing in JS would be a weird sort of hell that I wouldn't want to visit)
Was This Post Helpful? 0
  • +
  • -

#19 andrewsw  Icon User is online

  • It's just been revoked!
  • member icon

Reputation: 3624
  • View blog
  • Posts: 12,533
  • Joined: 12-December 12

Re: Why is this a good practice?

Posted 13 August 2013 - 03:45 PM

I shall spend the next year on a formal, scientific, investigation. Perhaps I'll get a grant? :smartass:

I shall entitle it: "Quantifying the vertical parallax phenomenon"

This post has been edited by andrewsw: 13 August 2013 - 03:49 PM

Was This Post Helpful? 1
  • +
  • -

#20 jon.kiparsky  Icon User is online

  • Pancakes!
  • member icon


Reputation: 7884
  • View blog
  • Posts: 13,400
  • Joined: 19-March 11

Re: Why is this a good practice?

Posted 13 August 2013 - 03:49 PM

Maybe you could work with Edward Tufte.
Or Piet Mondrian, maybe, if he wasn't dead.

Quote

I shall entitle it: "Quantifying the vertical parallax phenomenon"


Good thing you're not in social sciences. You'd end up with something like "The Eye and the Mind: Orthogonality and Hierarchy in the Construction and Representation of Structured Conceptual Frameworks For Computation"

This post has been edited by jon.kiparsky: 13 August 2013 - 03:55 PM

Was This Post Helpful? 2
  • +
  • -

#21 andrewsw  Icon User is online

  • It's just been revoked!
  • member icon

Reputation: 3624
  • View blog
  • Posts: 12,533
  • Joined: 12-December 12

Re: Why is this a good practice?

Posted 13 August 2013 - 03:55 PM

I understand that Tufte's book The Visual Display of Quantitative Information is a classic, and considered essential reading in a number of disciplines.

This post has been edited by andrewsw: 13 August 2013 - 03:58 PM

Was This Post Helpful? 0
  • +
  • -

#22 jon.kiparsky  Icon User is online

  • Pancakes!
  • member icon


Reputation: 7884
  • View blog
  • Posts: 13,400
  • Joined: 19-March 11

Re: Why is this a good practice?

Posted 13 August 2013 - 03:57 PM

It's great - I disagree with him on many points, but he makes a persuasive case, and really makes you think about the issues of clean design for communication.

If you can, get your boss to send you to one of his workshops - they're supposed to be great, and your boss can usually find some tax advantage in sending you to them.
Was This Post Helpful? 0
  • +
  • -

#23 DblAAssassin  Icon User is online

  • D.I.C Regular

Reputation: 33
  • View blog
  • Posts: 259
  • Joined: 11-May 13

Re: Why is this a good practice?

Posted 13 August 2013 - 03:59 PM

I'm a rightie (K&R), I find it way easier to read in large programs, I was the same way when I programmed C. That is also how I do it now in Javascript.
Was This Post Helpful? 0
  • +
  • -

#24 andrewsw  Icon User is online

  • It's just been revoked!
  • member icon

Reputation: 3624
  • View blog
  • Posts: 12,533
  • Joined: 12-December 12

Re: Why is this a good practice?

Posted 13 August 2013 - 04:03 PM

View Postjon.kiparsky, on 13 August 2013 - 10:57 PM, said:

It's great - I disagree with him on many points, but he makes a persuasive case, and really makes you think about the issues of clean design for communication.

If you can, get your boss to send you to one of his workshops - they're supposed to be great, and your boss can usually find some tax advantage in sending you to them.

Boss would have to pay for the flight as well :balloon:
Was This Post Helpful? 0
  • +
  • -

#25 jon.kiparsky  Icon User is online

  • Pancakes!
  • member icon


Reputation: 7884
  • View blog
  • Posts: 13,400
  • Joined: 19-March 11

Re: Why is this a good practice?

Posted 13 August 2013 - 04:12 PM

Well, your boss obviously need to work on generosity. This is a good place to start.
Was This Post Helpful? 0
  • +
  • -

#26 cfoley  Icon User is offline

  • Cabbage
  • member icon

Reputation: 2045
  • View blog
  • Posts: 4,233
  • Joined: 11-December 07

Re: Why is this a good practice?

Posted 13 August 2013 - 05:18 PM

Nobody seems to have noticed that the closing brace lines up with the if statement for righties (and lefties too, I guess). And silly bugs are possible if you're a leftie. You won't catch a rightie making this embarrassing mistake.

if (isReallySure)
System.out.println("Starting sprinklers."); // line added later
{
	activateSprinklerSystem();
}


If we like visual cues, why not:

if (isReallySure)
{
	for(Floor f : building)
	{{
		for(Room r : f)
		{{{
			for(Sprinkler s : r) 
			{{{{
				s.start();
			}}}}
		}}}
	}}
}


We can make this easier to read by formatting it as one would in lisp

if (isReallySure) {for(Floor f : building) {{for(
                                                 Room r : 
                                                 f){{{for(
                                                 	      Sprinkler s : 
                                                 	      r) {{{{
                                                 	             s.start();}}}}}}}}}}

Was This Post Helpful? 1
  • +
  • -

#27 lordofduct  Icon User is online

  • I'm a cheeseburger
  • member icon


Reputation: 2538
  • View blog
  • Posts: 4,639
  • Joined: 24-September 10

Re: Why is this a good practice?

Posted 13 August 2013 - 08:48 PM

View Postcfoley, on 13 August 2013 - 07:18 PM, said:

Nobody seems to have noticed that the closing brace lines up with the if statement for righties (and lefties too, I guess). And silly bugs are possible if you're a leftie. You won't catch a rightie making this embarrassing mistake.

if (isReallySure)
System.out.println("Starting sprinklers."); // line added later
{
	activateSprinklerSystem();
}


If that's your argument against leftie, it's a pretty shit argument.

I don't even see why you need to make an argument against it. It's just a preference.
Was This Post Helpful? 0
  • +
  • -

#28 cfoley  Icon User is offline

  • Cabbage
  • member icon

Reputation: 2045
  • View blog
  • Posts: 4,233
  • Joined: 11-December 07

Re: Why is this a good practice?

Posted 13 August 2013 - 11:06 PM

Well it's a good thing you took my serious post seriously.

:P
Was This Post Helpful? 2
  • +
  • -

#29 jon.kiparsky  Icon User is online

  • Pancakes!
  • member icon


Reputation: 7884
  • View blog
  • Posts: 13,400
  • Joined: 19-March 11

Re: Why is this a good practice?

Posted 13 August 2013 - 11:42 PM

Is it too late for me to flame you for wanting to format Java as if it were lisp? 'Cause I was totally going to do that.
Was This Post Helpful? 2
  • +
  • -

#30 cfoley  Icon User is offline

  • Cabbage
  • member icon

Reputation: 2045
  • View blog
  • Posts: 4,233
  • Joined: 11-December 07

Re: Why is this a good practice?

Posted 14 August 2013 - 01:08 AM

Are you crazy enough to reconfigure your code formatter?
Was This Post Helpful? 0
  • +
  • -

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