Bryce910 Posted April 27, 2012 Share Posted April 27, 2012 I am looking to finally move to a popular coding style. Anyone know any great ones I should look into? So far I have looked into PEAR. Thanks! Quote Link to comment Share on other sites More sharing options...
scootstah Posted April 27, 2012 Share Posted April 27, 2012 Regarding what exactly? Quote Link to comment Share on other sites More sharing options...
Bryce910 Posted April 27, 2012 Author Share Posted April 27, 2012 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. Quote Link to comment Share on other sites More sharing options...
Jessica Posted April 27, 2012 Share Posted April 27, 2012 Just be consistent with all your standards. Don't switch from camelCase to underscore_separation and if you put your brackets on the same lines as if(), do it for every single one, not half of them. Quote Link to comment Share on other sites More sharing options...
scootstah Posted April 27, 2012 Share Posted April 27, 2012 There's a lot of styles, all of them are perfectly valid. It is a personal preference after all. The main thing is consistency. PEAR and Zend are probably the most popular. Quote Link to comment Share on other sites More sharing options...
Zephni Posted April 27, 2012 Share Posted April 27, 2012 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 Quote Link to comment Share on other sites More sharing options...
scootstah Posted April 27, 2012 Share Posted April 27, 2012 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' Quote Link to comment Share on other sites More sharing options...
jstrike Posted April 27, 2012 Share Posted April 27, 2012 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 Quote Link to comment Share on other sites More sharing options...
El Chupacodra Posted April 27, 2012 Share Posted April 27, 2012 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.