开发者

How to write Clean Code in Cakephp [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 11 years ago.

I want to know how to write a clean code in CakePHP? Definitely something like the book "Clean Code, A handbook of Agile Software Craftmanship by Robert Martin"

What is a cleaner way to write a controller, a model, and a view? How to handle inline javascripts the cleaner way?

I ask this questions because I do have managed cakephp application and it is currently bloated. We didn't wrote it with the clean code technique in our min开发者_如何学JAVAd. So now we are having a hard time extending it.

Thanks in advance.


[ This question migth be closed ]

A few tips:

  • You should think first on your data model.. normalized tables, correct models and relations.
  • respect MVC and try using cake's ORM instead of doing $model->query() all the time.
  • DRY. Make your code reusable, even if you're not planning to reuse it right now. Create elements, helpers, components and functions.
  • try to use Cake Tools. i.e use the Session object instead of $_SESSION, the Cache Class, the Set Class, etc.
  • KISS. Avoid unnecessary complexity

in my experience:

  • I dont use cake's inline javascript.. I'd rather create Mootools Classes, i find it cleaner and much more flexible.
  • I dont like Plugins, because I end up searching for hours for a plugin that can exactly what i want, and usually i dont find it.. and when I find it, it takes more time to understand how to install it and test it... and if they ask me to modify something I have to spend even more time trying to understand how the plugin works... for me, it's faster if I create my own tools and plugins.

Hope this helps

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