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.