use intent-revealing name, if your need a comment ,that's not a good name.
int d; // elapsed time in days
int elapsedTimeInDays;
/***Useful range constant*/ public static final int INLCUDE_NONE=0; /***Useful range constant*/ public static final int INLCUDE_NONE=1; /***Useful range constant*/ public static final int INLCUDE_NONE=2; /***Useful range constant*/ public static final int INLCUDE_NONE=3;
can you tell me what they mean,did the comment helpful?
'userful?' are their useless code?'range?'range of what?'Constant' ofco use its a constant
whenever you have to read the code in order to understand the name, the name has pretty much failed to communicate the intent.It's a bad name.
Remember names are not for your convienient, it's your primariy tools for communicate intent.Commuicate your intent is always your first priority,it's even more important than the code work.
disinformation: name in code does not mean what it's said.(worsest sins)
a misleading name can cous
bad
int PC_GWDA; public int getYYYY(){ return this.year; } int qty_tests =0; int qty_pass_m=0; int qty_pass_s =0; int qty_skip = 0; int qty_fails=0;
prifix: p mean point,c mean char, b mean boolean.C for Class,I for Interface.
C: Class CAccount
I:Interface IAccount
p: pointer pAccount
s: String sName
st: Null Terminated StName
now days,IDE can tell all this informations,i won't be using them.That' 1990s legency,silly prifixs.Just use names! Let the IDE,compiller and test do the rest.
'Account is better than IAccount'Part of Speech
class and variable are norns or norn pharse,methods are verbs.
ignore silly nosie words.
good
ACOUUNT,MESSAGEPARSER
silly nosie words
MANAGER,DATA,INFO,PROSSOR
boolean variabels should been write like predicats,they read well,like isEmpty
,isTerminated
methods should been verbs or verbs pharese, they read well,like getPirce
,postPayment
if a methods returns a boolean,then should be predicats,beacuse they likely be used in if statement and they read well,likeisPostable
boolean isEmpty; boolean isTerminated; --- if(isEmpty){ if (payment.isPostable()){ postPayment(payment); } }
enum Color{RED,GREEN,BLUE}; enum Status{PENDING,CLOSED,CANCELLED}; enum Size{SMALL,MEDIUM,LARGE};
remmeber: it's a lot easier to read code if the statements form sentences that read like well written poems.
if(employee.isLate() employee.reprimand();
the longger the scope of variable,the longger veriable names,but the variable with short scope should have short names;
for (ITestResult tr: m_configIssues){ Elemtent element = createElement(d,tr); rootElement.appendChild(element); }
here
tr
is a good name,butd
is bad.element
should be shorten toe
.
the longer the scope,the shorter the function or name should be;
the shortter the scope,the longer the function should be.
public void server(Socket s){ try{ tryProcessInstructions(s); }catch(Throwable e){ slimFactory.stop(); close(); closeEnclosingServiceInSeperateThread(); } } }
we like long socpe public function names short like
serve
,convinient to use,long name hard to tell apart;we like short scope private function names long liketryProcessInstructions
,closeEnclosingServiceInSeperateThread
,only called from here ,it's kind of a comment, explain themselves.
The same arguement can be applied to Classes.