Clean Code



Download 3,58 Mb.
Pdf ko'rish
bet76/384
Sana05.04.2022
Hajmi3,58 Mb.
#530298
1   ...   72   73   74   75   76   77   78   79   ...   384
Bog'liq
Clean Code

Chapter 4: Comments
Warning of Consequences
Sometimes it is useful to warn other pro-
grammers about certain consequences. For
example, here is a comment that explains
why a particular test case is turned off:
// Don't run unless you 
// have some time to kill.
public void _testWithReallyBigFile()
{
writeLinesToFile(10000000);
response.setBody(testFile);
response.readyToSend(this);
String responseString = output.toString();
assertSubString("Content-Length: 1000000000", responseString);
assertTrue(bytesSent > 1000000000);
}
Nowadays, of course, we’d turn off the test case by using the 
@Ignore
attribute with an
appropriate explanatory string. 
@Ignore("Takes too long to run")
. But back in the days
before JUnit 4, putting an underscore in front of the method name was a common conven-
tion. The comment, while flippant, makes the point pretty well. 
Here’s another, more poignant example: 
public static SimpleDateFormat makeStandardHttpDateFormat()
{
//SimpleDateFormat is not thread safe, 
//so we need to create each instance independently.
SimpleDateFormat df = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z");
df.setTimeZone(TimeZone.getTimeZone("GMT"));
return df;
}
You might complain that there are better ways to solve this problem. I might agree with
you. But the comment, as given here, is perfectly reasonable. It will prevent some overly
eager programmer from using a static initializer in the name of efficiency. 
TODO Comments
It is sometimes reasonable to leave “To do” notes in the form of 
//TODO
comments. In the
following case, the 
TODO
comment explains why the function has a degenerate implementa-
tion and what that function’s future should be. 
//TODO-MdM these are not needed

Download 3,58 Mb.

Do'stlaringiz bilan baham:
1   ...   72   73   74   75   76   77   78   79   ...   384




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish