Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^2: Implementing a 2-mode "Audiobutton" on the Raspberry Pi

by cavac (Curate)
on Oct 29, 2018 at 15:37 UTC ( #1224858=note: print w/replies, xml ) Need Help??


in reply to Re: Implementing a 2-mode "Audiobutton" on the Raspberry Pi
in thread Implementing a 2-mode "Audiobutton" on the Raspberry Pi

In many cases, yes, you are right. But in this case, at least in my opinion, the usage is quite clear. The switch could either be on (1) or off(0) or we don't know yet (-1 = number that could never happen otherwise). And i even bothered to document it:

my $lastswitch = -1;

The whole $lastswitch thing could just be set to 0 on startup in theory (guessing the button isn't pressed on startup). Or i could just replicate the Device::BCM2835::gpio_lev($testpinnumber) call at the beginning.

I just kept this one-off script for my one-off device to my usual style guide of 15+ years of Perl coding. If i see that construct, i instantly know i'm dealing with an uninitialized boolean. Same goes for other "magic" numbers. 3600 is seconds per hour, 86400 is seconds per day and 365.25 is (average) days per year.

Those kinds of magic numbers i wouldn't call "bad", it's more of a grey area.

I can completely understand your point of view, and in most cases i'd support you all the way, but i hereby invoke my right of TIMTOWTDI 😉

perl -e 'use MIME::Base64; print decode_base64("4pmsIE5ldmVyIGdvbm5hIGdpdmUgeW91IHVwCiAgTmV2ZXIgZ29ubmEgbGV0IHlvdSBkb3duLi4uIOKZqwo=");'

Replies are listed 'Best First'.
Re^3: Implementing a 2-mode "Audiobutton" on the Raspberry Pi
by hippo (Chancellor) on Oct 29, 2018 at 16:08 UTC
    3600 is seconds per hour, 86400 is seconds per day

    Yesterday in the UK we had 90,000 seconds. In the hour from 1am to 2am we had 7200 seconds. Magic numbers will get you in the end.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1224858]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2021-02-25 00:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?