Re: How to write code: how wrong am I?

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

 



On Tue, Feb 22, 2011 at 14:15, Marc Guay <marc.guay@xxxxxxxxx> wrote:
> It's an interesting idea (a different take on coding best practices)
> but I find the PHP example to be laborious and time consuming with
> little benefit. ÂIf I'm typing an IF statement, I hope to god I know
> what the condition is before I start typing it. ÂCreating the if/else
> structure first and then filling in the conditions after is a lot of
> cursor-shuffling that could be lived without.
>
>

If the if statement is simple, then I do agree with you. But once
there are nestled functions or conditionals, I like to have the layout
already ready. Consider:

if ( someFunction( someCheck( srrtolower( $_POST["variable"] ) ) ) ){
    // Some Code
}

Now, after the $_POST variable, how many close parentheses does the
code need? This does trip up beginners, especially those who
rightfully learn outside an IDE. Similar situations occur for
something like this (unindented to not overflow email line character
limit):
function someFunction(){
if($something==true){
while($someCondition){
switch($someVariable){
    // Some Code
}
}
}
}

Writing that is fine, but if the user goes in to add another while or
if, he will get lost in the sea of parenthesis. Therefore, I always
close elements before filling them in. It keeps the mind's state
machine saner!

-- 
Dotan Cohen

http://gibberish.co.il
http://what-is-what.com

-- 
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