/    Sign up×
Community /Pin to ProfileBookmark

Can we ban this syntax from the forum?

Can we ban this syntax from the forum?

[code=php]if(statement):
# …
elseif(statement):
# …
else:
# …
endif;[/code]

to post a comment
PHP

21 Comments(s)

Copy linkTweet thisAlerts:
@pcthugOct 22.2006 — That syntax is still recognized as a completely valid [url=http://au.php.net/manual/en/control-structures.alternative-syntax.php]Alternative syntax for control structures[/url]. Why do you despise it to such a degree?
Copy linkTweet thisAlerts:
@so_is_thisOct 22.2006 — Some people can be such control freeks. :rolleyes:
Copy linkTweet thisAlerts:
@bokehauthorOct 22.2006 — Why do you despise it to such a degree?[/QUOTE]Well it is a remenant left over from before PHP3, its not as clear to read, it contains alien syntax (colons) and it can only serve to make the code harder to read by the majority (more than 99%) that learn the prefered C++ syntax.

In fact doing a search of the PHP forum which presently contains 13860 threads only 30 use that syntax giving it less than 0.2% coverage.
Copy linkTweet thisAlerts:
@pcthugOct 22.2006 — Well as you say, 99% (or 99.8%) of the time C++ style control structures are employed. Therefore, on those rare occasions I would suggest merely ignoring the use of the undesirable control structures and continue as normal.
[list=1]
  • [*]I think it's unnecessary to ban use of completely valid syntax just because of it's unfamiliarity within the community.

  • [*]It would be almost impossible to enforce such a restriction upon members.

  • [/list]
    Copy linkTweet thisAlerts:
    @Brain_StormOct 22.2006 — deleted
    Copy linkTweet thisAlerts:
    @bokehauthorOct 22.2006 — I think it's unnecessary to ban use of completely valid syntax just because of it's unfamiliarity[/QUOTE]Well I used the word "ban" more for a joke to get people to read the thread, I didn't mean it literally, I just thought it would be interesting to know other people's views on this.
    Copy linkTweet thisAlerts:
    @chestertbOct 23.2006 — Personally, I'd like to ban the practice of putting the opening curly braces on the same line as the statement...
    [code=php]if($something==$somethingelse){
    do this
    }[/code]


    is WAY harder to read and debug than
    [code=php]if($something==$somethingelse)
    {
    do this
    }[/code]


    CTB
    Copy linkTweet thisAlerts:
    @bokehauthorOct 23.2006 — Personally, I'd like to ban the practice of putting the opening curly braces on the same line as the statement[/QUOTE]Personally I agree but things are not so simple. Many programers have to format their code in a particular style because their employer's legislation dictates it.
    Copy linkTweet thisAlerts:
    @chestertbOct 23.2006 — because their employer's legislation dictates it[/QUOTE]
    Don't you mean "because the narrow minded bureaucrats who run some IT departments are incapable of adaptation and flexibility"?

    This is what Newton was really talking about in his 3rd law... you remember... "for every action there is an equal and opposite reaction".

    This roughly translates as "for every person with a great idea who wants to make the world a better place, there's an army of self interested, narrow, bloody minded bureaucrats standing in the way with a rulebook".
    Copy linkTweet thisAlerts:
    @so_is_thisOct 23.2006 — Personally I agree but things are not so simple. Many programers have to format their code in a particular style because their employer's legislation dictates it.[/QUOTE]
    Yep, things are not so simple. How about an employer (a programmer) who wants what they call the newer, alternate PHP syntax used because it is easier for them to see where structures start and end? (because of syntax color coding) ...or, how about other narrow-minded programmers who think every other programmer should do things their way? ?
    Copy linkTweet thisAlerts:
    @chestertbOct 23.2006 — Ah yes. 'Tis a complicated, self interested world we live in.
    Copy linkTweet thisAlerts:
    @so_is_thisOct 23.2006 — Now there's a reasonable response. ?

    Salud!
    Copy linkTweet thisAlerts:
    @KorNov 26.2006 — Personally, I'd like to ban the practice of putting the opening curly braces on the same line as the statement...
    [code=php]if($something==$somethingelse){
    do this
    }[/code]


    is WAY harder to read and debug than
    [code=php]if($something==$somethingelse)
    {
    do this
    }[/code]


    CTB[/QUOTE]


    Hm. It is harder to read and debug only if you are not used with. I had the same dilema in javascript and after a while I decided that it does not really matter, an average coder is able to analyse in the same way with the same speed the conditioners/loops/functions like:

    [COLOR=Blue]if(condition){

    statement

    }[/COLOR]


    or like:

    [COLOR=Blue]if(condition)

    {

    statement

    }[/COLOR]


    or even like:

    [COLOR=Blue]if(condition){statement}[/COLOR]

    The second syntax style is recommended for beginers. They are not used very much to read quickly a code. They forget to close the brackets. They loose the code sense when multiple nested conditioners are written. An expeirenced coder needs no longer that "extended" way of coding.

    You see, things goes in the same manner with, let's say, a 2nd Array, or an Object. Why should we code in JSON this way?:

    [COLOR=Blue]var myArray=

    [

    [1,2,3],

    [4,5,6]

    ][/COLOR]


    and not this way?:

    [COLOR=Blue]var myArray=[

    [1,2,3],

    [4,5,6]

    ]

    [/COLOR]


    or even this way?:

    [COLOR=Blue]var myArray=[[1,2,3],[4,5,6]]

    [/COLOR]


    Note that, in fact the last syntax looks more friendly for a beginer, as it is used with the simple arrays like

    [COLOR=Blue]var myArray=[1,2,3];[/COLOR]
    Copy linkTweet thisAlerts:
    @chestertbNov 26.2006 — Kor, you make some good points, and I suppose whatever works for each coder works. Sometimes what you're used to is more important than some convention.

    For me, it's just a matter of making a script as easy to read as I can, not just for me, but for the poor sap who has to come along after me and figure out what on earth I was doing.

    That's why we use, say, indents in html.

    This...
    [code=html]<table>
    <tr>
    <td>Something</td>
    </tr>
    </table>[/code]

    is easier to read, and especially debug, than this...
    [code=html]<table>
    <tr>
    <td>Something</td>
    </tr>
    </table>[/code]

    or even this...
    [code=html]<table><tr>
    <td>Something</td>
    </tr>
    </table>[/code]


    Having the { on the same vertical indent as } just makes more sense to me, in the same way that having a <tr> on the same vertical indent as its opposite </tr> makes sense.

    However, convention, like spoken language, is a funny thing. It changes from time to time, sometimes for better, and other times not. Just which it is remains in the eyes of the beholder.
    Copy linkTweet thisAlerts:
    @Barb54Nov 27.2006 — You guys must really be bored, lol. I'm completely new to PHP/MYSQL and frankly don't give a flying leap how it's written as long as I can somehow manage to disassemble it so I can make some since out of it. Yeeeeeeehaaaaaaa!!!!

    So.......... some REAL help with how the syntax for a FUNCTION should be laid out would help me tremendously since you are all so bored, lol.

    Barb
    Copy linkTweet thisAlerts:
    @chestertbNov 27.2006 — Yup.

    Bored.

    No life.

    Ah well. It's marginally better than TV.

    ?
    Copy linkTweet thisAlerts:
    @so_is_thisNov 27.2006 — So.......... some REAL help with how the syntax for a FUNCTION should be laid out would help me tremendously since you are all so bored, lol.[/QUOTE]
    How much do you need?
    [code=php]
    function MyFunction($arg1, $arg2, etc.)
    {

    ...etc...

    return $some_value;
    }[/code]
    Copy linkTweet thisAlerts:
    @felgallNov 27.2006 — I think that you consistently using one style for the way that you code these constructs it is more important than which of them that you choose. Department heads dictate a particular style of coding such things in order to get everyone in the department to code the same way so that the code looks similar regardless of who wrote it and thus making it easier to maintain.
    Copy linkTweet thisAlerts:
    @so_is_thisNov 27.2006 — A reasonable position.
    Copy linkTweet thisAlerts:
    @SlappyTheFishNov 27.2006 — I must include myself in this when I say that in my experience, programmers are very particular about their own styling and layout of PHP, HTML, etc. I for one can't understand why someone else has a different way of writing code than me yet at the same time I really can't see many advantages of my way over their's.

    I think that in the grand scheme of things there are much more important things to worry about - like does the thing work as it's supposed to. In my department we make great products yet there are still so many things that need improving that we all agree on, so code hair-dressing is fairly close to the bottom of the list. Somewhere along with "empty the bin" and "wash the mugs".
    Copy linkTweet thisAlerts:
    @baseiberNov 27.2006 — My biggest problem with a company's coding style is inconsistancy.

    For example:

    One of the standards for my employer is to have a comment block at the top of each page. The problem is, every couple of months they change what should go into the block and in what order. Should it say "Updates" or "Revisions"? Should the revisions list the date, author, and description horizontally or vertically? Should we include requirement numbers? Should we include variables? How do we describe variables?

    I'm tempted to say, "To Heck with you! I'm gonna display things in a way that makes sense to me."
    ×

    Success!

    Help @bokeh spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.14,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...