Greetings Brethren,
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 :) }
...and I'm sure there are many others :). As this is intended for a CPAN module rather than supporting any specific piece of code, I have no 'in-house' style guidelines to follow, and I don't really know how potential users will want to use the module (or even if there *are* any potential users except for myself :) ), so want to make it as intuitive and consistent as possible. I guess that it'll most often be called as part of a loop in code that'll only be dealing with single 'from' and 'to' formats - hence the package default idea ( so that I'm not having to read/parse the format types for every call).
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
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.