8种方式让你在6分钟内成为一个更好的程序员(译)-8 ways to be a better programmer in 6 minutes
Remember how Justice Gray started that little fad about becoming a better developer in 6 months?
Well, that was a while ago and most of you failed. Badly.
So here's a simpler challenge, some ways to be a better programmer in 6 minutes.
==只要6分钟,你就能成为一个更好的程序员
You've got 6 minutes, right?
Go for it!
1. Use a bigger font size.
==用大些的字体,比如14号字
大字体会让一屏可显示的代码减少,让你不由自主简化你的代码。
This is ridiculously easy -- but it works.
Go to your favourite IDE, and crank the font-size up. I switched from 10pt to 14 pt. The difference is that a lot less code fits on the screen at once.
The effect is: you're forced to write shorter methods. And that's a Good Thing.
(Scott Hanselman recommends that one)
2. Make hard-coded strings look ugly.
==让那些“硬编码”的字符串以醒目丑陋的字体突出显示
这会让你不由自主减少使用硬编码字符串。
I learnt this from Joe Cooney.
Go to your favourite IDE, and set it so that literal strings stand right out -- for example a yellow background with a red font. Make 'em ugly. Damn ugly. This will encourage you to perform less hard coding, and to notice when you are embedding strings in your text.
3. Pick an 'obscure' keyword and master it
==选一个没弄明白的关键字,掌握它
关键字往往代表一个重要的概念,当你渐渐地把一门语言的所有关键字都搞懂了,这门语言也就掌握了。
Do you fail to yield?. Is there a keyword you never use?
Every keyword has a purpose. Learn to master those mystery keywords and your powers will become extraordinary.
Here are lists for a few .net languages: C#, VB.net, F#.
4. Increase code-coverage by 1%
==在自动单元测试中把代码覆盖率提高1%
比如,选那种特复杂的正则表达式或者业务逻辑的关键部分,把它们的测试强度加大一下。
Don't kill yourself striving for 100% coverage of code with automated unit tests. But take a few minutes to increase your coverage by 1%.
Most likely, that means going from 0% to 1%. And that's the biggest improvement of all.
Find a particularly ghoulish regular expression. Or a critical piece of business logic. These things can't be trusted without tests.
5. Read the code from an open source project
==找个开源项目,读它的代码
读别人的代码,会给你不一样的感觉。
Sometimes, when I'm looking at the code of a complete stranger, I get that same, weird feeling I get when I'm creeping through my neighbour's house. Picking up their stuff, looking through their fridge.
Learn to overcome the creepy sensation, and bring on the learn.
Maybe start with Hanselman's Weekly Source Code series.
6. Run a static analysis tool against your code
==找个静态分析工具分析你的代码
这些工具的分析结果往往会让你大吃一惊,你会发现自己的代码原来有这么大的改进余地。
Use fxcop, or StyleCop, clone detective, ndepend, the code metrics feature of VS 2008, or any other static analysis tool of your choice.
Uncover your greatest weakness. Even a cursory glance at the output will leave you distraught at just how much room you've got for improvement.
7. Pick an ugly method to refactor
==重构一段丑陋的代码
重构所有代码可能让人望而却步,但是咱们可以每次只做一点,比如我们把某个变量名改得更规范和达意一些,或者把一小段代码单独剥离出来。
You know the method. That method you're particularly ashamed of. That one that's long and ugly and horrible. And it's crucial to the whole application.
You don't have to polish it from a turd to a diamond, but just neaten it up a little. Rename a variable. Hoist part of it out into a separate method. Start simple. The momentum will increase. Watch out.
8. Stop reading, start writing.
==自己写个简单的编译器试试
写过编译器,哪怕是最简单的那种,也许你就会对很多语法规定有不一样的理解。从而你在日后的编程里会采取一些有利于编译的“最佳实践”。
And don't just write. Write a compiler!
This ol' msdn article is a good place to start. Joel Pobar will get you writing your own language compiler in but a handful of minutes.
That's all I've come up with for now. But what've you got?
What are some 6 minute activities that helped you be a better programmer?