|
Posted by Jerry Stuckle on 04/18/07 22:31
Rami Elomaa wrote:
> Steve kirjoitti:
>> "Rami Elomaa" <rami.elomaa@gmail.com> wrote in message
>> news:f05c10$2tq$1@nyytiset.pp.htv.fi...
>> | Steve kirjoitti:
>> | > "Rami Elomaa" <rami.elomaa@gmail.com> wrote in message
>> | > news:vNkVh.38543$8H5.25109@reader1.news.saunalahti.fi...
>> | > | "Toby A Inkster" <usenet200703@tobyinkster.co.uk> wrote in message
>> | > | news:v1ugf4-9qv.ln1@ophelia.g5n.co.uk...
>> | > | > Rami Elomaa wrote:
>> | > | >
>> | > | >> <?php
>> | > | >> $i++;
>> | > | >> if($i<10) xyz (__FILE__) ;
>> | > | >> else echo $i;
>> | > | >> ?>
>> | > | >>
>> | > | >> Substitute xyz with a standard function or construct so that
>> the output
>> | > | >> is 10.
>> | > | >
>> | > | > My immediate thought would be...
>> | > | >
>> | > | > <?php
>> | > | > $i++;
>> | > | > if($i<10) echo
>> preg_replace('/[^\d]/','',file_get_contents(__FILE__));
>> | > | > else echo $i;
>> | > | > ?>
>> | > | >
>> | > |
>> | > |
>> | > | Well, that's quite a brilliant solution, but the goal was to use
>> one and
>> | > | only one function substituting xyz, but you've used three. This
>> was my
>> | > fault
>> | > | since I couldn't describe the task correctly. English isn't my
>> native
>> | > | language and it was late in the evening... Let me try to
>> rephrase the
>> | > | question:
>> | > |
>> | > | <?php
>> | > | $i++;
>> | > | if($i<=9)
>> | > | xyz (__FILE__) ;
>> | > | else
>> | > | echo $i;
>> | > | ?>
>> | >
>> | > rami, you've REALLY got to work on your single line if/else
>> formatting.
>> | >
>> |
>> | Please show me the correct formatting. I tried two combinations which
>> | both seem to me ok and understandable, and you've banned both of them.
>> | I'm all out of ideas. It would be REALLY helpful if you could point out
>> | what is wrong with these and secondly what is the correct way. What
>> am I
>> | supposed to do?
>>
>> do as you will, i believe though that the standard practice is to
>> include brackets to clearly show the body block rather than just
>> leaving that to indentions.
>
> Brackets schmackets. If it's a single statement I've never felt any
> guilt of leaving out the brackets. I agree that the first piece of code
> I posted was not the best possible since the entire if and alse clauses
> were on a single line. However the second one I posted is just as good
> as any other. With or without the extra spacing. They aren't that
> important, you know... We're programmers, not women!
>
>> this is especially true when multiple if/else if/else statements are
>> combined. ex.
>>
>> if ($i <= 9)
>> {
>> xyz (__FILE__);
>> } else {
>> echo $i;
>> }
>>
>> that makes the 'if' stand out clearly as well as the operations being
>> performed for each condition checked. also note the space between 'if'
>> and '(' . 'if' is not a function. notice the space on either side of
>> '<=' . the space makes it easier to see/read the variable, the
>> condition, and the value being evaluated.
>>
>> i'm not ragging on you,
>
> Oh, but you are. Come now, you could've easily revealed the "correct"
> formatting right away and we wouldn't be having this stupid conversation
> anyway. But no, you just wanted to see me try again and fail, and beg
> you to reveal the correct answer.
>
>> but these points make it easier to manage code.
>
> Bollocks. It's just that you're used to something and I'm used to
> something else. I do admit the first case was shitty, but really, how
> dare you mock my second example? There was nothing wrong with it, period.
>
> Okay, I'm a stupid asshole who can't format his code and can't take any
> criticism. Fine, I'm okay with that. I'm sorry if I've ruined everyone's
> day now.
>
Rami,
I normally don't use braces (brackets are the square things - '[]') for
a single statement, either, and not a lot of programmers I know do.
It's optional - either way is fine. The important thing is to format
your code so that it's easily readable by others.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Navigation:
[Reply to this message]
|