登陆 |  注册  |  我的客厅  |  我的圈子  |  管理中心  | 
布谷首页 > 客厅 > 掌牛狼会客室 > 日志
标签: PHP 程序员
发布时间:2008.08.29 10:30
[对照注意]PHP程序员的40点陋习
Reinhold Weber 提出PHP程序员的40点陋习.
1不写注释

2不使用可以提高生产效率的IDE工具

3不使用版本控制

4不按照编程规范写代码

5不使用统一的方法

6编码前不去思考和计划

7在执行sql前不执行编码和安全检测

8不使用测试驱动开发

9编码时不打开自动报错(error_reporting)

10不使用一种好的调试工具

11不重构你的代码(refactor)

12不采用MVC这样的分层结构

13不知道以下等等概念:KISS,DRY,MVC,OOP,REST

14在函数或者类里直接用print或者echo输出东西而不是返回(return)

15不使用也不去了解单元测试

16返回HTMl而不是data,strings,objects等类型

17糟糕的代码和配置参数(hard code messages and configuration parameters)

18不优化sql查询

19不使用__autoload

20不支持自动错误操作(应该是智能纠错)

21使用$_GET替代$_POST去进行危险的参数传递(记得这40条都是错误的东西)

22不知道怎样使用正则表达式

23从未听说过sql注入和跨站脚本(安全方面,应该了解下这两个东西的英文:sql injection,cross-site scripting)

24不支持简单配置,传递参数给类的构造函数,set/get方法,定义常量

25不能理解OOP的优缺点

26无论要做的东西有多小,都使用OOP

27认为做可复用的软件就是OOP

28不使用缺省值(don’t choose intelligent defaults)

29不使用单一配置文件

30不想让别人看到代码,却使用.inc替换掉.php

31不使用数据库抽象层(持久层)

32开发时不DRY(Dont repeat yourself). (就是总开发重复的东西)

33不开发可以重复使用的类或者方法.

34不使用抽象类或者接口类,继承,多态,封装.

35不使用已有的设计模式优化你的程序.

36不允许使用者定义基础目录(这点好象PHP不太适合,毕竟不是基于操作系统的开发)

37错误的使用命名空间,使用大家都普遍使用的单词作为前缀.(这样以后别人使用会造成冲突.,例如自己定义一个function 叫 array_push())

38使用数据库时不使用表前缀(这个很重要…)

39不使用或者使用一个陌生的模板引擎(方便团队开发,大家要使用常见的模板)

40不去看PHP的框架(大多数框架中都包含优秀的代码和先进的概念.值得我们学习)

其中译者还有很多做不到的,还需要努力!

以下是原文:

1. don’t comment your code properly with something like phpDoc

2. don’t see the need and/or benefits of a good programming IDE like Zend Studio or Eclipse PDT

3. have never used some form of version control like Subclipse

4. don’t adopt some coding & naming standards and general conventions and stick to to them at least throughout the project

5. don’t use a consistent methodology

6. don’t escape and/or validate properly input or sql queries

7. don’t plan your application thoroughly before starting to code

8. don’t use test-driven development

9. don’t program & test with error reporting on

10. don’t see the benefits of a debugger

11. don’t refactor your code

12. don’t keep the different layers seperated using something like MVC

13. don’t know what these stand for: KISS, DRY, MVC, OOP, REST

14. don’t return content but echo or print it from your functions or classes

15. have never seen the advantage of unit tests or testing in general

16. return HTML, not data, strings, or objects.

17. hard code messages and configuration parameters

18. don’t optimize your sql queries

19. don’t use __autoload

20. don’t allow intelligent error handling

21. use $_GET instead of $_POST for any destructive actions

22. don’t know how to use regular expressions

23. you’ve never heard of sql injection or cross-site scripting

24. don’t allow simple configuration, can be parameters passed to a class’s constructor, set/get methods called later, or constants defined at a runtime.

25. don’t understand the benefits and limitations of Object Oriented Programming

