* sudo add-apt-repository ppa:openjdk-r/ppa
* sudo apt-get update -q
* sudo apt install -y openjdk-11-jdk
* Clone this repo
* install ant by running 'sudo apt-get install ant'
* then go to the folder where you have cloned this repo
* Run 'ant compile'
* Run 'ant jar'
* Run 'java -cp build/jar/args.jar com.cleancoder.args.Arguments'
* Run the command given below from the root folder of this repo
* Run 'java -cp "lib/junit-4.13.jar:lib/hamcrest-core-1.3.jar:build/jar/args.jar" ./test/com/cleancoder/args/ArgsTest.java testCreateWithNoSchemaOrArguments'
[Ref. Clean code by Robert C. Martin and class slides]
-
a. Naming:
- [OUT OF THE BOX] Class name
ArgsMain
has been changed toArguments
to avoid mental mapping and because classes should have noun or noun phrase names and to avoid mental mapping. - Changed
e
toexception
b. Visual Design of Code:
- Unifying list of arguments i.e. arguments in separate lines
- Removed extra whitespaces and newlines
- [OUT OF THE BOX] Removed extra curly braces that reduce the readability of the code
c. All methods now follow noun-verb naming convention.
- [OUT OF THE BOX] Class name
-
a. Naming: "A long descriptive name is better than a short enigmatic name. A long descriptive name is better than a long descriptive comment."
- Variable
schema
changed toargSchema
for reflecting the components of the schema. - Method
parseArgumentStrings
changed toparseListofArguments
for better readability and to provide better and descriptive names. - Changed
elementTail
toelementSymbol
. - Changed
argsList
tolistOfArgs
for better readability. - Renamed method
parseArgumentCharacter
tosetMarshaler
. - Renamed meaningless variables
m
ande
to more meaningful name likematchedMarshaler
,err
respectively. - Renamed method
has
tohasFoundArgument
b. Reduced number of function arguments for:
parseSchema()
andparseListofArguments()
by declaring all variables in the entire scope of the classArgs()
.- Passed
element
to methodputIntoMarshaler
instead of passingelementId
andelementSymbol
separately.
c. Functions must do exactly one thing:
- Broke down
parseSchemaElement
method intoparseSchemaElement
andputIntoMarshaler
corresponding to the two fuctions/actions which were being preformed. - Broke
parseArgumentCharacters
method intomatchMarshaler
andsetMarshaler
corresponding to the two fuctions/actions which were being preformed.
d. [OUT OF THE BOX] Order of functions changed according to: "put the private utilities called by a public function right after the public function itself. This follows the stepdown rule and helps the program read like a newspaper article."
e. [OUT OF THE BOX] Using inbuilt function
isBlank()
to check for blank or empty strings instead ofelement.length() > 0
.f. [OUT OF THE BOX] In method
parseSchemaElement
, to avoid using hardcoded indices for e.g. -char elementId = element.charAt(0);
used variables instead -
int index = 0; char elementId = element.charAt(index);
f. [OUT OF THE BOX] To improve the scalability of the code, a HashMap
marshalersMappedToSymbols
(that maps each schema symbol to its corresponding marshaler) has been added. Now, in the case of adding a new Marshaler type, one just needs to add an entry of the formput("Symbol", marshalerType());
in the hashtable, and a corresponding get function at the end of the class.g. [OUT OF THE BOX] Added new utility functions to improve the readability of if-else statements. For example: Changed
if(!Character.isLetter(elementId))
toif(isNotLetter(elementId))
.h. Visual Design of Code:
- Unifying list of arguments i.e. arguments in separate lines
- Removed extra whitespaces and newlines
- Removed extra curly braces that reduce the readability of the code
i. All methods now follow noun-verb naming convention.
- Variable
-
a. Naming:
- Changed
am
toargsMarshaler
- Changed
e
toexception
b. [OUT OF THE BOX] Functions must do exactly one thing: Divided method
set
into three methodsset
,parseEntry
andputInMap
where:set
: parses the list of entriesparseEntry
: parse each entry into its entry components and checks their length making sure each entry has one key-value pair.putInMap
: Inserts each key-value pair into the map.
c. Visual Design of Code:
- Unifying list of arguments i.e. arguments in separate lines
- Removed extra whitespaces and newlines
- Removed extra curly braces that reduce the readability of the code
d. All methods now follow noun-verb naming convention.
- Changed
-
BooleanArgumentMarshaler.java, StringArgumentMarshaler.java, StringArrayArgumentMarshaler.java:
a. Naming:
- Changed
am
toargsMarshaler
- Changed
e
toexception
b. Visual Design of Code:
- Unifying list of arguments i.e. arguments in separate lines
- Removed extra whitespaces and newlines
- Removed extra curly braces that reduce the readability of the code
c. All methods now follow noun-verb naming convention.
- Changed
-
IntegerArgumentMarshaler.java, DoubleArgumentMarshaler.java
a. Naming:
- Changed
am
toargsMarshaler
- Changed
e
toexception
- Changed
parameter
to a more meningful and descriptive nameargValue
b. Visual Design of Code:
- Unifying list of arguments i.e. arguments in separate lines
- Removed extra whitespaces and newlines
- Removed extra curly braces that reduce the readability of the code
c. All methods now follow noun-verb naming convention.
- Changed
- Corrected name of method
malFormedMapArgument()
tomalformedMapArgument()
- Corrected name of method
malFormedMapArgumentExcess()
tomalformedMapArgumentExcess()
- Corrected test corresponding to
malformedMapArgument()
- Added a test for negative numbers
- Added a test discovering a multiple flag function i.e. -xy 7 3.6