Re: Do you use braces?
Posted: Mon Aug 17, 2009 5:16 pm
You get that feeling too??some evil overload imposed some arbitrary standard upon us, crushing our wills, and forcing us to use these unnatural braces
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
You get that feeling too??some evil overload imposed some arbitrary standard upon us, crushing our wills, and forcing us to use these unnatural braces
Opening braces on the same line drive me nutsVirtuosiMedia wrote:The thing that drives me nuts, however, is an opening brace on a separate line.
Code: Select all
if($condition)
{
do_something();
}
//or
if($condition){
do_something();
}Code: Select all
return {'something': 'something','something_else': 'something_else'}Code: Select all
if (true) {
// do something
}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?"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.
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.That ignores the years and years that thousands upon thousands of programmers experimented with different brace styles and decided on K&R style braces.
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.Like anything nonstandard, it is brilliant to a the individual who uses it.
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.jackpf wrote:Opening braces on the same line drive me nuts
What looks neater?!?!?
Code: Select all
if($condition) { do_something(); } //or if($condition){ do_something(); }
Hm, that's interesting. I guess that, and font size, could affect someone's interpretation of these things.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.
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 allCode: Select all
if (true) { // do something }
standard count: 7Is 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 standard standard standard standard standardstandard count: 7
Yeah, I can't really argue with that. As I said: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.
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 thereIn a professional situation, where there is a coding standard to adhere to, I would usually complain little before conforming.
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.Ollie Saunders wrote:Is the standard better because it's a standard or because it actually mandates a better set of practises?
As I said, I think trying to be objective about evolved conventions misses the point.VirtuosiMedia wrote:I'm sure there must be some study somewhere that sheds some objective light on this discussion.
Which are fine for personal code.VirtuosiMedia wrote:I certainly have my personal preferences,
Which are necessary for public code.VirtuosiMedia wrote:but I think the biggest thing that I advocate is consistency, closely followed by readability.