Page 2 of 2

Re: Do you use braces?

Posted: Mon Aug 17, 2009 5:16 pm
by Eran
some evil overload imposed some arbitrary standard upon us, crushing our wills, and forcing us to use these unnatural braces
You get that feeling too??

Re: Do you use braces?

Posted: Mon Aug 17, 2009 5:40 pm
by Christopher
:D

Re: Do you use braces?

Posted: Mon Aug 17, 2009 6:16 pm
by jackpf
VirtuosiMedia wrote:The thing that drives me nuts, however, is an opening brace on a separate line.
Opening braces on the same line drive me nuts :P

What looks neater?!?!?

Code: Select all

if($condition)
{
    do_something();
}
//or
if($condition){
do_something();
}
Besides, with bracket matching or whatever, where it draws the line up to the opening/closing bracket, it'll be a straight line for the first (easy to see), whereas it'll be all <span style='color:blue' title='I&#39;m naughty, are you naughty?'>smurf</span> up for the second one.

The only time I use them on the same line is for javascript, which is white-space sensitive. Like:

Code: Select all

return {'something': 'something','something_else': 'something_else'}

Re: Do you use braces?

Posted: Mon Aug 17, 2009 6:23 pm
by John Cartwright
I used to use the compact approach to braces, i.e.,

Code: Select all

if (true) {
   // do something
}
However, that was when vertical screen space was at a premium. Now that any decent monitor will support much larger resolutions, I prefer readability over compactness.

Re: Do you use braces?

Posted: Mon Aug 17, 2009 6:27 pm
by Ollie Saunders
Is the standard better because it's a standard or because it actually mandates a better set of practises? If the standard is truly better by the virtue of it being a standard why should you have to justify the practises of the standard? You should really just say "It's the standard; standards are best." and that would be the end of it. [I'm enjoying that this is opening up into a wider debate that isn't just about bracing but about conformity and opinion within software]. But I'd argue a part of you realises that simply being a standards isn't sufficient defence for one, otherwise, why would you have defended it on other grounds, saying, as you did, "It balances the likes and dislikes of most programmers, trading off density, whitespace, etc."

Standardisation has its benefits, that I acknowledge; and thank you, arborint, for bringing that perspective to the debate. But standards aren't everything, and you know it. In the hypothetical situation where you have something non-standardised that is 70% awesome and something standardised that is 50% awesome, which do you choose? (Imagine that those figures of 70 and 50 were empirically ascertained and indisputable.) It then becomes a measure of how important you think standardisation is.

