- 浏览: 746451 次
- 性别:
- 来自: 上海
文章分类
- 全部博客 (419)
- 杂软粉墨 (2)
- 创意灵感 (3)
- 经验记录 (137)
- 开源轨迹 (2)
- sip-communicator (2)
- 闲侃杂谈 (8)
- 问题交流 (24)
- 概念模式 (32)
- 难点备案 (5)
- JwChat (1)
- 中国象棋 (1)
- 教育探索 (6)
- 英语研究 (58)
- 星际争霸 (1)
- 电信知识 (1)
- 软件架构 (3)
- 哲学探索 (26)
- 算法灵魂 (8)
- 近视探索 (6)
- 数学数学 (3)
- 牛角钻尖 (23)
- 至强文言 (3)
- 数据结构 (1)
- 宇宙物理 (2)
- 网络架构 (3)
- 游戏领域 (4)
- 图形处理 (2)
- 修炼之路 (8)
- 读书天地 (20)
- 编解乱码 (2)
- 概念探索 (8)
- 格物致知 (1)
- 其它语言 (1)
- 测试领域 (3)
- 文化风流 (1)
- JQuery (1)
- 網頁領域 (1)
- Unix/Linux (1)
- Inside JVM (1)
- 异常分析 (1)
最新评论
-
suyujie:
引用
HTML <a> 标签灰显禁用 -
suyujie:
HTML <a> 标签灰显禁用 -
suyujie:
HTML <a> 标签灰显禁用 -
suyujie:
HTML <a> 标签灰显禁用 -
iamzhoug37:
您能说一下"局部变量不受文本顺序限制" 是 ...
声明前为什么能赋值却不能输出,都是使用
you should try several different names and read the code with each in place .
here the in place is key point. it asks people to consider better names, don't be afraid to spend more time, cuz it's worth that. in place means in proper place, it's an important usage.
Modern IDEs like Eclipse or IntelliJ make it trivial to change names.
here the usage of trivial by make it trivial to do sth is rare to see, means easy, right? with the help of modern IDEs, it's rather easy to change a whole bunch of the same names.
2011.04.06
the following is a pretty classic English paragraph from the first of the 5th chapter.
When people look under the hood, we want them to be impressed with the neatness, consistency,
and attention to detail that they perceive. We want them to be struck by the
orderliness. We want their eyebrows to rise as they scroll through the modules. We want
them to perceive that professionals have been at work. If instead they see a scrambled
mass of code that looks like it was written by a bevy of drunken sailors, then they are
likely to conclude that the same inattention to detail pervades every other aspect of the
project.
Code formatting is about communication, and communication is the professional developer’s first order of business .
Perhaps you thought that “getting it working” was the first order of business for a
professional developer. I hope by now, however, that this book has disabused you of
that
idea. The functionality that you create today has a good chance of changing in the next
release, but the readability of your code will have a profound effect on all the changes
that will ever be made. The coding style and readability set precedents
that continue to
affect maintainability and extensibility long after the original code has been changed
beyond recognition. Your style and discipline survives, even though your code does not.
here uncle bob continues to emphasize and prove why communication i.e. formatting style is so important?
readability of the code is preferrable to getting it working. and beyond recognition means your code has been changed a lot and it's beyond recognition. so your style and discipline survives, even though your code does not.
But we’re not trying for precision here. We’re just trying to get a feel.
Seven different projects are depicted .
What does that mean to us? It appears to be possible to build significant systems
(FitNesse is close to 50,000 lines) out of files
that are typically 200 lines long, with an
upper limit of 500. Although this should not be a hard and fast rule, it should be considered
very desirable. Small files are usually easier to understand than large files are.
As you continue downward, the details increase until you have all the dates, names, quotes, claims, and other minutia.
A newspaper is composed of
many articles; most are very small. Some are a bit larger
.
Very few contain as much text as a page can hold
. This makes the newspaper usable. If the
newspaper were
just one long story containing a disorganized agglomeration of facts,
dates, and names, then we simply
would not read it.
As you scan down the listing, your eye is drawn to the first line that follows a blank line.
Taking those blank lines out, as in Listing 5-2, has a remarkably obscuring effect on the
readability of the code.
This effect is even more pronounced when you unfocus your eyes. In the first example
the different groupings of lines pop out at you, whereas the second example looks like a
muddle. The difference between these two listings is a bit of vertical openness.
We want to avoid forcing our readers to hop around through our source files and classes.
Dependent Functions. If one function calls another, they should be vertically close,
and the caller should be above the callee, if at all possible. This gives the program a natural
flow. If the convention is followed reliably, readers will be able to trust that function definitions
will follow shortly after their use. Consider, for example, the snippet from FitNesse
in Listing 5-5. Notice how the topmost function calls those below it and how they in turn
call those below them. This makes it easy to find the called functions and greatly enhances
the readability of the whole module.
As an aside, this snippet provides a nice example of keeping constants at the appropriate
level [G35]. The "FrontPage" constant could have been buried in the
getPageNameOrDefault function, but that would have hidden a well-known and expected
constant in an inappropriately low-level function. It was better to pass that constant down
from the place where it makes sense to know it to the place that actually uses it.
String pageName = getPageNameOrDefault(request, "FrontPage"); private String getPageNameOrDefault(Request request, String defaultPageName) { String pageName = request.getResource(); if (StringUtil.isBlank(pageName)) pageName = defaultPageName; return pageName; }
pass that constant down (means from high level to low level) where it makes sense to know it (the caller place) to the place that actually uses it (the function body)
These functions have a strong conceptual affinity because they share a common naming
scheme and perform variations of the same basic task. The fact that they call each other is
secondary. Even if they didn’t, they would still want to be close together.
As in newspaper articles, we expect the most important concepts to come first, and
we expect them to be expressed with the least amount of polluting detail. We expect the
low-level details to come last. This allows us to skim source files, getting the gist from the
first few functions, without having to immerse ourselves in the details.
Remember this is a log scale, so the linear appearance of the drop-off above 80 characters
is really very significant. Programmers clearly prefer short lines.
I used to follow the rule that you should never have to scroll to the right. But monitors
are too wide for that nowadays, and younger programmers can shrink the font so small that they can get 200 characters across the screen. Don’t do that. I personally set my limit at 120.
Whenever I have succumbed to this temptation, I have almost always gone back and put the indentation back in.
Then we encoded those rules into the code formatter of our IDE and have stuck with them ever since.
Remember, a good software system is composed of a set of documents that read nicely. They need to have a consistent and smooth style.
The last thing we want to do is add more complexity to the source code by writing it in a jumble of different individual styles.
here the the last thing roughly means the thing one should not do
发表评论
-
effective java 2nd Item 18
2012-08-15 15:45 1218Prefer interfaces to abstract ... -
Head First HTML with CSS and XHTML
2012-03-27 14:50 974i finished it by fast reading a ... -
head first jquery
2012-03-22 10:21 1136Thursday, March 22, 2012 fi ... -
Software Architecture Design Patterns in Java
2011-05-13 22:53 813to be continued... -
Effective Java 2nd edition
2011-04-25 16:19 1016Item 3: Enforce the singleton p ... -
Clean Code: chapter 13~15
2011-04-20 17:20 1024What follows is a series of p ... -
Clean Code: chapter 11~12
2011-04-15 09:35 1053The startup process is a concer ... -
Clean Code: chapter 9~10
2011-04-12 11:49 997Yes, we’ve come a long way; but ... -
Clean Code: chapter 6~8
2011-04-06 17:05 8542011.04.07 Objects and D ... -
Open Stanford Course: programming methodology 04
2011-04-05 11:52 921because this is sort of pre thi ... -
Open Stanford Course: programming methodology 03
2011-04-04 13:01 951any questions to start off with ... -
Open Stanford Course: programming methodology 02
2011-03-31 00:30 974If you are stuck in the back, j ... -
Open Yale Course: Frontiers of Biomedical Engineering 01
2011-03-30 11:21 905http://www.verycd.com/topics/28 ... -
Open Stanford Course: programming methodology 01
2011-03-25 11:00 926you can pick them up on the ... -
Java Puzzler
2011-03-24 23:58 10602011.03.24 now i've been thr ... -
How Computers Work
2011-03-04 09:58 1016Yes, im at last reading this fa ... -
The Java Language Specification Third Edition
2011-01-25 10:36 845starting day: 2011.01.25 -
Tricks of the Java Programming Gurus
2011-01-24 11:22 921In the world of programming, t ... -
Thinking in Java Fourth Edition
2011-01-17 15:59 987以前这些经典书籍都零零散散地阅览过,现在准备重新精读一遍,随时 ...
相关推荐
Chapter 1 Clean Code Chapter 2 Meaningful Names Chapter 3 Functions Chapter 4 Comments Chapter 5 Formatting Chapter 6 Objects and Data Structures Chapter 7 Error Handling Chapter 8 Boundaries Chapter ...
There is the right way to do things, and there's the wrong way to do things....Chapter 1. Introduction Chapter 2. Debugging and Maintenance Chapter 3. Code Conventions Chapter 4. Thought Patterns
But if code isn’t clean, it can bring a development organization to its knees. Every year, countless hours and significant resources are lost because of poorly written code. But it doesn’t have to ...
Chapter 5: Development Cycle Chapter 6: Preparing for Testing Chapter 7: Fixtures Chapter 8: Model Tests Chapter 9: Controller Tests 1 Chapter 10: Mocks Chapter 11: Controller Tests 2 Chapter 12: Test...
CleanCode4Noobs 罗伯特·塞西尔·马丁(Robert Cecil Martin)编写的《清洁代码:敏捷软件技巧手册》的摘要。 内容 参考 Robert C. Martin,“清洁代码:敏捷软件Craft.io手册” 如何贡献 贡献使开源社区成为了一...
Chapter 5: Dependency Management Chapter 6: Code Quality Plugins Chapter 7: Reporting and Documentation Chapter 8: Handling Typical Build Requirements Chapter 9: Multimodule Projects Chapter 10: Java ...
Chapter 5: Game 1–Pachinko/Plinko Chapter 6: Attributes Chapter 7: Graphics and Artwork Chapter 8: Behaviors Part 1 Chapter 9: Behaviors Part 2 Chapter 10: Player Input Chapter 11: Game 2 – Space ...
I will first guide you through a very simple example in chapter 1, demonstrating how to use TDD to approach a project, and how to properly create tests from requirements. In chapter 2 I will then ...
Chapter 5: System Framework Environment ExploreRegEx FileIO pathIO RegularExpression socketsClient socketsServer threads XmlDocument XmlDom XmlMisc XmlParse XmlSchema XPath...
### SCJP Sun® Certified Programmer for Java™ 6 Study Guide Chapter 5: Flow Control, Exceptions, and Assertions #### Certification Objectives Overview In this chapter, we delve into the critical ...
Title: Less Web Development Essentials, ...Chapter 5: Integrating Less In Your Own Projects Chapter 6: Using The Bootstrap 3 Frontend Framework Chapter 7: Less With External Applications And Frameworks
Chapter 5: More Classification Techniques – K-Nearest Neighbors and Support Vector Machines Chapter 6: Classification and Regression Trees Chapter 7: Neural Networks Chapter 8: Cluster Analysis ...
Chapter 5. Working with Legacy Code Chapter 6. Maintaining Your Test Suite Chapter 7. Executable Documentation with doctest Chapter 8. Extending unittest with nose2 Chapter 9. Unit Testing Patterns ...
Chapter 5: Persisting Changes Chapter 6: Applying Styles Chapter 7: Authentication and Authorization Chapter 8: Third-Party Authentication and External Providers Chapter 9: User Registration and ...
Create funky, impressive applications using Swift About This Book ...Chapter 5: Flappy Swift Chapter 6: Polishing Flappy Swift Chapter 7: Cube Runner Chapter 8: Completing Cube Runner
**Chapter 5: Strings** - **String Literals:** Explanation of different ways to define strings in PHP, including single quotes, double quotes, and heredoc syntax. - **String Functions:** Overview of ...