the reasonable man adapts himself to the world;the unreasonable one persists in trying to adapt the world to himself. —蕭伯納
相信自己看得懂就看得懂了,相信自己能寫下去,我就開始寫了.其實也簡單—泥沙磚瓦漿木匠
today , i am writing my java notes about <編寫高品質代碼改善java程式的151個建議> -秦小波.
three pieces[1-3]:
1.don't code by confusing letters in the constants and variables [不要在常量和變量中出現易混淆的字母]
2.don't change the constants into the variable. [莫讓常量蛻變成變量]
3.make the the types of ternary operators the same. [三元操作符的類型務必一緻]
from the book:
outputs:
1
<code>2</code><code> </code>
(unbelieved?just ctrl c + ctrl v run the code !)
in my words:
‘1l’is not ‘11’. but we always code by the confusing things .
then bebug for a long time , finally we will laught at ourselves with
the computer and codes face to face.”what fucking are the
coder?”lol,smile ! carm down , because u r so lucky to read this . i
will tell some excemples to keep them away. away ? really away?
step 1: somthing about coding standards
constants should always be all-uppercase, with underscores to separatewords. [常量都要大寫,用下劃線分開]
see a case from my project itp:
camel case:[變量命名駝峰原則,自然你也可以選擇其他的法則等]
if u wanna do it , right now ! it can make your codes more beautiful and clean! amazing ! u learned it , keep on!!!
#please remeber the camel , then u can write a nice code.

step 2: somthing can make your program easier to understand
some letters should not be used with the numbers,like l o … they
are the brother of the numbers.but we can do some to avoid. like use
‘l’ , and write some notes about them.
a magical demo:
#i think the demo is bad. rand_cosnt is not a constant and we never do that.
what is constants ?
constants are immutable values which are known at compile time and do not change for the life of the program.but if the project is too large to manage.there will be a problem.let me show u!
example:
class a's goodnumber = 0.618
now we change a.java –> goodnumber to “0.6180339887”
“javac a.java”then “java b” , we will find the outputs is the same:
why??????????????????
just see the class of b, use “ javap –c b”:
#3: ldc #3 // string class a's goodnumber = 0.618
ok , we see! the last interface a was already in the class b. so we can “javac b.java”to deal.
all in all ,
a best way store constants : static fianl xxx static object getxxx()
it shows the java dynamic advantage and a constant principle.
<code>false</code>
see the compiled code ,use “javap –c client03”,we will see:
the transformation rules about ternary operators.
三元操作符類型的轉換規則:
1.若兩個操作數不可轉換,則不做轉換,傳回值為object 類型。
2.若兩個操作數是明确類型的表達式(比如變量),則按照正常的二進制數字來轉換,int 類型轉換為long 類型,long 類型轉換為float 類型等。
3.若兩個操作數中有一個是數字s,另外一個是表達式,且其類型标示為t,那麼,若數字s 在t 的範圍内,則轉換為t 類型;若s 超出了t 類型的範圍,則t 轉換為s類型(可以參考“建議22”,會對該問題進行展開描述)。
4.若兩個操作數都是直接量數字(literal) ,則傳回值類型為範圍較大者。