jwilson122 Posted October 27, 2010 Share Posted October 27, 2010 Hey, I was hoping someone can help me with some advice to keeping my code clean, secure, and easy to read but yet have the most power... any tips or advice for me? Quote Link to comment Share on other sites More sharing options...
salathe Posted October 27, 2010 Share Posted October 27, 2010 Just bear in mind that a) clean, b) secure, c) easy to read, and d) powerful might not play well together. Are you having any particular problems with any of those topics or have you just heard that your code should have those attributes and you want to fit in and be cool? Quote Link to comment Share on other sites More sharing options...
jwilson122 Posted October 27, 2010 Author Share Posted October 27, 2010 Just bear in mind that a) clean, b) secure, c) easy to read, and d) powerful might not play well together. Are you having any particular problems with any of those topics or have you just heard that your code should have those attributes and you want to fit in and be cool? not really... but why cant secure, clean code be powerful? Quote Link to comment Share on other sites More sharing options...
salathe Posted October 27, 2010 Share Posted October 27, 2010 So you're not having any particular problems, and you're not trying to be cool. What do you want? Quote Link to comment Share on other sites More sharing options...
jwilson122 Posted October 27, 2010 Author Share Posted October 27, 2010 So you're not having any particular problems, and you're not trying to be cool. What do you want? Um?? not trying to be "cool"? LOL.. Dude, I'm cooler than you, and im also calm too bro! BUT, My question was, for tips and advice on creating clean, secure code. Quote Link to comment Share on other sites More sharing options...
Anti-Moronic Posted October 27, 2010 Share Posted October 27, 2010 Just bear in mind that a) clean, b) secure, c) easy to read, and d) powerful might not play well together. Are you having any particular problems with any of those topics or have you just heard that your code should have those attributes and you want to fit in and be cool? ?? Maybe he should do what the rest do and completely ignore the quality of his work and get on with it. You should be very receptive to people who are trying to become better developers - that's what this forum is all about. wilson, what you're looking for is php best practices. Search in google, there are tons of websites about this. Then, search on each specific item again to validate cause just in case. Here are a few links: http://pear.php.net/manual/en/standards.bestpractices.php http://cyrilmazur.com/2010/10/proposal-best-practices-for-writing-php.html In fact, here's the search link: http://www.google.co.uk/search?q=php+best+practices+readability&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-GB:official&client=firefox-a Some excellent links there. Got me fired up now to do some improving! Keep it cool. Quote Link to comment Share on other sites More sharing options...
Anti-Moronic Posted October 27, 2010 Share Posted October 27, 2010 On the power of your code, I'd definitely suggest you start learning a framework. My fave is Zend, but I've heard good things about Symphony and CodeIgniter. Quote Link to comment Share on other sites More sharing options...
Maq Posted October 27, 2010 Share Posted October 27, 2010 Firstly, this is such a broad question and cannot possibly be answered in a single reply. Secondly, the OP should have Googled and came back with specific questions. @OP, if you have specific questions we don't mind helping, after all, that's why we're here. Quote Link to comment Share on other sites More sharing options...
jwilson122 Posted October 27, 2010 Author Share Posted October 27, 2010 Thanks a lot Anti-Moronic! Will take a look at your links. Firstly, this is such a broad question and cannot possibly be answered in a single reply. Secondly, the OP should have Googled and came back with specific questions. @OP, if you have specific questions we don't mind helping, after all, that's why we're here. Well, I dont have any So can you be helpful and tell me tricks and techniques you do? Thats ALL I want! Quote Link to comment Share on other sites More sharing options...
jimmyt1988 Posted October 27, 2010 Share Posted October 27, 2010 Indenting and spacing: $var = 0; for($i = 0; $i <= 100; $i++){ $var++; echo $var; } Realising the best way of doing something if($var==0){ echo "boo"; }elseif($var == 1){ echo "bies"; }elseif($var == 2){ echo "are"; }elseif($var == 3){ echo "always"; }elseif($var == 4){ echo "fun"; }elseif($var == 5){ echo "to"; }else($var == 6){ echo "squeeze"; } Can be changed to: switch($var){ case 0: echo "boo"; break; case 1: echo "bies"; break; case 2: echo "are"; break; case 3: echo "always"; break; case 4: echo "fun"; break; case 5: echo "to"; break; default: echo "squeeze"; } Learning different ways to structure code in your head: function do(){ function this(){ echo "this"; } function that(){ echo "that"; } } that(); can be layed out like: class do{ public $this = "this"; public $that = "that"; public function this(){ echo $this->this; } public function that(){ echo $this->that; } } $do = new do(); $do->that(); Lots more.. Looking at how others lay their code out is always a good start. In a job, commenting is a MUST. so always comment your stuff really clearly. Also use full words rather than abbreviations a - z lol. Quote Link to comment Share on other sites More sharing options...
jwilson122 Posted October 27, 2010 Author Share Posted October 27, 2010 Thanks jimmyt1988, however the boobies are always fun to squeeze was unnecessary. Thanks though! Anyone else? Quote Link to comment Share on other sites More sharing options...
jimmyt1988 Posted October 27, 2010 Share Posted October 27, 2010 Quote Link to comment Share on other sites More sharing options...
Anti-Moronic Posted October 27, 2010 Share Posted October 27, 2010 God point made above. I'd certainly suggest you download some highly regarded opensource frameworks/apps and read the code. Look at the readability - but more importantly try to understand some of the advanced abstract methods. It can be a real eye opener and if you analyze modern frameworks/apps, you'll learn modern techniques! To be honest, I'm very surprised there isn't a sticky here for this kind of thing. Solving other people's problems is one thing, but teaching them how to be better developers can only make all our lives better. More from that search list: http://www.phpvs.net/2008/06/04/ten-php-best-practices-tips-that-will-get-you-a-job/ http://www.mikebernat.com/blog/My_PHP_Best_Practices http://www.odi.ch/prog/design/php/guide.php Another great idea is to find amateur code and try to improve it to the best of your ability. Make it more readable, more abstract and flexible (search DNR or DIE principle), less lines, faster, whatever. It will truly help you become a better programmer...and *always* search google if you want to know if php can do _____ and how ____ THEN check the manual for ______. Hope that helps! I'm not sure how far into php you are, but it's start to get really really addictive about a month or two in. Quote Link to comment Share on other sites More sharing options...
Anti-Moronic Posted October 27, 2010 Share Posted October 27, 2010 Thanks jimmyt1988, however the boobies are always fun to squeeze was unnecessary. Thanks though! Anyone else? But boobies are fun to squeeze. I thought you were cool? Hey...ur not pulling our collective leg are you? Quote Link to comment Share on other sites More sharing options...
jimmyt1988 Posted October 27, 2010 Share Posted October 27, 2010 function cool($user){ switch ($user){ case "jwilson122": return false; break; default: return true; } } cool($aboveContext); Quote Link to comment Share on other sites More sharing options...
jwilson122 Posted October 27, 2010 Author Share Posted October 27, 2010 LOL @ that code jimmy, and for Anti-Moronic, nah, just messin Quote Link to comment Share on other sites More sharing options...
salathe Posted October 28, 2010 Share Posted October 28, 2010 The code snippets posted by jimmyt1988 can hardly be considered the cleanest way to do things, nor "best practices". I'd love to go into depth on one or more subjects that the OP might like to know more about, but can see the dangers already (from posts above) that he might very well take what is said as "gospel" and not take the time to learn the subject. Quote Link to comment Share on other sites More sharing options...
jimmyt1988 Posted October 28, 2010 Share Posted October 28, 2010 Quote Link to comment Share on other sites More sharing options...
Maq Posted October 28, 2010 Share Posted October 28, 2010 Thanks a lot Anti-Moronic! Will take a look at your links. Firstly, this is such a broad question and cannot possibly be answered in a single reply. Secondly, the OP should have Googled and came back with specific questions. @OP, if you have specific questions we don't mind helping, after all, that's why we're here. Well, I dont have any So can you be helpful and tell me tricks and techniques you do? Thats ALL I want! Then you haven't put any time or research into your own question. If you have, then I'm sure you would have plenty of questions. The only advice I can give you is that PHP doesn't have a set standard for code formatting or indenting, so be consistent and, if using a framework, use their style. Quote Link to comment Share on other sites More sharing options...
jwilson122 Posted October 28, 2010 Author Share Posted October 28, 2010 Lol okay well, thanks and good point @ salathe! If you could please show me your style, that would be great @Maq, well 1. I don't use any frameworks since I develop sites for people freelancing. So, I'm asking others to show me code sniplets if they could.. my code needs to be clean enough another programmer can edit it since my customers gets the script. Anyways, thanks for your help! Anyone else, if you can provide me with code sniplets or something, it would be great! Thanks tons. Quote Link to comment Share on other sites More sharing options...
Anti-Moronic Posted October 28, 2010 Share Posted October 28, 2010 I'm a freelancer and frequently use frameworks. You'll find the more high paying clients and projects (i.e. $3000+) expect you to work with a well designed framework and design pattern. Whether that be your own or otherwise. Because they might then hire other people to amend later, it is usually required that you develop using a framework. What's the use in using your own framework if somebody had to learn it..there are plenty of frameworks out there which are maintained and studied by tons of professionals. Far more than your own framework can attract. If you want to see code snippets - check the other threads or look at anybody's profile here and check their latest posts. Should be plenty of snippets. First though, I'd advise you read *every* link I sent before. There is a link which shows you how to make your code more readable and maintainable. Quote Link to comment Share on other sites More sharing options...
Maq Posted October 28, 2010 Share Posted October 28, 2010 Anyone else, if you can provide me with code sniplets or something, it would be great! Thanks tons. http://www.php.net Quote Link to comment Share on other sites More sharing options...
jwilson122 Posted October 28, 2010 Author Share Posted October 28, 2010 Okay cool, Lol.... I know of php.net bro Quote Link to comment Share on other sites More sharing options...
Maq Posted October 28, 2010 Share Posted October 28, 2010 Okay cool, Lol.... I know of php.net bro You asked for code snippets, so there you go, from the official source brah. Quote Link to comment Share on other sites More sharing options...
jwilson122 Posted October 28, 2010 Author Share Posted October 28, 2010 Okay cool, Lol.... I know of php.net bro You asked for code snippets, so there you go, from the official source brah. LOL, Very true! Cant say I didn't 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.