tags:

views:

217

answers:

6

There is a lot of books and tutorials about php that are completely different from each other.

How can I choose the right way? Is the only way is test with xdebug or phpUnit or benchmark?

+6  A: 

General Best Practices

As code quality/readability/maintainability cannot be "benchmarked", I suggest reading books about proper code structuring and best practices.

Maybe Code Complete book from Steve McConnell?

Consider using Suitable Patterns and Frameworks

It's also worth mentioning the use of a well defined pattern like MVC and build your project with some Framework like Zend, as this will encourage you to put each piece of code where it belongs.

Bakkal
This is not true. Code Quality/Readability/Maintainability can very much be benchmarked. See my link to PHP QA Tools. Also, frameworks are not guarantee for proper code. Frameworks solve certain problems. If you do not have these problems, you do not need a framework.
Gordon
I went through the interesting slide and the tools. By `How can I choose the right way?` I understood he isn't looking for metrics but rather how to land software in the "right way". I can't suggest writing software and run "benchmarks" on each iteration and stop when the metrics says so. Some of those tools rely on "code mistakes" and well known anti-patterns like duplicate and dead code. A bad "benchmark" score most likely indicate bad software structure, while the other direction is far less probable. No substitution to proper research and design.
Bakkal
@Bakkal well, sure, those tools only indicate IF something is foul. The developer is still the one who has to learn how to improve his coding himself. If the developer understands the metrics though, she is already a good step forward in doing so though. Actually, running those tools constantly against your code is a common practise. Continuous Integration Servers like hudson or phpundercontrol will do this for you.
Gordon
A: 
  • Get experienced. Once you have changed a switch statement with instanceof's a couple of times, you see the advantages of polymorphism.
  • Keep thinking critical of your own code. Keep thinking about how you solve things and be open to other ways.
  • Read code. Unfortunately, most PHP code is not a good example on how to write code, but you will learn something from it nevertheless.
  • Read a book. A book is often more in-depth and detailed than any article on the interwebs.
Sjoerd
"Read a book. A book is often more in-depth and detailed than any article on the interwebs." : There is a lot of books and tutorials about php that are completely different from each other.How can I choose the right way?
phpExe
Different in what way?
Sjoerd
+1  A: 

xdebug is a very powerful tool and can help you a lot.
You will be able to see in your development server (and not an ideal server) what is happening with your code!

kanenas.net
What is this 'ideal server' about? Are there other tools that simulate an ideal server?
Sjoerd
It isn't always possible to have a server(s) with cutting edge CPU, Memory, Hard Disks, Software etc... That is what I meant with the "ideal server". A server that has all the above!
kanenas.net
A: 

Download a well known open source project or framework like Zend. Then read through some of the code to see how they approach common tasks, and the general structure they use.

Neil Aitken
Is there any opensource project that could support high traffic? (like news portals?), thanks
phpExe
@Bakkal Thanks for the correction, I really shouldnt answer questions from my phone :)
Neil Aitken
Scalability is quite a complex issue, and is a mix of good coding and hardware. I would reccomend reading some articles on high availability and scalability for more info.
Neil Aitken
+7  A: 

Have a look at the slides and the tools given at

Disclaimer: I am not affiliated with Sebastian Bergmann or thePHP.cc - they just happen to be major influence on the code quality topic in the PHP world, which is why I suggest this link.

Gordon
+1  A: 

If you like to improve your php code here are several advices:

  • do not use procedural programming, use oo
  • use some framework like kohana
  • use patterns every time
  • read some books about java oo programming (good book: beginning java objects 2 edition) Aldo it is different language, java teaches about good oo code and patterns.
  • do not use functions with cyclomatic complexity>20
  • Most programmers use complex hierarchical associative array. They are hard to maintaine. avoid using complex structure of associatve array as DTO, try using classes.
  • use coning standards.
  • test driven development, unit tests. If your code can be tested with unit tests you are one step towards good code. Continuous integration is always welcome, but not always suitable in php, depending on the code and libraries you are uning.
  • use mvc, layers in you architecture
  • there are a lot more thinks, but keep reading and improve all the time

Regards

darko petreski