R
Roedy Green
I decided to update a little program I wrote for my personal use. It
was very much a one-shot, quick and dirty.
But in coming back to do a simple change -- move the data from
internal to the program to external CSV files, the work took a lot
longer than it should have.
If I had this to do over:
1. always document variables. In particular I did not document
whether various arrays always had an entry for each day or just
selected days in a range.
2. When you have to do a theme and variations DON'T copy clone the
code and modify. Encapsulate the common part. Otherwise the common
part will gradually diverge over time and be harder and harder to
maintain.
3. keep asking yourself, is this piece of code even POTENTIALLY
reusable. If so, bundle it up, and keep the application specific code
out of it.
4. get very clear on responsibility areas and the interfaces between
them so you know exactly where any given piece of code belongs.
It is not good enough to get the code in the stream somewhere. It must
go at the right responsibility point.
5. Rather than displaying error messages, throw an exception you catch
at a higher level and treat them in a consistent way. Otherwise you
will find messages being ignored or sent to a mixture of System.out
and System.err.
was very much a one-shot, quick and dirty.
But in coming back to do a simple change -- move the data from
internal to the program to external CSV files, the work took a lot
longer than it should have.
If I had this to do over:
1. always document variables. In particular I did not document
whether various arrays always had an entry for each day or just
selected days in a range.
2. When you have to do a theme and variations DON'T copy clone the
code and modify. Encapsulate the common part. Otherwise the common
part will gradually diverge over time and be harder and harder to
maintain.
3. keep asking yourself, is this piece of code even POTENTIALLY
reusable. If so, bundle it up, and keep the application specific code
out of it.
4. get very clear on responsibility areas and the interfaces between
them so you know exactly where any given piece of code belongs.
It is not good enough to get the code in the stream somewhere. It must
go at the right responsibility point.
5. Rather than displaying error messages, throw an exception you catch
at a higher level and treat them in a consistent way. Otherwise you
will find messages being ignored or sent to a mixture of System.out
and System.err.