- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
#define FRIST 2
Admin
The solution: compare against THREE_CLICKS / TWO_CLICKS
Admin
Article published earlier than expected... Couldnt send the Nullptr in time....
Admin
const THREE_CLICKS = new List<Click>(3) {a,b,c};
Admin
Where's the
ONE_CLICK
though? FWIW it could as well beand the
HOLD
constant is actually-1
.Admin
DST strikes again!
Admin
So that's how you improperly debounce a button.
Admin
A click is a click, you can't say it's only a half.
Admin
Not where i live. we didn't get the switchover yet.
Admin
I expect the interface was changed because clicking three times transported the user to Kansas...which was not the desired effect.
Admin
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.
Admin
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.
Admin
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.
Admin
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.
Admin
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)
Admin
3 equals 6 for sufficiently large values of 3, and sufficiently small values of 6…
Admin
What's wrong with TICKS_PER_SECOND?
Admin
In your example, the name is wrong, should've been TICKS_PER_SECOND
Admin
Constants aren't. Variables don't.
Admin
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.
Admin
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.
Admin
THIS IS A GOOD POINT
Admin
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.
Admin
Let me introduce you to the square root of NOT : https://en.wikipedia.org/wiki/Quantum_logic_gate
Admin
Trust, but verify your constants!
Admin
If so, then the software was probably developed in Ruby.
Admin
Why would you assume this example in the article isn't debounced?
Admin
1-1+1-1+1- ... = 1/2 https://en.wikipedia.org/wiki/Grandi%27s_series
Admin
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.
Admin
I make only good points, including this one.
Admin
Great minds think alike.
Admin
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.
Admin
The code base I am working on defines ZERO through SIX. Though at least they are what you’d expect.
Admin
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.
Admin
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).
Admin
Exactly. You have seconds, but the function you're calling needs ticks, so you need a SECONDS_TO_TICKS conversion factor.
Admin
What about ONE_SECOND_WORTH_OF_TICKS, isn't that a cool name?
Admin
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.
Admin
At least go all the way in. 5ECOND5. There.
Admin
I would lock the user_account, but then I'm an Evil developer...
Admin
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])
Admin
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 ).
Admin
Still lives on in .NET Core: https://docs.microsoft.com/en-us/dotnet/api/system.timespan.tickspersecond?view=netcore-3.1
Admin
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 =.