RE: PHP Standard style of writing your code

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, April 28, 2006 5:18 pm, Chris W. Parker wrote:
> Richard Lynch <mailto:ceo@xxxxxxxxx>
>     on Monday, April 24, 2006 11:50 PM said:
>
>> So no matter what was actually typed, *I* would see:
>>
>> function foo ($x) {
>>   //body
>> }
>>
>> but some heretic who doesn't know any better would see:
>> function foo($x)
>> {
>>   //body
>> }
>>
>> Now *THAT* would be a feature worth paying for in an IDE! :-)
>
> Setting aside the fact that you're completely wrong about your
> preference... ;)
>
> What, in your mind, is the advantage to putting the opening brace on
> the same line as the function call, logic statement, etc.? (Btw, this
> is a serious question!)

Okay, but let's do keep this fairly serious, and let's NOT let it
devolve into the usual religious flame-war this topic gets to...

Since it IS a religious question, I'm not super-interested in
discussing it with too many go-rounds...


The reasons I chose the brace-on-same-line style, way long time ago:


#1.
Screen real estate and lines of code are fairly precious to me.

Lines wasted for { on a line by itself is just, err, wasteful. :-)

Obviously, some consider that { line by itself useful, but I don't
consider the cost/benefit ratio sufficient to warrant the expense.


#2.
The indentation of the following lines is more than sufficient, with
practice, for the eye to follow the program flow.

An extra line, almost blank, does not make it any easier to "see" the
code flow.

To see this, you have to practice reading both styles in equal
measure, however, and most programmers don't really do that.


#3.
Obviously, whatever one gets used to typing for oneself is the EASIEST
to read.

But if you end up reading a lot of other people's code anyway, you
pretty much have to live with all the different styles.

I'd rather use the more compact style, since I have to be able to read
all of them anyway.


#4.
To me, the brace and what is "going on" in the program at that
juncture are inseparable from the logic that makes the brace
necessary.

I'm not sure how to express this well, but the best I can do is:

The logic and its brace are one and the same, not separate things, and
they should be on the same line because they are one and the same.

The code block body is indented, because it is encompassed by the
program logic, in the sense that the body is either executed or not
based on the logic.

The braces are not something to be executed or not executed, but are
simply delimiters for the code block body.  They are more a part of
the logical structure of the program logic, then they are a part of
the body, because they delimit the structure, rather than get executed
(or not).


#5.
If you print it out on that old-school 3-line alternating green-bar
fan-fold paper, and you hang it up across the room, it's much prettier
as ASCII art with the braces on the same line.

The preceding sentence is obviously a very subjective statement.

But I'm totally serious here -- I made this decision in college circa
1981, and I wrote the same long program both ways, and hung the two
versions up on the wall side-by-side, and I liked the one with { on
the same lines better.

I even solicited my non-programmer roommates' opinions, and they also
preferred the braces on the same line as ASCII art.

The extra practically blank lines version was not as pretty as ASCII
art from a distance.

Note that I (and obviously my roommtes) had no pre-conceived
preference before this ASCII art gallery test.

I daresay an experienced programmer is going to pick the style they
prefer as "prettier."

Though it would be an interesting experiment for some psychology
student to A/B compare with programmers, non-programmers, experienced
programmers, etc...


Well, there it is, fwiw.

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux