阅读 Bob Martin 的《简洁代码》。这本书充满了关于这个主题的技巧:以 Java 作为示例语言编写组织良好、可读性强的代码。
Read Bob Martin's Clean Code. It's a book full of tips on exactly this subject: writing well-organised, very readable code, with Java as the example language.
You can achieve this to some extent on different levels:
the language itself: use all features the language offers, e.g. the ternary operator (though some think it's not very readable) and Java7's elvis and diamond operator
how you implement: use all the libraries and their features! don't optimize prematurely!
the design: use design patterns and the suggestions in Josh Bloch's Effective Java. Precisely document your design decisions by referencing them (e.g. "Visitor" or "Bloch Item 7").
发布评论
评论(3)
阅读 Bob Martin 的《简洁代码》。这本书充满了关于这个主题的技巧:以 Java 作为示例语言编写组织良好、可读性强的代码。
Read Bob Martin's Clean Code. It's a book full of tips on exactly this subject: writing well-organised, very readable code, with Java as the example language.
三元运算符(if-then-else 语句的简写)可以很方便。
The Ternary Operator (shorthand for if-then-else statement) can be handy.
您可以在不同层面上在某种程度上实现这一点:
You can achieve this to some extent on different levels: