9 is moving towards excellent software design? -- Understanding of the thoughtworks Anthology

Source: Internet
Author: User

I really shouldn't have read this book based on my current level and experience. Translate the Chinese name of the thoughtworks anthology into the "Meditation on software development. This book contains many short articles to discuss all aspects that need attention in Agile development. Unfortunately, I am not experienced enough to understand it.

One article in the book is named "Object aerobics", which proposes nine rules for excellent software design exercises:

1. The method only uses a level-1 indent (I'm a little surprised)

2. refuse to use the else keyword (is this possible? I'm quite surprised)

3. encapsulate all native types and strings (this is fine)

4. One rowCodeUse only one "." Operator

5. Do not use abbreviations (troublesome)

6. Keep the object simple and clear

7. No more than two entity variables in any class

8. Use a first-class set

9. Do not use any getter/setter/Property

 

Look at two strange

Rule 1: The method only uses a level-1 indent

Example:

 

Code

 Class  Board {
....
String Board (){
Stringbuffer Buf = New Stringbuffer ();
For ( Int I = 0 ; I < 10 ; I ++ ){
For ( Int J = 0 ; J < 10 ; J ++ )
Buf. append (data [I] [J]);
}
Return Buf. tostring ();
}

}

 

 

Change

 

  Class board {
...
String Board (){
Stringbuffer Buf = New Stringbuffer ();
Collectrows (BUF );
Return Buf. tostring ();
}

Void Collectrows (stringbuffer BUF ){
For ( Int I = 0 ; I < 10 ; I ++ )
Collectrow (BUF, I );
}
Void Collectrow (stringbuffer Buf, Int Row ){
For ( Int I = 0 ; I < 10 ; I ++ )
Buf. append (data [row] [I]);
Buf. append ( " \ N " );
}

 

In my understanding, some of the larger functions are divided into the smallest ones. Of course, if the function is too long, it is not good. Can so many short functions be created, is it really beneficial for project development?

 

2. refuse to use the else keyword

This looks incredible. The example is as follows:

 

 
Public static void endme () {If (status = done) dosomething (); else <other>}

The author recommends removing Else.

 

 
Public static void endme () {If (status = done) {dosomething (); Return () ;}< other>}
 
Another example:
 
Public static node head () {If (isadvancing () return first; else return last ;}
So change
Public static node head () {return isadvancing ()? First: Last ;}

In this case, it seems that I often write code that does not use else, but do I have to disable all else keywords? Is it necessary?

As I have no experience, I hope you will discuss it.

 

 

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.