News for hackers. Stuff that matters.
Re:Buttons as Finite Automata by zevv on Thursday March 24, 2022 @11:55AM (#30791658)
I am an embedded software engineer, and I love everything about this FSM example. It shows that seemingly simple and binary things often have more complexity then meets the eye. I love using old fashioned finite state machines for implementing all kinds of behavior; if forces you to think about every single state and transition, and it naturally isolates the different cases - basically, it makes it easier to think and talk about the implementation.

Buttons get even more fun when you add a "long push" to it. I can not recall how often I have had discussions with customers about the intended behavior of physical buttons on devices; it takes some effort and patience to explain how requirements like "Perform action A when the button is pushed, or perform action B when the button is pushed for a 3 seconds" simply can not be implemented. "Oh, so you mean, perform action A when the button us released within 3 seconds?". "Well, no I want it do A when I push the button".

And then I draw a little picture on the white board showing the circles and arrows.

Re:Buttons as Finite Automata by p1necone on Thursday March 24, 2022 @03:49PM (#30794546)
This isn't quite as impossible as you make it sound. You can certainly make it feel like you have this behaviour by triggering A on release if the button is held for < ~300ms, or whatever feels right as a short press.

Of course now you have to accept the button doing nothing if it's held for longer than 300ms but shorter than 3s, but making it slowly fill up with another colour or something is probably enough to communicate the long press behaviour.

Re:Buttons as Finite Automata by atoav on Thursday March 24, 2022 @03:19PM (#30794222)
You: "So you want action A to happen immediately when the button is pushed AND 3 seconds after that when the button is still held action B should happen?"

Customer: "No, I only want action B when it is held for 3 seconds"

You: "Todays technology can't do that"

Customer: "What. Wait. Why?"

You: "Because at the point when action A would be triggered we would have to know the future to tell whether the button will have been held for 3 seconds or not."

Re:Buttons as Finite Automata by recuter on Thursday March 24, 2022 @03:47PM (#30794526)
PM: "Let's not rush into any hasty answers!"

(Under no circumstances should you show them this: https://www.youtube.com/watch?v=BKorP55Aqvg)

Re:Buttons as Finite Automata by xsmasher on Thursday March 24, 2022 @05:52PM (#30795774)
This is entertaining, but also cringe; clients and product people aren't generally idiots. They just have requirements that they can't adequately express.

Requirements capture is part of every eng job I've had.

Re:Buttons as Finite Automata by xupybd on Friday March 25, 2022 @12:29AM (#30798656)
They aren't generally idiots but sometimes their mental model of the problem space is incomplete and they don't understand what they're asking for. This is fine if they don't want to specify details. However when they do it can result in impossible requests.
Re:Buttons as Finite Automata by atoav on Friday March 25, 2022 @04:15AM (#30799709)
Agreed, but as a former freelancer: Sometimes your customer doesn't know what they want and instead of figuring it out together they sketched together an internet-research-fuled plan that they want you to follow to the point, even if the plan is inefficient, doesn't solve their problem etc.

I usually managed to convince those people to come up together with a new plan while making sure they still feel like their original work is somewhat in there — after all I was the expert they came to with their issue, would be a bit idiotic to not pay for my expertise..

Sometimes this does not work, then I usually just told them I won't take that project. And projects like these don't make any sense, the customer will complain about their own planning mistakes as if it was your fault, you get angry, they get angry, everybody loses.

The best customers are those who know the problem they want to solve very well, as well as having some idea how a potential solution could look, but who thank you if you have an even better solution.

Re:Buttons as Finite Automata by recuter on Thursday March 24, 2022 @06:11PM (#30795996)
I hear you and I understand what you're saying, those are some good points. Can you express what you require out of a none cringe comedy skit that this lacks?
Re:Buttons as Finite Automata by mirekrusin on Thursday March 24, 2022 @05:42PM (#30795672)
He should be fired for not suggesting 7-dimentional plot.
Re:Buttons as Finite Automata by ggm on Thursday March 24, 2022 @07:28PM (#30796834)
Lie about immediate effect, wait 1.5sec on press A. If it was <1sec press, proceed. Otherwise, wait for another 1.5sec and then work on B modality.

It depends on the lie, but I think it probably fits human-centric timescale.

The alternative is to work on the partially ordered set of events {A, B, undo-A} and convert to {A, undo-A}, {B} and then transform to {no-op, B}

Hysteresis/Queue is your friend.

Re:Buttons as Finite Automata by thaumasiotes on Thursday March 24, 2022 @11:37PM (#30798398)
> "Oh, so you mean, perform action A when the button us released within 3 seconds?". "Well, no I want it do A when I push the button".

It seems like what's gone wrong here is not that the customer wants something impossible, but that they don't understand what you mean when you say "perform action A when the button is released".

If you show one of those people a device with the behavior you describe -- e.g. "toggle a light if the button is released within 0.5 seconds, but toggle the other light, instead, if it's pressed and held for 3 seconds" -- would they agree that it does what they say they want?

Almost everyone understands "pushing a button" to include the action of releasing the button.

Re:Buttons as Finite Automata by agumonkey on Thursday March 24, 2022 @06:00PM (#30795880)
Been reading a few books about automaton (after going back into parsing) and it's indeed nice. There's something universal in them.
Re:Buttons as Finite Automata by NoWizards on Thursday March 24, 2022 @08:00PM (#30797132)
Is there a (mathematical if possible) way, using FSMs, to demonstrate if a specific case or behavior can or can't be implemented.
Re:Buttons as Finite Automata by glitchc on Thursday March 24, 2022 @08:31PM (#30797401)
Yes there is. You may want to look into Deterministic and Non-Deterministic Finite Automata. They are foundational to computability and Turing machines.

https://en.wikipedia.org/wiki/Deterministic_finite_automaton...

Re:Buttons as Finite Automata by ThinBold on Thursday March 24, 2022 @08:52PM (#30797521)
You are designing a "prefix code". It is a collection of strings of button presses such as {A, BA, BBAA, BBABA, BBB, ...}. Each string maps to an action.

Ideally no string is a prefix of another string. Even more ideally any infinite sequence of As and Bs can be decoded into a sequence of actions.