Weedpacket wrote:

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.

    3 months later
    lazzerous wrote:

    http://framework.zend.com/manual/en/coding-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). 😉

      3 months later

      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:

      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:

      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.

        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!

          icehose wrote:

          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.

            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.

              icehose wrote:

              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.

              icehose wrote:

              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.

                NogDog;10856788 wrote:

                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.

                  3 months later

                  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:

                  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:

                  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.

                    nrg_alpha;10888405 wrote:

                    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.

                    PHP Parse Error:  syntax error, unexpected T_STRING in showpost.php on line 7

                    Looks like a problem with nested ( ) statements 😃

                      PHP Parse Error: syntax error, unexpected T_STRING in showpost.php on line 7

                      -- Haha!

                      I was poking around today and found out that there are actually names for the styles we are talking about! My style is called "Whitesmiths" as opposed to the "GNU/Pear" style that others here have mentioned.

                      If formatting your code is just too much trouble for you, try this site: PHP Formatter

                      You can paste your code into the window, select your preferred style, and click a button and it will make your code all pretty for you. Pretty cool...

                        I just type Ctrl-F in my editor and it does it for me.

                          ixalmida wrote:

                          You can paste your code into the window, select your preferred style, and click a button and it will make your code all pretty for you. Pretty cool...

                          If you don't keep your code formatted while you're writing it - pretty much on every line you write as you write it - you're missing a big chunk of the reason why you should be formatting it.

                          Using that site every time you type a line seems like a little too much trouble 🙂

                            Using that site every time you type a line seems like a little too much trouble

                            Agreed. However, if you're having to fix someone else's code the site can be really helpful.

                            I inherited a mission-critical site. The previous developer wasn't really a developer. Not only did he not format his code, but he used modular pages (not to be confused with OOP), so it is impossible to change something without potentially affecting a bunch of other pages.

                            For example, the main index page loads 6 different modules (layed out with Javascript), and those modules reference or load other modules based on a user's access level. When you click a link, it loads a new module not a new page.

                            It gets complicated very quickly and there is NO documentation. It is also very slow in places, doesn't take advantage of CSS ,and is difficult to optimize. So I'm pretty much looking at rebuilding from scratch a financial site that took 3 years to build.

                            (Sorry folks, just had to vent a little!)

                            I just type Ctrl-F in my editor and it does it for me.

                            Okay...could you enlighten us on what editor you're using? Ctrl-F is mapped to the "find" function in every editor I'm aware of.

                              ixalmida;10898812 wrote:

                              ...
                              Okay...could you enlighten us on what editor you're using? Ctrl-F is mapped to the "find" function in every editor I'm aware of.

                              Oops, should've been "Ctrl-Shift-F".

                              phpDesigner is the editor/IDE. I don't remember if that was the default key-mapping for the format command or if I overrode it at some point. Aptana has a similar function, so I wouldn't be surprised if some of the other Eclipse-based IDE's also do.

                                NogDog wrote:

                                Aptana has a similar function, so I wouldn't be surprised if some of the other Eclipse-based IDE's also do.

                                You'd be right; the same keybinding is the default in Zend Eclipse and Eclipse itself.

                                  4 months later

                                  In relation to my previous post back in 2008 regarding correctly spacing your code to make it eaasily readable, I have found many articles supporting my recommendation for using in the Allman Style syntax formatting.

                                  This is where the main rules are that each new curly brace goes on a new line.

                                  I have also found this on expressionengine.com about general syntax formatting.

                                  I particularly like this syntax style as it makes it incredibly easy to comment out braces to enable certain flow.

                                  Allman style (bsd in Emacs)

                                  Any views, comments, agreements, disagreements?

                                    iceomnia wrote:

                                    I have found many articles supporting my recommendation for using in the Allman Style syntax formatting.

                                    If you have not found many articles supporting other indent styles, then either you have not searched hard enough, or the supporters are too busy coding to evangelise 😉

                                    iceomnia wrote:

                                    I have also found this on expressionengine.com about general syntax formatting.

                                    So what? That is just a style guideline that I am not required to follow :p

                                    iceomnia wrote:

                                    I particularly like this syntax style as it makes it incredibly easy to comment out braces to enable certain flow.

                                    That sounds dubious: why would you be commenting out braces?

                                    I like it for a different reason, related to one cited by the "Technical Spartacus" blog that you linked to: I would rather not extend code horizontally, so I try to break to a new line after about the 80th column. This new line of code would then be indented by one level. Without the opening brace being on its own line, there would then be no visual cue as to the difference between the continuation of the previous line of a control statement and the first line of the block. (But note that some style guidelines suggest a two level indentation for continuation lines instead, in which case this "problem" would no longer apply. But I dislike the extra level of indentation.)

                                    Of course, I disagree with Spartacus' implication that the Allman style is the "correct" indent style.