Recently i was reading an article from Hasin bhai,
which is titled “Just PHP will give you nothing, unless you upgrade yourself”
here is my comment on hasin bhai’s post
wow hasin bhai, nice write up.
Bro i wanna add up few topics which are leaking in most of the php developers. i belief most of the PHP developers are producing dirty fast code (not 30th first night ;)) it is because of the following reasons:
(my suggestion are enclosed with in ‘–>’ context)
1. less concentration of DRY (Don’t Repeat Yourself)
–> Create each fragment as reusable module (for example: latest_comments.php, latest_user.php, latest_news.php etc..)
2. Search those code which u have written more than once
–> Separate them. (keep them in separate reusable file)
3. Keep your business logic away from presentation layer
–> you don’t need to follow any strict design pattern like MVC, MVP. just plain solution is enough. Use php class to manage your business rules.
4. Use any good framework, it doesn’t mean you have to use java or Ruby on rails like framework. Better go for simple and productive framework.
5. Use library from trusted parties (hope zend is growing up its huge libraries on many aspect), PEAR is obviously great choice.
6. Don’t think all running web application is 100% accurate, and never ever grab their design and code. Better use your own sense and create a colorful stuff… meet your own client requirements.
7. Don’t mix up PHP with java or these kinda technologies
–> The way php works and the way Java works are not same, and better not compare both. Never ever try to implement all design patterns which are successful on Java EE platform. PHP is great for its simplicity. Java is great for its complexity.
8. Go for better object orientation, but it doesn’t mean you have to restrict everything with in a bunch of classes.
–> PHP is not intended to develop for this purpose. Rather follow php related performance tuning stuff.
9. Always keep your data access layer separate from raw or presentational php coding
10. Always go through open source projects, where you can learn how big projects are managed by human beings.
My few suggestions:
1. Keep a separate file for all SQL queries. for example:
(#) file: sql_index.php
$select_users = ‘select * from User’;
$delete_user_by_id = ‘delete from User where userID=?’;
$select_comments = ‘select * from Comment’;
$delete_comments = ‘delete from Comment’;
(#) file: sample_usages.php
$result = mysql_query( $select_user);
—> Benefit is, when you want to solve cross database related issue, you can resolve it very frequently (though you can write Data Abstraction Layer dependent code)
2. Presentational files (which files are used to render web UI) should keep their logic through few helper functions (rather hard embedded code). For example:
(#) File: test.php
——————title ? >
(#) File: replace_test.php
3. Limit frequent database access.
–> Go for caching system, use PEAR cache or any cache solution from PECL. For more optimized and challenging solution go for DSO related caching solution, whenever you will need multiple server It will give you a big hug. Go for MemCache, as it has been proven for several years.
4. Grow your knowledge on Software engineering.
5. Explore your idea, you can become a good developer but you can’t become a good idea creator unless you explore and dive inside the deep sea of knowledge.
6. Travel as much place as you like, it will help you to grow up a good sense of creativity. (I have to start it … 😀 )
7. Don’t forget to adopt little stuff from TDD (Test driven development), dig these terms: unit test, fixture etc…
8. Try to work on agile team. Enforce your PM to learn about agile related stuff. Select the best agile methodologies which are most suitable for your company. (Agile comes with a bunch of options, scrum, XP, rup and many stuff)
9. While you writing your code, always think, your code will be verified by some guy, who is very strict and who will surly scream because of your poor writing… :p (anyway, if u feel your code is nice … just send me. during my week ends I will check it up… obviously I will come with a set of good criticize 🙂 )
10. Learn, Dig, Seek and Dive in “KnowSea”
11. Use change management tools, (Subversion, bug tracking system and project planning tools)
(hasin bhai apologized for Big comment :p)