Theoretical question bound for opinionated answers alert...

So in my GPS distribution, I've decided that I want to make certain items toggle-able. First, some informational aspects are measured in metres-per-second by default. These include altitude, current speed and current lateral movement. I am trying to design a mechanism whereby someone presses a button (calls a method) it toggles between metric (metres) and imperial (feet). The other toggle I am creating is turning a signed decimal (latitude and longitude) into it's (for lack of better terms that I don't know yet) "English" counterpart. An example of this would be converting -114.1234567 into 114.1234567W (note the 'W' at the end).

At first, I was only converting these internally, and only if a param was sent into the object instantiation method (new()). I have decided I want to make this functionality available at runtime.

Now, at first, when the code was only being init in new, it was simple. I had a _metric() and _signed() methods. They make sense internally to me and to the software. The program run will either be metric or not, and signed or not.

To expose these two options as methods, I can't think of a good name for them that encompasses what they do. For the 'metric' conversion, I plan on declaring like this: sub_name($decimal);. I could just work on the innards of the object where the relevant pieces are stored, but it would be handy for testing and other instances to be able to throw in any numbers, not just what we've collected. The declaration for the conversion of signed to "English" will be something like: sub_name($lat, $lon);.

Internally, there's already a check to see whether something is metric or signed or not, so the toggle piece already works. It's the names I'm looking for. I don't want something crude like convert_lat_lon(). The name metric() *could* stand, but when going from metric to imperial, I kind of just don't like it.

Looking for any and all suggestions for the naming conventions of these two simple methods :)

Because it's Perlmonks, here's some untested code that I started to write before I came here for some insight...

sub metric { my ($self, $stat, $metric) = @_; if ((! defined $metric || ! $metric) && ! $self->_is_metric) { $stat = $stat * 3.28084; $self->{tpv}{$_} = substr($stat, 0, index($stat, '.') +1 +3); $self->_is_metric(1); } }

At the time, I was considering using the metric name and throwing in an extra param, but I really don't like that.


In reply to Request for help in method naming by stevieb

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.