26. misuse OOP / everything you write , no matter how small is OOP

27. you think reusable software equals/requires your code to be OOP

28. don’t choose intelligent defaults

29. don’t have one single configuration file

30. don’t want the file contents to be seen, but give it a .inc extension instead of .php

31. don’t use a database abstraction layer

32. don’t keep it DRY, Don’t repeat yourself. If you have to copy and paste or duplicate something your design may be off.

33. don’t make a function/class/method do just one thing and don’t make them interact.

34. don’t try to take advantage of OOP specific features like abstract/interface classes, inheritage polymorphism & access modifiers.

35. don’t optimize your application design with established design patterns

36. don’t allow your user to define a base directory if you have multiple files and/or directories

37. pollute the global namespace, one option is to prefix the functions in your library with a common string

38. don’t allow a table prefix when using database tables

39. use a separate template engine

40. don’t take a look at established php frameworks for inspiration, most of them have advanced web dev concepts and good code

Reinhold Weber has put together a list of signs (40 in all on his “programming list of shame”) that you’re a lousy PHP programmer. Here’s a sampling:
don’t see the need and/or benefits of a good programming IDE like Zend Studio or Eclipse PDT
have never used some form of version control like Subclipse
don’t use a consistent methodology
don’t use test-driven development
don’t return content but echo or print it from your functions or classes
return HTML, not data, strings, or objects.
don’t allow intelligent error handling
you think reusable software equals/requires your code to be OOP
Now granted, some of them are a bit more high level than others, but if you’re not headed towards a lot of these, you might change paths, hop out of that comfort zone and branch out into the community and the language a little bit more.

 
人推荐
 
浏览(8) | 评论(0)
精彩评论
正在请求评论列表....
 
 
 发表评论
 
昵称: 注册 | 登录    
 
 
 
 厅主信息
年龄:25    职业:保密
积分:637   刺鸟
个性签名:
     从该来的地方来, 到该去的地方去; 留下该留下的, 带走该带走的.
  
 
布谷客厅推荐   更多  
小贝与爱儿
亲爱的小孩
 
厅主最新日志   更多  
暂无相关信息
 
美图欣赏推荐   更多  
一个人的快乐
她的名字叫王筝
 
原创大赛作品   更多  
·老人——(我慈祥的 ·我们仨儿
·只是如此 ·雨幕
·我的灵魂 ·千古爱情
·狂傲吟 ·
·父亲之歌 ·我的灵魂
 
布谷相册推荐   更多  
快过年的样子
童真的年代
 
精彩日志推荐   更多  
·为什么亲嘴不卫生 ·女人的话要这样听
·令人喷饭的车窗标语 ·11种男人不应该错过
·盖茨的10句名言 ·人生“三”要点
·女孩女应该知道的事 ·四种水起床不能喝
·孩子最爱听的40句话 ·做一个有情的人
 
布谷圈子推荐   更多  
蟠龙花园
海天四望大厦
 
原创日志推荐   更多  
·心上眉间 ·女孩听 男孩做
·贬值最快的三种人 ·男人外表软里面硬
·人是到世界来奉献 ·没有爱情请给我红酒
·毕业前一定要做的事 ·百度的繁荣还有多久?
·女人的依赖性 ·多事之冬,静观为好
 
圈子热图推荐   更多  
浴出性感美人
一个男人的忧伤
 
热门话题推荐   更多  
·萨科奇执意见达赖? ·日政治家频“失言”?
·中国的大学误人子弟? ·网络暴力要不得
·他们是富豪还是土豪 ·网友炮轰建设部主任?
·打工仔路在何方? ·医生收红包不算受贿
·大学生家教遇寒流? ·现代人睡眠也赤字?

关于布谷 | 联系我们 | 友情链接 | 布谷帮助 | 免责声明 | 网站地图
广州亿码科技有限公司版权所有◎2000-2008    粤B2-20050444    网络实名:布谷    服务热线(9:00-18:00):020-38480358-1020  简化1  简化2