• preprocessor (unregistered)

    #define FRIST 2

  • (nodebb)

    The solution: compare against THREE_CLICKS / TWO_CLICKS

  • NULLPTR (unregistered)

    Article published earlier than expected... Couldnt send the Nullptr in time....

  • (nodebb)

    const THREE_CLICKS = new List<Click>(3) {a,b,c};

  • P (unregistered)

    Where's the ONE_CLICK though? FWIW it could as well be

    #define ONE_CLICK          0
    

    and the HOLD constant is actually -1.

  • ray10k (unregistered) in reply to NULLPTR

    DST strikes again!

  • Q (unregistered)

    So that's how you improperly debounce a button.

  • TJ (unregistered) in reply to P

    A click is a click, you can't say it's only a half.

  • NULLPTR (unregistered) in reply to ray10k

    Not where i live. we didn't get the switchover yet.

  • (nodebb)

    I expect the interface was changed because clicking three times transported the user to Kansas...which was not the desired effect.

  • HW guy (unregistered)

    ah software people, that assume if you physically and imperfectly "click" a button once, electrically that means a single click and no additional care has to be taken for debouncing etc.

  • Scott (unregistered)

    The people I work with would use this as an example of why magic numbers are o.k. "Well, what if the value ever changed, then our name wouldn't be meaningful."

    Sigh.

  • ooOOooGa (unregistered) in reply to Scott

    I feel that.

    Because doing a search/replace to change THREE_CLICKS to SIX_CLICKS is going to be so much harder than figuring out which of the thousands of 3 literals should be changed and which shouldn't.

  • Brian (unregistered)

    I did see a case once where a numerically-named constant was pretty useful. It was an embedded system with a clock circuit in it that ran at some number of MHz. So we had a constant called ONE_SECOND (which was really a count of the number of ticks in a second) that tended to get used a lot in timing loops - e.g. 5 seconds would be 5 * ONE_SECOND.

    I think at one point during development we had to change the clock to one with a different frequency. So yes, the value of ONE_SECOND did actually change.

  • foo (unregistered)

    Changing THREE_CLICKS to equal 3 violates our internal coding conventions, page 254, section 5: "Each constant shall only be defined once, using a single, clear identifier"

    We suggest the following change to achieve compliance: if (clickCount == PI)

  • (nodebb)

    3 equals 6 for sufficiently large values of 3, and sufficiently small values of 6…

  • Jaloopa (unregistered) in reply to Brian

    What's wrong with TICKS_PER_SECOND?

  • (nodebb) in reply to Brian

    In your example, the name is wrong, should've been TICKS_PER_SECOND

  • NotThatJim (unregistered)

    Constants aren't. Variables don't.

  • Bruce W (unregistered)

    Back in 1995 I tested an application that crashed if you triple clicked on an item. The developers told me that "no one with ever triple click!" I wonder if the same developer went on to work on this system and hated the idea that triple clicking was a feature.

  • Kleyguerth (github) in reply to Bruce W

    I wonder how old is the "triple click to select paragraph" feature. I use it all the time, maybe that developer hates most text processors and browsers.

  • DON'T Shut the fuck up (unregistered) in reply to Mr. TA

    THIS IS A GOOD POINT

  • Dave (unregistered) in reply to Mr. TA

    Should it be ticks per second? Ticks/s is a rate, one second is a unit of time. It could perhaps be ticks in one second, but that's a silly way to name something you use all the time.

  • (nodebb) in reply to TJ
    A click is a click, you can't say it's only a half.

    Let me introduce you to the square root of NOT : https://en.wikipedia.org/wiki/Quantum_logic_gate

  • (nodebb)

    Trust, but verify your constants!

  • Another Anon (unregistered) in reply to sibtrag

    If so, then the software was probably developed in Ruby.

  • (nodebb) in reply to HW guy

    Why would you assume this example in the article isn't debounced?

  • Hasseman (unregistered)

    1-1+1-1+1- ... = 1/2 https://en.wikipedia.org/wiki/Grandi%27s_series

  • Prime Mover (unregistered)

    I can't see where your confusion lies. It's all perfectly simple.

    "Click" is a sound that is sometimes transliterated as "!".

    So "two clicks" is "2!" that is, 2 factorial. Similarly, "three clicks" is "3!", that is, 3 x 2 x 1 = 6.

  • (nodebb) in reply to DON'T Shut the fuck up

    I make only good points, including this one.

  • (nodebb) in reply to Jaloopa

    Great minds think alike.

  • sizer99 (google) in reply to Sulis

    Yeah, I'm not seeing debounce issues here. Even the ten year old SOC we're using on one of the projects has hardware debounce which works great on our three buttons - false triggers have never been one of our problems. I have some code in there to flag an error if you see an impossible up/down time, because I have had to do extra debounce before and was paranoid, but it's never been activated.

    The 6 is because you get one interrupt when the switch closes and one when it opens, so 2 events is a full click and release and 6 events is 3 full clicks. ... Or so someone thought, but apparently they've configured it to only activate on one of those events.

  • X (unregistered)

    The code base I am working on defines ZERO through SIX. Though at least they are what you’d expect.

  • Some Ed (unregistered) in reply to Brian

    If your environment has a substantial difference between "the number of ticks per second" and "a count of the number of ticks in a particular second", you have bigger issues than you're going to be able to handle in a constant. Alternatively, if the number of ticks per second isn't documented, such that to find out the number, you had to have your software count while someone provided it some reference start and stop points for a second, and then averaged those to get the "actual" number, ... I think you just have problems.

    Also, I do realize in the latter scenario I provided that the sample size is most likely going to be one in any given instance. But sometimes I apparently like to type a lot to make up for all the keystrokes I didn't need to use because I know how to code somewhat efficiently.

  • (nodebb) in reply to Dave

    5TICKS_PER_SECOND reads like a rate (five ticks per second). If it's supposed to represent five seconds, then 5SECONDS scans better.

    (5 sec * T ticks/sec = 5T ticks).

  • just some guy (unregistered) in reply to Watson

    Exactly. You have seconds, but the function you're calling needs ticks, so you need a SECONDS_TO_TICKS conversion factor.

  • Olivier (unregistered)

    What about ONE_SECOND_WORTH_OF_TICKS, isn't that a cool name?

  • 🤷 (unregistered) in reply to Bruce W

    The developers told me that "no one with ever triple click!"

    I once thought "No one will ever double click a button!" But users taught me a lesson. Yes, some people double click a button and then the function behind that button click will execute twice. At least it didn't crash the application, it was just a minor annoyance that the underlying database operation (a SELECT) would get logged twice. So I did what every sane person would: Deactivated the button for two seconds after a single click occured.

  • 🤷 (unregistered) in reply to Watson

    If it's supposed to represent five seconds, then 5SECONDS scans better.

    At least go all the way in. 5ECOND5. There.

  • Co_RNeR (unregistered) in reply to 🤷

    I would lock the user_account, but then I'm an Evil developer...

  • EmbeddedSpree (unregistered)

    The problem is naming anything a "single click", "double click" or "triple click" in the first place. Simply changing "THREE_CLICKS" to "TRIPLE_CLICK" (or for that matter "THIRD_CLICK") merely would change the form of the word "three". What we really should do, is name these actions by their semantics - "select", "confirm", "cancel" or whatever. The word "CLICK" is the real WTF, especially when everybody except me seems to have a touch device when they don't "click" anything.

    It's just unfortunate that we named these actions "double-click" and so on all those years ago.

    (Sent via e-post from [email protected])

  • EmbeddedSpree (unregistered) in reply to Some Ed

    Re: "lternatively, if the number of ticks per second isn't documented, such that to find out the number, you had to have your software count..."

    On early PCs (4.77Mhz and 8Mhz era) Borland Turbo Pascal's clock unit (library) did this in a tight loop to get an approximation of the system clock rate. In the absence of a real-time clock, there wasn't really any other way to do it. Of course, it relied on instructions having a known number of cycles to execute (no fancy caches, instruction prefetch, etc ).

  • Stephen Cleary (unregistered)

    Still lives on in .NET Core: https://docs.microsoft.com/en-us/dotnet/api/system.timespan.tickspersecond?view=netcore-3.1

  • Raul (unregistered) in reply to Hasseman
    1-1+1-1+1- ... = 1/2

    That is not and never will be true. What is true is that CesaroSum(1,-1,1,-1,1,-1,...) = 1/2, but Cesaro sums aren't the same as =.

Leave a comment on “Three's a Constant”

Log In or post as a guest

Replying to comment #:

« Return to Article