Jump to content

Help with proper programming techniques


HGeneAnthony

Recommended Posts

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 ;)

Link to comment
Share on other sites

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.

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.