stevieb has asked for the wisdom of the Perl Monks concerning the following question:
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Request for help in method naming
by tobyink (Canon) on May 18, 2017 at 19:16 UTC | |
by stevieb (Canon) on May 18, 2017 at 19:39 UTC | |
|
Re: Request for help in method naming
by jdporter (Paladin) on May 18, 2017 at 20:09 UTC | |
by stevieb (Canon) on May 18, 2017 at 21:02 UTC | |
|
Re: Request for help in method naming
by Anonymous Monk on May 18, 2017 at 18:26 UTC | |
by stevieb (Canon) on May 18, 2017 at 18:32 UTC | |
|
Re: Request for help in method naming
by Anonymous Monk on May 18, 2017 at 18:36 UTC | |
by stevieb (Canon) on May 18, 2017 at 19:08 UTC |