benn has asked for the wisdom of the Perl Monks concerning the following question:
I'm about to plunge into some code to convert various musical note formats back and forth - "BB-" <->"Bb2" <->"bf3" etc. Looking around, I guess there are between 5 and 10 different formats that I'll eventually want to build in.
My problem is how to structure this. Possible options would appear to be...
- Provide (up to 100!) different methods for each conversion (ugh). More work for me, but with a consistent naming scheme (abc2kern(), kern2midi(), midi2abc() etc.), possible easier for the user - a simple list of format names would provide every possible method name.
- As above, but use AUTOLOAD or similar to 'generate' the method - split up the method name and call "convert($1,$2,$argument)"
- All passed as parameters to a single method - convert("BB-","kern","abc").
- As above, but 'autodetect' the original style - convert_to("BB-","abc") - slightly problematic, but possible.
- Named param style - convert(note=>"BB-",from=>'kern",to=>"abc")
- OO style - notetype->new("BB-","kern")->convert_to("abc).
- 'No param' OO style - notetype->new("BB-","kern")->as_abc()
- Use package variables to set defaults - $::INPUT="kern"; $::OUTPUT="abc"; convert("BB-");
- {Fill in your own favourite here :) }
One wrinkle is that different formats may require / return additional parameters - ABC format, for instance, sets up a key and a default octave as part of its header, so they may need to be passed in ("F" in the key "D" would convert to "F#" etc.).
Atm, I'm favouring the named parameter style (easy to maintain and pass extra parameters ) but I'd be grateful for any input before I "get my coding pencil out" :)
Cheers,
Ben.
Title edit by tye
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: A Matter of Style...
by Skeeve (Parson) on Aug 12, 2003 at 11:27 UTC | |
Re: A Matter of Style...
by Juerd (Abbot) on Aug 12, 2003 at 11:27 UTC | |
Re: A Matter of Style...
by dragonchild (Archbishop) on Aug 12, 2003 at 13:06 UTC | |
Re: A Matter of Style...
by fglock (Vicar) on Aug 12, 2003 at 12:37 UTC | |
by benn (Vicar) on Aug 12, 2003 at 12:56 UTC | |
Re: A Matter of Style...
by benn (Vicar) on Aug 12, 2003 at 14:09 UTC |