We actually have a fairly decent body of code which includes over 500 classes. Below is a script which dumps how various constructors are used (the script is a lot shorter than the results). I'll be going thru these results more carefully and posting my thoughts. But my initial observations:
Over 30% of classes have a compiler generated synthetic make ctor
56% of classes have a constructor with arguments (although many were designed before with-blocks)
Only 6% of code has multiple constructors, virtually all of those in compiler and haven, and almost about all of them are easily reworked
Err classes scream for parameter based constructors since all of them take Str, Err as their first two optional parameters (and also scream for the ArgErr("bad arg") syntax)
Location is a good example where multiple constructors are handy and where the constructor does a non-trivial transformation of File to a Str.
Compiler Exprs are probably the most extensive use of constructors in the code base using multiple constructors with subclass chaining that isn't just "pass-thru"
Pretty much every manually coded, no arg constructor only does initialization and validation
If you tried to do that in Java it would be more than a thousand lines of code.
How often I've wanted to iterate through Java's notion of a Pod....
jodastephenFri 18 Jul 2008
I'd be particularly interested in how many times (and in what circumstances) a construction-with-block sets a const field (or performs any other operation that is disallowed for a normal-with-block. Also how many times both a () constructor and construction-with-block are paired together.
brian Fri 18 Jul 2008
We actually have a fairly decent body of code which includes over 500 classes. Below is a script which dumps how various constructors are used (the script is a lot shorter than the results). I'll be going thru these results more carefully and posting my thoughts. But my initial observations:
ArgErr("bad arg")
syntax)File
to aStr
.JohnDG Fri 18 Jul 2008
If you tried to do that in Java it would be more than a thousand lines of code.
How often I've wanted to iterate through Java's notion of a
Pod
....jodastephen Fri 18 Jul 2008
I'd be particularly interested in how many times (and in what circumstances) a construction-with-block sets a const field (or performs any other operation that is disallowed for a normal-with-block. Also how many times both a () constructor and construction-with-block are paired together.