crap code indicators

Roger:

These are some of my "crap" indicators:
- No error detection/handling.
- Incorrect or non use of language features/standard libraries.
- Non understanding/incorrect use of programming paradigms (e.g. "is a", "uses a" ...).
- Useless, lack of, or bad documentation.
- Massive functions or methods
- Obfuscated code.

I hate it when:
Someone recreates functions because they were too distracted/overworked/lazy/dumb to see if a working function already existed.
Someone codes 5 lines to do something that could have been done with 1.
There are no naming conventions.
Someone uses one name for an object in one section of code but a different name in another but the two sections relate or interact. Duh!
There is no way to know who wrote the code or who made changes to it.
There is no formatting or inconsistent formatting.

Reiterate:
"more than 2 instructions in a line" is crap.
"no documentation or poor docs/comments" is crap.

> What code characteristics would make you say: “Pardon my French, but this code is crap!”

This is actually one of my favorite interview questions. I think lots of you guys already nailed the big ones: Functions with side effects. Big classes. Low cohesion. High coupling. Cut-paste-tweak duplication. Meaningless comments. Premature optimization. Premature generalization. Nonexistent error handling. Error handling everywhere. Empty catch blocks. Lots of "if" statements (special cases). Shared state concurrency.

I'll buck the trend and say the following aren't code smells, however:

* m_ notation. There are many abuses of Hungarian, but this isn't one of them.
* Multiple instructions on a line.
* Superficial layout inconsistencies. I don't think code has to cater to OCD sufferers to be considered "readable".
* Few comments. Well-written code doesn't need a lot of comments. (No comments at all is definitely a problem, but it's also one I've never run into. I have seen lots of problematic heavily commented code, though).
* Long functions. I look more at the number of locals and the level of indentation. Sometimes you really do need to do A, then B, then C, all the way to Z -- and in many cases, arbitrarily chopping it up into funclets is actually the wrong thing to do.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值