Add constructors to class definitions
heuermh opened this issue · comments
Often state within fields of a class must be initialized properly before an instance of a class can be used by callers. Typically this initialization is performed in a constructor.
Constructor declarations
http://docs.oracle.com/javase/specs/jls/se7/html/jls-8.html#jls-8.8
Since ChucK does not provide constructors library authors have to rely on a pattern of static factory methods, which instantiate and return a new instance of another class. They do not prevent callers from creating instances of that class with improperly initialized fields however.
For example, the LiCK class Scales contains several static methods that instantiate and return instances of Scale.
Scales.ck, line 226
https://github.com/heuermh/lick/blob/master/Scales.ck#L226
Scales.ck, line 233
https://github.com/heuermh/lick/blob/master/Scales.ck#L233
etc.
It would be preferable to instantiate these with constructors on the subclasses of Scale themselves.
as of 1.5.2.0
chuck supports constructors!
see release notes
https://github.com/ccrma/chuck/blob/2a42d9e1a8be85cdf4526eb8817ce69683a5642e/VERSIONS#L5-L56
Thank you, @gewang