PHP Syntax Formatting - Page 2
Page 2 of 6 FirstFirst 1234 ... LastLast
Results 16 to 30 of 85

Thread: PHP Syntax Formatting

  1. #16
    Pedantic Curmudgeon Weedpacket's Avatar
    Join Date
    Aug 2002
    Location
    General Contact Unit "Coping Mechanism"
    Posts
    22,534
    Quote Originally Posted by laserlight
    In our context, this translates to: recommend that users be consistent with a reasonable formatting style when posting, but do not enforce a particular formatting style.
    And if they're posting code in these forums, they should check that what they posted is actually readable. But then I think they should be trying to do that with their English, so what do I know?
    THERE IS AS YET INSUFFICIENT DATA FOR A MEANINGFUL ANSWER
    FAQs! FAQs! FAQs! Most forums have them!
    Search - Debugging 101 - Collected Solutions - General Guidelines - Getting help at all

  2. #17
    Settled 4 red convertible dalecosp's Avatar
    Join Date
    Jul 2002
    Location
    Accelerating Windows at 9.81 m/s....
    Posts
    8,522
    PROBBABLEE NUTHING AT AWL, MEESTER WEEDPOCKET. MABBE U SHULD B A MATH TCEACHER INSTED??
    /!!\ mysql_ is deprecated --- don't use it! Tell your hosting company you will switch if they don't upgrade! /!!!\ ereg() is deprecated --- don't use it!

    dalecosp "God doesn't play dice." --- Einstein "Perl is hardly a paragon of beautiful syntax." --- Weedpacket

    Getting Help at All --- Collected Solutions to Common Problems --- Debugging 101 --- Unanswered Posts --- OMBE: Office Machines, Business Equipment

  3. #18
    Geek
    Join Date
    Jul 2007
    Posts
    780

    !!!! URGENT PROBLEM HELP IMMEDIATTLLLYYYYY !!!!!!!!!!!

    HAY GUISE I HAVE A PROBLEM


    CAN U HALP ME FIX IT PLZ

    YOU CAN EMAIL ME HERE

    THX

  4. #19
    Pedantic Curmudgeon Weedpacket's Avatar
    Join Date
    Aug 2002
    Location
    General Contact Unit "Coping Mechanism"
    Posts
    22,534
    Quote Originally Posted by dalecosp
    MABBE U SHULD B A MATH TCEACHER INSTED??
    You're not the first to suggest that

    Way way way back in high school I asked my maths teacher about career paths in mathematics: like what particular opportunities would open up for me if I went on to get my MSc? His reply: "Maths teacher."
    THERE IS AS YET INSUFFICIENT DATA FOR A MEANINGFUL ANSWER
    FAQs! FAQs! FAQs! Most forums have them!
    Search - Debugging 101 - Collected Solutions - General Guidelines - Getting help at all

  5. #20
    Settled 4 red convertible dalecosp's Avatar
    Join Date
    Jul 2002
    Location
    Accelerating Windows at 9.81 m/s....
    Posts
    8,522
    Quote Originally Posted by Weedpacket
    You're not the first to suggest that

    Way way way back in high school I asked my maths teacher about career paths in mathematics: like what particular opportunities would open up for me if I went on to get my MSc? His reply: "Maths teacher."
    Lol, so, did he know what he was talking about?

    My brother got a BS in Aerospace Engineering, well-timed with the fall of the Berlin Wall, end of the Cold War, Soviet Union breakup and the cancellation of the B-2 bomber. Needless to say, he ended up working outside of aerospace.

    IIRC, night clerk at a motel/steakhouse, then a pothole inspector for the city, now he's their MIS.

    Politics.
    /!!\ mysql_ is deprecated --- don't use it! Tell your hosting company you will switch if they don't upgrade! /!!!\ ereg() is deprecated --- don't use it!

    dalecosp "God doesn't play dice." --- Einstein "Perl is hardly a paragon of beautiful syntax." --- Weedpacket

    Getting Help at All --- Collected Solutions to Common Problems --- Debugging 101 --- Unanswered Posts --- OMBE: Office Machines, Business Equipment

  6. #21
    Senior Member
    Join Date
    Feb 2001
    Location
    Crystal Lake, IL
    Posts
    412
    http://framework.zend.com/manual/en/...-standard.html

    I am astonished this had not been mentioned earlier in this thread.
    PHP Code:
    $footer--; 

  7. #22
    High Energy Magic Dept. NogDog's Avatar
    Join Date
    Aug 2006
    Location
    Ankh-Morpork
    Posts
    14,882
    Quote Originally Posted by lazzerous
    http://framework.zend.com/manual/en/...-standard.html

    I am astonished this had not been mentioned earlier in this thread.
    Why are you astonished? It's not like most of us are creating code for the Zend Framework. For the vast majority of us who are not, it's just YACS (Yet Another Coding Standard).
    "Well done....Consciousness to sarcasm in five seconds!" ~ Terry Pratchett, Night Watch

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

    My Blog
    cwrBlog: simple, no-database PHP blogging framework

  8. #23
    Junior Member
    Join Date
    Aug 2008
    Posts
    11
    I wrote my first two programs for an IBM 1620 in binary -- the prof thought it would be 'instructive' to start with the 'basics'. We then progressed to 'Symbolic' (referred to today as 'assembly'). This was way back in 1963. However, I was so impressed with 'Symbolic' that, even today, I prefer coding at this level since you have your hands directly on the 'control knobs' of the machine, without the obfuscating layers created by the compiler designer(s). The point, for this thread, is that, back then, there were almost NO so-called 'coding standards' beyond those established within coding teams.

    Through the years, I have been paid to code in almost 40 different 'languages' (separately counting the assembly language for each of the different computer systems for which I coded: IBM, Univac, Honeywell, Burroughs, Motorola, Intel, etc.). Looking back, I believe that my current PHP/HTML coding standards are based more on my (rather limited) use of C than on any other language. In this regard, my personal standards conform closely with those recommended by iceomnia (see, above). I wish to emphasize one, especially important, characteristic of the above examples: putting the opening '{' or '(' of control sub-structures on separate lines, aligned immediately below the 1st character of the respective function or conditional. Indeed, I even do this for 'else' conditionals:

    PHP Code:
    if ($condition)
    {
        
    // if true
    }
    else
    {
        
    // if false

    I realize that this is NOT the usual way (which is to leave these as the last character on the function/condition line), but, once you get accustomed to it, it sure facilitates rapid identification of logic boundaries.

    One additional recommendation: to facilitate rapid identification of the closing '}' of a class/function, always add a comment indicating the form and name of that structure:

    PHP Code:
    class foo
    {
        function 
    constructor()
        {
           ; 
    // code
        
    // end function constructor
    // end class foo 
    Remember:
    compared to you, a computer is a very fast, very accurate idiot; whereas,
    compared to a computer, you are a very slow, very inaccurate genius.

    Since the computer could not care less what 'coding standards' you choose, use those 'coding standards' that you, personally, find improve your accuracy. I submit that those same standards will, more likely than not, prove useful to others.

    Of course, opinions are like, uh, noses -- (almost) everyone has one.

  9. #24
    Senior Member iceomnia's Avatar
    Join Date
    Oct 2007
    Posts
    181
    compared to you, a computer is a very fast, very accurate idiot; whereas,
    compared to a computer, you are a very slow, very inaccurate genius.
    Hey, and thanks for your heads up! - I have always been a true believer of, every time one start a new code block one should always use a new currrrrly brace '{'.

    ....

    Thanks for the heads!
    *** Please read this when pasting your code into this website ***

    Here is a great article about Correctly Formatting Your Code to make it easily readable and easier to comment for debugging.

  10. #25
    Pedantic Curmudgeon Weedpacket's Avatar
    Join Date
    Aug 2002
    Location
    General Contact Unit "Coping Mechanism"
    Posts
    22,534
    Quote Originally Posted by icehose
    Since the computer could not care less what 'coding standards' you choose, use those 'coding standards' that you, personally, find improve your accuracy.
    Exactly; the computer puts your source code goes through a lot of mangling before doing anything that it says, and by then you wouldn't want to look at it.
    Last edited by Weedpacket; 04-19-2010 at 06:46 PM.
    THERE IS AS YET INSUFFICIENT DATA FOR A MEANINGFUL ANSWER
    FAQs! FAQs! FAQs! Most forums have them!
    Search - Debugging 101 - Collected Solutions - General Guidelines - Getting help at all

  11. #26
    Yes, I can. Wait, what?
    Join Date
    Dec 2006
    Location
    Dallas, TEXAS!
    Posts
    300
    I'm really starting to like the syntax highlighting and auto-indent in Vim. Mac doesn't ship OS X with those features as default, so it took some digging and googling to get my .vimrc file tweaked.
    When I die, I hope to die like my grandmother did: peacefully, in my sleep.

    Not panic-stricken, screaming in terror like the passengers in her car . . .

  12. #27
    PHP Witch laserlight's Avatar
    Join Date
    Apr 2003
    Location
    Singapore
    Posts
    13,915
    Quote Originally Posted by icehose
    I realize that this is NOT the usual way (which is to leave these as the last character on the function/condition line)
    Actually, the indent style that you prefer is a common style that is sometimes called the Allman style.

    Quote Originally Posted by icehose
    One additional recommendation: to facilitate rapid identification of the closing '}' of a class/function, always add a comment indicating the form and name of that structure:
    I disagree, on the grounds that comments can be incorrectly maintained, so it is best to provide only those comments that are necessary. If a block is so long that such a comment becomes necessary, then perhaps one or more new functions should be introduced (or the block should be shortened in some other way).

    EDIT:
    I suppose that the above reasoning does not apply to a class definition, since there is no way to shorten a class definition other than by reducing the number of member functions and their implementation (but see the "Designing Simple Interfaces" section of The C++ Style Sweet Spot interview with Stroustrup as it applies to PHP). On the other hand, the need for such comments even for class definitions is diminished by the use of proper indentation and code editors with brace matching and code folding capability.
    Last edited by laserlight; 09-29-2008 at 12:25 PM.
    Use Bazaar for your version control system
    Read the PHP Spellbook
    Learn How To Ask Questions The Smart Way

  13. #28
    Personally Humbled Person nrg_alpha's Avatar
    Join Date
    Mar 2008
    Location
    Canada
    Posts
    917
    Quote Originally Posted by NogDog View Post
    Not like the good(?) old days writing BASIC programs on my TRS80 with 4KB of RAM (yes, that is four (4) kilobytes), where every unnecessary space risked making my program too big. And as for comments...who had room for them!
    Oh man! lol.. And here I thought I had it rough progamming on my first computer (Commodore Vic 20 complete with casette drive [can't remember the size of cassettes back then.. but I *think* it was larger than 4kb... not sure about the Vic 20's RAM..I'll have to look that up, just for kicks ).

    On a note with code formatting (rather, cutting and pasting sections of code from Dreamweaver.. if the code snippet in DW is indented (as obviously, we deal with nested divs, for statements, if statements, etc..as such, deeper levels of nested code appears further and further away from the edge of the screen) I find that pasting code from there to these forum message windows does tend to mess up code formatting from the left-hand spacing of the screen edge quite badly.

    I also noticed that if I highlight the indented / nested code, and press SHIFT + TAB (this 'back-tabs' if you will, the code) multiple times till it is right at the start of the screen, copy and paste that, the code shows up more or less quite respectably in the message forum window. This little tip can save some frustrations when dealing with keeping code indented integrity (I know this is not quite the formatting of code that this thread intended.. but it is code formatting none-the-less).

    Cheers,

    NRG

    EDIT - Apprently, my beloved Vic 20 had 5k ram.
    Last edited by nrg_alpha; 10-02-2008 at 11:10 PM.
    "Build a man a fire, you warm him for a day. Set a man on fire, and he'll be warm for the rest of his life."
    ------------------------------------------------------------------------------------------------------
    If preg was a woman, I'd marry her. But I could just see the pattern... she would replace me with someone with money ($1).

  14. #29
    Deviloper ixalmida's Avatar
    Join Date
    Jul 2008
    Location
    Chicago-area
    Posts
    554

    DW formatting

    cutting and pasting sections of code from Dreamweaver..
    I also noticed this. Tab stops in Dreamweaver, regardless of how you've set them, equal about 10 spaces in the forum message window. On the other hand, if you've indented the code yourself (by spacing twice, for example), then it stays the same.

    I'd also agree with previous statements about code formatting. Formatting like this makes me dizzy:
    PHP Code:
    while(($row mysql_fetch_assoc($rs)) != false){
    if((
    $row['Actual_Incentive'] + $row['CSP_Incentive'] + $row['Manual_Adjustment']) < $row['Guarantee_Amount']){
    if(
    $row['GM_Dollar'] >= $row['GM_Quota']){
    $incentive 0;
    $guarantee $row['Guarantee_Amount'];
    }else{
    $incentive $row['Actual_Incentive'] + $row['CSP_Incentive'] + $row['Manual_Adjustment'];
    $guarantee = -1;
    }
    }else{ 
    Etc...That's from another person's code I'm currently dealing with.

    I've come to basically the same formatting standard as mentioned above even though nobody ever told me, "this is the way to do it." The only variation I have is that I like to indent the braces because it "looks" cleaner to me:

    PHP Code:
    while($row mysql_fetch_assoc($rs))
      {
      
    extract($row);
      if(
    $Actual_Incentive $CSP_Incentive $Manual_Adjustment $Guarantee_Amount)
        {
        if(
    $GM_Dollar'] >= $GM_Quota)
          {
          $incentive = 0;
          $guarantee = $Guarantee_Amount;
          }
        else
          {
          $incentive = $Actual_Incentive + $CSP_Incentive + $Manual_Adjustment;
          $guarantee = -1;
          }
        }
      else
        {
        $incentive = $Actual_Incentive + $CSP_Incentive + $Manual_Adjustment;
        $guarantee = 0;
        }
      } 
    The condition/loop statements stick out better - for me at least. But to each his/her own, as long as it is clean.

  15. #30
    Settled 4 red convertible dalecosp's Avatar
    Join Date
    Jul 2002
    Location
    Accelerating Windows at 9.81 m/s....
    Posts
    8,522
    Quote Originally Posted by nrg_alpha View Post
    Oh man! lol.. And here I thought I had it rough progamming on my first computer (Commodore Vic 20 complete with casette drive [can't remember the size of cassettes back then.. but I *think* it was larger than 4kb... not sure about the Vic 20's RAM..I'll have to look that up, just for kicks ).

    On a note with code formatting (rather, cutting and pasting sections of code from Dreamweaver.. if the code snippet in DW is indented (as obviously, we deal with nested divs, for statements, if statements, etc..as such, deeper levels of nested code appears further and further away from the edge of the screen) I find that pasting code from there to these forum message windows does tend to mess up code formatting from the left-hand spacing of the screen edge quite badly.

    I also noticed that if I highlight the indented / nested code, and press SHIFT + TAB (this 'back-tabs' if you will, the code) multiple times till it is right at the start of the screen, copy and paste that, the code shows up more or less quite respectably in the message forum window. This little tip can save some frustrations when dealing with keeping code indented integrity (I know this is not quite the formatting of code that this thread intended.. but it is code formatting none-the-less).

    Cheers,

    NRG

    EDIT - Apprently, my beloved Vic 20 had 5k ram.
    Code:
    PHP Parse Error:  syntax error, unexpected T_STRING in showpost.php on line 7
    Looks like a problem with nested ( ) statements
    /!!\ mysql_ is deprecated --- don't use it! Tell your hosting company you will switch if they don't upgrade! /!!!\ ereg() is deprecated --- don't use it!

    dalecosp "God doesn't play dice." --- Einstein "Perl is hardly a paragon of beautiful syntax." --- Weedpacket

    Getting Help at All --- Collected Solutions to Common Problems --- Debugging 101 --- Unanswered Posts --- OMBE: Office Machines, Business Equipment

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •