Wednesday, December 24, 2008

singleton discussions

Why I Hate Singletons

Singletons are not evil

Why Singletons are Evil

Thursday, December 18, 2008

OOP Principles

Below principles are extracted from the excellent PHP book: PHP In Action.

A class should be open to extend, closed to modification. A refactoring technique is also regarded in this principle: Replace conditional with polymorphism.

In real world: when a new requirement comes up, what a programmer usually do is, open the source code, find the related part, put if (condition) {//do the new requirement}

a class that tries to do everything will have to change frequently because
some responsibility it has needs to be updated. A class should have only one reason to change.

In real world: any other template engines except smarty can allow developers put business logic into it?

GoF tell us: program to an interface, not an implementation.


Friday, December 12, 2008

read list

I list some books which i am reading and about to read.

1. PHP Objects, Patterns, Practices
2. PoEA
3. High Performance Mysql 2nd edition (i read the 1st one and feel good. Wonder the difference in 2nd edition)
4. Symbian S60 Programming a tutorial guide
5. Symbian Effective C++
6. Common Design Patterns for Symbian

Monday, December 8, 2008

Good and Bad PHP Code

Today I read a blog about good and bad php code.

When I asked this question to myself, what is good php code, I surprisingly find out that my brain is blank! However, when I try to ask in the other way, what is bad php code, I can give tons of examples. Below is some of them.

0. Variable is not initiated.
1. Not using isset to check if a variable is initiated.
2. Not checking data type
3. Global variables everywhere
4. Static methods everywhere
5. Long functions (function should be short & simple enough that you even think unit test is not required)
6. Long parameters
7. Duplicate codes
8. Low efficient coding style
9. huge class
10. No memory management concept in mind (Yes, even PHP we need to think of that!)
11. Implement large project without MVC architecture.
12. Put business logic in presentation logic(Especially for smarty users)
13. Like to use too many if, else, switch to control the logic
14. Without security concept in mind (sql injection, string filter)
15. poor DB modelling and SQL statements, e.g. using too many Mysql Fucntions which could be done in PHP, using IN in sql Query (Although this is not PHP code)