Jump to content

Coding Standard


Bryce910

Recommended Posts

Well I mean personally I code using my own style. But I have been told by many more experienced people that  I need to use a public coding style like how pear has certain ways of doing the coding (line length,bracket placement, ..etc). So I was wondering if you guys have any suggestions other then PEAR.

Link to comment
Share on other sites

There isn't a definite answer, just keep to what ever you feel most comfortable with. As others have said, just make sure you keep to the same style the whole way through your application.

 

I always do if's like this:

<?php
  if($this == $that){
    //Stuff
  }
?>

 

And variables/classes/functions

<?php
  $a_variable = "something";
  function underscore_delimited(){
    //stuff
  }
?>

 

Sometimes I get so stuck in that way that it hurts when I see it different, and if I have copy'd some code from somewhere I have to indent it and style it the way I'm used to.

 

Something I don't like but sometimes have to do, is perform a query on separate lines because it is too long, or extend a function with too many parameters on to separate lines. But once again there is nothing wrong with that

Link to comment
Share on other sites

Something I don't like but sometimes have to do, is perform a query on separate lines because it is too long, or extend a function with too many parameters on to separate lines. But once again there is nothing wrong with that

 

The function parameters on separate lines bugs me too, but I almost always split queries up. Unless you are doing something like SELECT * FROM table, they seem to always be way too long to be readable. I tend to break it up on every keyword, and separate selected columns by table. For example...

 

SELECT t1.first_name, t1.last_name, t1.email,
       t2.age, t2.gender, t2.location	   
FROM table1 t1
LEFT JOIN table2 t2 ON t2.id = t1.id
WHERE t1.first_name = 'John'

Link to comment
Share on other sites

I started in AS2/3 so I tend to use those conventions; camelCase for most variables, prepending $_variable for private or local vars, STATIC_VARS_UPPERCASE, Classes beginning with an uppercase letter.

 

Just watch out you don't use camelCase when you're naming your mysql tables or you might be in for a surprise  ::)

Link to comment
Share on other sites

What I started doing very late was comment my own code.

I never bothered first since I was working on it all by myself most of the time but I realized later that when you want to reuse parts of your code six months later it's going to be hard to figure out what does what.

Other than that - consistency is key.

Even if it's an easy rule to accidentally break.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.