Advocating for programmer ergonomics is always a good thing. And I think more people should advocate and try to design languages in such a way that the way of programming more closely resembles the actual real thing [1, 2]. As you might recall in cognitive psychology there's a specific idea that translating a problem to a more recognizable problem (or simply changing the symbols) is a good thing [3]. Having less work…
While I love Bret's work I don't think that's scalable. If you can simulate time axis, it means it can simulate only systems that can are hundreds of times smaller than system resource. E.g. can you simulate a Kubernetes swarm with thousands of different settings? It's a great learning tool, but not much else.
State Machines in Rust
21–30 of 119 posts
Re: State Machines in Rust
#22> In Germany traffic lights go green -> yellow -> red -> yellow -> green, but let's pretend they're only green -> yellow -> red -> green.
is not correct if I'm not missing something major. Is there any situation where they turn yellow before turning green?
Re: State Machines in Rust
#23Slightly OT, but: > In Germany traffic lights go green -> yellow -> red -> yellow -> green, but let's pretend they're only green -> yellow -> red -> green. is not correct if I'm not missing something major. Is there any situation where they turn yellow before turning green?
Re: State Machines in Rust
#24Once upon a time I have implemented POP3 server protocol state machine in Clojure. 180 lines in total, of which 40 were FSM declaration, 140 command handling functions. Not sure I'll ever want to approach FSM in any other language, unless no other choice.
Re: State Machines in Rust
#25Slightly OT, but: > In Germany traffic lights go green -> yellow -> red -> yellow -> green, but let's pretend they're only green -> yellow -> red -> green. is not correct if I'm not missing something major. Is there any situation where they turn yellow before turning green?
Re: State Machines in Rust
#26Who is Yoshua Wuyts?
Re: State Machines in Rust
#27C++20 supports enums as non-type template parameters, so I think it'd be possible to do it with enums there. Something like: enum class Color{Green, Yellow, Red}; template struct State{}; auto newState() -> State {...}; auto next(State ) -> State {...} auto next(State ) -> State {...} auto next(State ) -> State {...} int main(){ const auto state = newState(); // Green const auto state = next(state); // Yellow const a…
https://play.rust-lang.org/?version=nightly&mode=debug&editi...
#![feature(const_generics)]
#[derive(PartialEq, Eq)] // enums used as const generics must be Eq
enum Color { Green, Yellow, Red }
struct State;
impl State { fn next(self) -> State { State } }
impl std::fmt::Debug for State { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { f.write_str("green") } }
impl State { fn next(self) -> State { State } }
impl std::fmt::Debug for State { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { f.write_str("yellow") } }
impl State { fn next(self) -> State { State } }
impl std::fmt::Debug for State { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { f.write_str("red") } }
impl State { fn new() -> Self { State } }
fn main() {
let state = dbg!(State::::new());
let state = dbg!(state.next());
let state = dbg!(state.next());
let state = dbg!(state.next());
}
Output: [src/main.rs:20] State::::new() = green
[src/main.rs:21] state.next() = yellow
[src/main.rs:22] state.next() = red
[src/main.rs:23] state.next() = greenRe: State Machines in Rust
#28Here is the initial paper from David Harel: STATECHARTS: A VISUAL FORMALISM FOR COMPLEX SYSTEMS (1987) - https://www.inf.ed.ac.uk/teaching/courses/seoc/2005_2006/res...
Website with lots of info and resources: https://statecharts.github.io/
And finally a very well made JS library by David Khourshid that gives you lots of power leveraging statecharts: https://github.com/davidkpiano
While we're at it, here are some links to previous submissions on HN regarding statecharts with lots of useful and interesting information/experiences:
- https://news.ycombinator.com/item?id=18483704
- https://news.ycombinator.com/item?id=15835005
- https://news.ycombinator.com/item?id=21867990
- https://news.ycombinator.com/item?id=16606379
- https://news.ycombinator.com/item?id=22093176
My own interest in Statecharts comes from wanting/trying to use them for UI development on the web, think there is lots of value to be had and time to be saved by using leveraging it.
Re: State Machines in Rust
#29Once upon a time I have implemented POP3 server protocol state machine in Clojure. 180 lines in total, of which 40 were FSM declaration, 140 command handling functions. Not sure I'll ever want to approach FSM in any other language, unless no other choice.
Did you iterate to a FSM solution, from many nested conditions, or use it right from the start? I'm fighting the urge to write any FSM without having the absolute certainty that it is needed. There seems no other way than by refactoring to an FSM.
Re: State Machines in Rust
#30Once upon a time I have implemented POP3 server protocol state machine in Clojure. 180 lines in total, of which 40 were FSM declaration, 140 command handling functions. Not sure I'll ever want to approach FSM in any other language, unless no other choice.
Can you perhaps point to it? Sounds interesting to read that code!
https://gist.github.com/juskrey/61148c98bdde871a8d3743f54b82...
https://gist.github.com/juskrey/127cf8456fc527d20ed5e244ce01...