OK, so how important is standardisation? That's an almost impossible question but I can list some of the things that make standardisation more important:
  • Having to interoperate with other people in your company/clients.
  • Having to interoperate with other development shops.
  • Having to interoperate with potentially anyone (say, with contributors if you're writing a library).
  • Consider the cost of conflicting standards (for builders of aeroplanes and spaceships this cost is massive; inconsistencies might kill).
So, perhaps this is a personal choice as these factors may vary from person to person. As all the PHP I write is written and maintained by me alone the motivation for following standards is small.
I get the sense that there is a belief that some evil overload imposed some arbitrary standard upon us, crushing our wills, and forcing us to use these unnatural braces.
Actually, yeah, that's pretty astute of you. I have discovered that life is full of stupid things that we do to appease the wills of others. And if I can prove to a handful of people that this is the case I feel like I've won a small victory (the ultimate victory being the universal popularisation of my beliefs). Whilst I understand why life is this way I detest that my thinking might be limited by it. History is littered with examples of scientists thinking the unthinkable, being punished for it, and progress being prevented as a result. I like to think our society has matured out of this thinking but it probably hasn't. For many many years I used K&R, as I'm sure most on this forum do, until I realised I could do better and then I felt stupid for conforming so religiously for so long. Quoth Bioshock: "Are you a man or a slave?"
That ignores the years and years that thousands upon thousands of programmers experimented with different brace styles and decided on K&R style braces.
K&R predominates but isn't universally accepted. At best, you could describe the status quo as K&R with addendums, at worst, only a fraction actually practising K&R. As a friend of mine once said, "The great thing about standards is that there are so many of them." As soon as there's more than one standard for something it's not a standard, it's a choice, which defeats the whole point.

Lastly...
Like anything nonstandard, it is brilliant to a the individual who uses it.
This is pretty good to me. There is actually one problem with it that I haven't mentioned yet. But I have taken the time to explain why it is objectively good, not just good to me. So, I hope you don't view this as a complete egofest I actually think this is a better way to brace for programmers who like to take pride in their code.

Re: Do you use braces?

Posted: Mon Aug 17, 2009 6:31 pm
by Ollie Saunders
jackpf wrote:Opening braces on the same line drive me nuts :P

What looks neater?!?!?

Code: Select all

if($condition)
{
    do_something();
}
//or
if($condition){
do_something();
}
That's not a fair comparison because one is indented and the other is not. Also you're missing a space before the brace; these things are important for comparison. Also because it is incredibly difficult to imagine all the possible scenarios for which a good bracing style should handle you do need to look at a reasonable block of code to make good judgements about this.
However, that was when vertical screen space was at a premium. Now that any decent monitor will support much larger resolutions, I prefer readability over compactness.
Hm, that's interesting. I guess that, and font size, could affect someone's interpretation of these things.

Re: Do you use braces?

Posted: Mon Aug 17, 2009 6:33 pm
by jackpf
I agree...

Like you, I'm the only one who maintains my code, so it doesn't really matter what other people think anyway.

Re: Do you use braces?

Posted: Mon Aug 17, 2009 6:39 pm
by Eran

Code: Select all

if (true) {
   // do something
}
I like this style and still use it. I imagine a long diagonal line running from the top brace to the bottom one.. makes me feel there's a higher purpose to it all

interesting tidbit -
Is the standard better because it's a standard or because it actually mandates a better set of practises? If the standard is truly better by the virtue of it being a standard why should you have to justify the practises of the standard? You should really just say "It's the standard; standards are best."
standard count: 7

To all of you who maintain your own code and never have to inter-operate - we solute you. however, when you work as a professional programmer in any significant capacity, following standard is not a privilege - it's a necessity.

Re: Do you use braces?

Posted: Mon Aug 17, 2009 6:44 pm
by Ollie Saunders
standard count: 7
Standard standard standard standard standard standard :-P :mrgreen:
To all of you who maintain your own code and never have to inter-operate - we solute you. however, when you work as a professional programmer in any significant capacity, following standard is not a privilege - it's a necessity.
Yeah, I can't really argue with that. As I said:
In a professional situation, where there is a coding standard to adhere to, I would usually complain little before conforming.

Re: Do you use braces?

Posted: Mon Aug 17, 2009 6:51 pm
by Eran
In a professional situation, where there is a coding standard to adhere to, I would usually complain little before conforming.
oops! missed that with all the standards in there ;)

but yeah, you can understand where we are coming from.

Re: Do you use braces?

Posted: Mon Aug 17, 2009 6:56 pm
by Christopher
Ollie Saunders wrote:Is the standard better because it's a standard or because it actually mandates a better set of practises?
This is exactly the kind of thinking that made me post. The K&R brace standard is not a "mandate", it is the wisdom of years of good programmers working together. It's not best for any one programmer. It has evolved through many years of use and even today it is a formatting style that most groups of PHP programmers choose as the best solution for their group.

My point was that you can talk all you want about how you think your ideas are "objectively good", but that ignores that the standard is a compromise that continues to work -- not some spontaneous idea. Likewise the idea that "scientists thinking the unthinkable" has much application to this mundane convention is silly. Code formatting not on the cutting edge of human knowledge. The whole idea the some brilliant idea is going to change an evolved convention is absurd.

Re: Do you use braces?

Posted: Mon Aug 17, 2009 7:17 pm
by VirtuosiMedia
I'm sure there must be some study somewhere that sheds some objective light on this discussion. I certainly have my personal preferences, but I think the biggest thing that I advocate is consistency, closely followed by readability.

Re: Do you use braces?

Posted: Mon Aug 17, 2009 7:20 pm
by jackpf
This is a good read.

Re: Do you use braces?

Posted: Mon Aug 17, 2009 8:01 pm
by Christopher
VirtuosiMedia wrote:I'm sure there must be some study somewhere that sheds some objective light on this discussion.
As I said, I think trying to be objective about evolved conventions misses the point.
VirtuosiMedia wrote:I certainly have my personal preferences,
Which are fine for personal code.
VirtuosiMedia wrote:but I think the biggest thing that I advocate is consistency, closely followed by readability.
Which are necessary for public code.