Mudanças entre as edições de "Use Intent Revealing Names"

De Basef
Ir para: navegação, pesquisa
(Criou página com 'It is easy to say that names should reveal intent. What we want to impress upon you is that we are serious about this. Choosing good names takes time but saves more than it ta...')
 
Linha 7: Linha 7:
 
The name of a variable, function, or class, should answer all the big questions. It
 
The name of a variable, function, or class, should answer all the big questions. It
 
should tell you why it exists, what it does, and how it is used. If a name requires a comment, then the name does not reveal its intent.
 
should tell you why it exists, what it does, and how it is used. If a name requires a comment, then the name does not reveal its intent.
 +
 +
<source lang="Java">
 
int d; // elapsed time in days
 
int d; // elapsed time in days
 +
</source>
  
 
The name d reveals nothing. It does not evoke a sense of elapsed time, nor of days. We
 
The name d reveals nothing. It does not evoke a sense of elapsed time, nor of days. We

Edição das 10h34min de 27 de janeiro de 2020

It is easy to say that names should reveal intent. What we want to impress upon you is that we are serious about this. Choosing good names takes time but saves more than it takes.

So take care with your names and change them when you find better ones. Everyone who reads your code (including you) will be happier if you do.

The name of a variable, function, or class, should answer all the big questions. It should tell you why it exists, what it does, and how it is used. If a name requires a comment, then the name does not reveal its intent.

int d; // elapsed time in days

The name d reveals nothing. It does not evoke a sense of elapsed time, nor of days. We should choose a name that specifies what is being measured and the unit of that measurement:

int elapsedTimeInDays;
int daysSinceCreation;
int daysSinceModification;
int fileAgeInDays;