Clean Code



Download 3,58 Mb.
Pdf ko'rish
bet198/384
Sana05.04.2022
Hajmi3,58 Mb.
#530298
1   ...   194   195   196   197   198   199   200   201   ...   384
Bog'liq
Clean Code

Listing 14-8 (continued)
Args.java (first draft)


206
Chapter 14: Successive Refinement
I hope your initial reaction to this mass of code is “I’m certainly glad he didn’t leave it
like that!” If you feel like this, then remember that’s how other people are going to feel
about code that you leave in rough-draft form. 
Actually “rough draft” is probably the kindest thing you can say about this code. It’s
clearly a work in progress. The sheer number of instance variables is daunting. The odd
strings like 
“TILT
,

the
HashSets
and
TreeSets
, and the 
try-catch-catch
blocks all add up to
a festering pile.
I had not wanted to write a festering pile. Indeed, I was trying to keep things reason-
ably well organized. You can probably tell that from my choice of function and variable
names and the fact that there is a crude structure to the program. But, clearly, I had let the
problem get away from me. 
The mess built gradually. Earlier versions had not been nearly so nasty. For example,
Listing 14-9 shows an earlier version in which only 
Boolean
arguments were working.
Listing 14-9 
Args.java (Boolean only)
package com.objectmentor.utilities.getopts;
import java.util.*;
public class Args {
private String schema;
private String[] args;
private boolean valid;
private Set unexpectedArguments = new TreeSet();
private Map booleanArgs = 
new HashMap();
private int numberOfArguments = 0;
public Args(String schema, String[] args) {
this.schema = schema;
this.args = args;
valid = parse();
}
public boolean isValid() {
return valid;
}
private boolean parse() {
if (schema.length() == 0 && args.length == 0)
return true;
parseSchema();
parseArguments();
return unexpectedArguments.size() == 0;
}
private boolean parseSchema() {
for (String element : schema.split(",")) {
parseSchemaElement(element);
}


207

Download 3,58 Mb.

Do'stlaringiz bilan baham:
1   ...   194   195   196   197   198   199   200   201   ...   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