ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Peter Donald <>
Subject Re: Ant Coding guidelines
Date Tue, 15 Jan 2002 07:59:09 GMT
On Mon, 14 Jan 2002 22:26, Stephane Bailliez wrote:
> Peter, could you please clarify your conventions and send me your IDEA
> configuration file for layout as well.

The typographics conventions is basically MS style with lower case instead of 
upper case as first letter. Also the names of things tend to be full names 
rather than abreviations. There is a document explaining it on avalon website 
- maybe /avalon/code-conventions.html ?? (I think).

However most of the conventions have less to do with typpographic features 
and more to do with structure of the code. 

For instance I try to never have any non-private mutable variables at all - 
they are acccessed via accessors/mutators. In a similar way all methods are 
as private as possible. This is to ease evolution (you can always change 
stuff later if no one but you could get to it). 

I also try to make every variable/method I use as final as possible. For 
variables this stops recycling variables for different purposes because they 
can only be assigned once. It also makes it easy for a more controlled 
evolution if you know which methods will be possible to be overidden by users.

The above also has the side effect of reducing the size of methods because 
people who would previously recycle variables now end up having variables 
named val1, val2, val3 which is always easy to spot and refactor into smaller 
reusable chunks.

Then there are other various rules of thumb (ie 3 levels of braces implies 
there should be a new method and so forth). That I am not sure are documented 
anywhere exactly ;)

These sort of principles also cross over into what I have been doing with the 
tasks. Many of the tasks I have touched now have a validate() method which 
contains all the validation code. 

So tasks that previously validated the attributes in the setter have now had 
the validation placed in the validator method and everything has been put 
into separate "phases". ie set attributes, validate and clean/prepare 
attributes, then execute.

I also tend to prefer delegation over inheritance but this is a pattern that 
already exists throughout ant (or has evolved to exist). For instance 
<inclde/> functionlity was originally cut and paste jobe between tasks, then 
they started to inherit from MatchingTask (or whatever it is called) then 
that was deprecated and we have FileSets that are delegated to etc.

Most of these things I use to keep code as simple and as agile as possible. 
Some "feel" sucky at first (putting finals before all variables) but end up 
being worth it in the long run (and I don't even notice it anymore).



 "No. Try not. Do. Or do not. There is no try." 
                                     -- Yoda 

View raw message