HGeneAnthony Posted August 18, 2008 Share Posted August 18, 2008 I've been working on developing better coding techniques for awhile now but I don't have all the answers so I was wondering other things you think I should do that I'm currently not doing. 1. I use psuedocode to define the logic of my functions before I write them. Later they work for comments. 2. I stress object oriented techniques and I try to keep my functions small with one central purpose, well labeled, and loose coupled. 3. My classes have strong cohesion 4. I make use of asserts for assumptions I assume to always be correct 5. I use constants for any numbers defined. I keep my code clean of numbers whenever possible. 6. I use an MVC design pattern for my programs 7. I try to make use of Unit testing and Mock objects 8. I'm trying to make more use of debugging but PHP doesn't seem very good for that A couple of things I'd like to learn is how to people profile an application? Are there any good tools for debugging PHP? Any of tips you can think of? Quote Link to comment https://forums.phpfreaks.com/topic/120232-help-with-proper-programming-techniques/ Share on other sites More sharing options...
HGeneAnthony Posted August 18, 2008 Author Share Posted August 18, 2008 I also forgot to mention one technique I heard of was done by ruby on rails where there's 3 projects going on simultaneously a development, test, and distribution along with 3 equally named databases. Does anyone use this method here. Also I use a SVN repository which I use to sync my updates with. Quote Link to comment https://forums.phpfreaks.com/topic/120232-help-with-proper-programming-techniques/#findComment-619376 Share on other sites More sharing options...
Jabop Posted August 18, 2008 Share Posted August 18, 2008 Some projects are good for oop, but most others in my opinion are better developed using the procedural method. Your style seems to be proper though, it appears that you really think about it before you actually do it. Most people don't do that. ;P? Quote Link to comment https://forums.phpfreaks.com/topic/120232-help-with-proper-programming-techniques/#findComment-619384 Share on other sites More sharing options...
nrg_alpha Posted August 18, 2008 Share Posted August 18, 2008 8. I'm trying to make more use of debugging but PHP doesn't seem very good for that One thing that I always do is ensure that errors are always displayed: ini_set('error_reporting', E_ALL | E_STRICT); ini_set('display_errors', 'On'); Google is your friend. Searching for PHP and debugging brings some good results: http://www.ibm.com/developerworks/library/os-debug/ Alos, the IDE of choice makes a difference. You can get PHP specific IDEs like Zend for exmple. http://www.zend.com/en/products/studio/?engine=google&cmpg=Zend_Studio_New&k_id=zend_ide&247SEM So there are some options to help you out in that regard. Cheers, NRG Quote Link to comment https://forums.phpfreaks.com/topic/120232-help-with-proper-programming-techniques/#findComment-619422 Share on other sites More sharing options...
Mchl Posted August 18, 2008 Share Posted August 18, 2008 Xdebug is an interesting php debugging tool. Helps a lot. Quote Link to comment https://forums.phpfreaks.com/topic/120232-help-with-proper-programming-techniques/#findComment-619429 Share on other sites More sharing options...
DeanWhitehouse Posted August 18, 2008 Share Posted August 18, 2008 you dont need to do that bit , ini_set('error_reporting', E_ALL | E_STRICT); As far as i know you just do error_reporting(E_ALL); Quote Link to comment https://forums.phpfreaks.com/topic/120232-help-with-proper-programming-techniques/#findComment-619596 Share on other sites More sharing options...
nrg_alpha Posted August 18, 2008 Share Posted August 18, 2008 Damn.. never realised that lol Quote Link to comment https://forums.phpfreaks.com/topic/120232-help-with-proper-programming-techniques/#findComment-619627 Share on other sites More sharing options...
HGeneAnthony Posted August 18, 2008 Author Share Posted August 18, 2008 Been using Aptana for my PHP. I've been very happy with it. I used to use XDebug I'll have to download that again. Error Reporting is pretty standard though I always leave that on. I tend to be big on doing it right the first time. Experience has taught me that if you put more effort in at the beginning you have less issues down the road and it ends up saving far more time later on. Quote Link to comment https://forums.phpfreaks.com/topic/120232-help-with-proper-programming-techniques/#findComment-619646 Share on other sites More sharing options...
DeanWhitehouse Posted August 18, 2008 Share Posted August 18, 2008 It is best to make your own error reporting for when it's live , so the errors are tidyer. And not just a white screen or something. Quote Link to comment https://forums.phpfreaks.com/topic/120232-help-with-proper-programming-techniques/#findComment-619656 Share on other sites More sharing options...
nrg_alpha Posted August 19, 2008 Share Posted August 19, 2008 It is best to make your own error reporting for when it's live , so the errors are tidyer. And not just a white screen or something. You might not have much choice... Some live hosting servers are configured to not display any error messages at all for security reasons. Quote Link to comment https://forums.phpfreaks.com/topic/120232-help-with-proper-programming-techniques/#findComment-619675 Share on other sites More sharing options...
DeanWhitehouse Posted August 19, 2008 Share Posted August 19, 2008 Yer i mean make your own for everything , e.g. instead of mysql die statements use a custom message , etc. I know i some hosts stop errors, but if they do you should probs contact them or change host. Quote Link to comment https://forums.phpfreaks.com/topic/120232-help-with-proper-programming-techniques/#findComment-619677 Share on other sites More sharing options...
Mchl Posted August 19, 2008 Share Posted August 19, 2008 It is best to make your own error reporting for when it's live , so the errors are tidyer. And not just a white screen or something. You might not have much choice... Some live hosting servers are configured to not display any error messages at all for security reasons. Use exceptions Quote Link to comment https://forums.phpfreaks.com/topic/120232-help-with-proper-programming-techniques/#findComment-619838 Share on other sites More sharing options...
HGeneAnthony Posted August 19, 2008 Author Share Posted August 19, 2008 Another trick I forgot to mention is creating your own Error class that can manage all errors and take different actions based on type. You create variables for type (where the error is user login for example), level (whether it's a user error like unsuccessful login or system error like database not available), message text, where the error occurred (line, file, etc.), etc. Then you can manage message errors by automatically creating log files for system errors or having it email you if you wish. You can use a database to log messages instead if you prefer. A class gives you a lot of flexibility for the future as well. Quote Link to comment https://forums.phpfreaks.com/topic/120232-help-with-proper-programming-techniques/#findComment-619925 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.