boost-ext / sml

C++14 State Machine library
https://boost-ext.github.io/sml
Boost Software License 1.0
1.14k stars 177 forks source link

Is SML ready to be used in production? #138

Open ooxi opened 6 years ago

ooxi commented 6 years ago

I'm currently in the process of evaluating different options for implementing a rather complex state machine for an embedded target. This library seems to be the most polished one so far, using modern language concepts. Also I watched two talks about Boost.SML and was quite impressed.

However I'm a bit concerned about the current state of development with the latest version being 1.0.1, released more than a year ago. Therefore I would like to ask you if you could honestly recommend using this library in production for an embedded target (Atmel SAMD21, thus quite memory and performance restrained).

ooxi commented 6 years ago

Sooo... I'll guess not that ready to be used in production? :D

splitsen commented 6 years ago

@ooxi May be you should start with boost-msm using the eUML syntax, and then update to sml later, AFAIK the syntax is more or less identical.

ooxi commented 6 years ago

Thanks for the hint!

sebkraemer commented 6 years ago

I'm working on a project with boost-msm and I think the migration to boost-sml would take a lot of rewriting. Especially dependency handling is rather different, dependency injection not being available in boost-msm (at least not in the way I'm seing it in sml). That being said, boost-msm is hard on the compiler for projects of a certain size, but it's working pretty reliably for us.

splitsen commented 6 years ago

I'm using too msm in a very big cross-platform project, sure it is very reliable, elegant, easy to maintain, etc, but ... As the transition table grow, compilation time explode, even fail if RAM is too low , that is very annoying, and as sml looks far better, I'm very interested but current version has a lot of compilation failures, especially with Visual Studio 2015. @kris-jusiak maybe you could enlighten us on a boost submission date !

sebkraemer commented 6 years ago

Same here. boost-msm sure has its well-known drawbacks.

freak82 commented 6 years ago

We've been used in production for about year and half. We use it for the http state machine in our http cache proxy. Also for the state machines in the caching subsystem of the proxy. However, I use limited set of it's features: initial sate, states, events, guards and orthogonal regions. In addition, I've added external error handling for the case when there is no transition on given event. I couldn't get the author attention at the time (See: 'A question about the behavior of unexpectedevent<> vs unexpected_event. #85' and 'Another question about the behavior of unexpectedevent<> vs unexpected_event #86'). This is important feature, for me, which is present in the MSM library. I use it to ensure at run time that there are no hidden bugs in my transition tables. Although I've used MSM in other projects, for this one it was really no go for me especially for the HTTP state machine due to the compilation time. In addition, I find the syntax of SML much cleaner due to the new C++ features.

sjtuhjh commented 6 years ago

@ooxi , have you tried boost sml in production for an embedded target ?

ooxi commented 6 years ago

@sjtuhjh I have not, since I received mixed feedback on this issue. While I'm very impressed with this library and would like to use it, betting on it for an embedded project is a huge liability.

I might have to take over maintaining this library, if the API changes drastically or support is dropped.

ooxi commented 6 years ago

@sjtuhjh fyi: we are now using Boost.SML in production for an embedded project. Up until now it works fine for our (simple) use cases, but we are not sure how to model hierarchical state machines with Boost.SML (see issue #185)

indiosmo commented 6 years ago

I've been using it in production as the basis of my networking library where the protocol state machines are implemented using SML.

@ooxi I added an example of the hierarchical machine in one of the protocols to #185.

edobez commented 5 years ago

Have you ever considered using QP (https://www.state-machine.com/) for embedded applications?

ooxi commented 5 years ago

Thanks for the suggestion @edobez, I have not heard of QP before. While it looks like a comprehensive framework, the state machine part does not look too appealing.

Are you familiar with QP? Most likely I'm overlooking something, but a state machine definition like in this blinky example does not look very maintainable, at least compared to the Boost.SML version. Or was this source code generated from a DSL?

edobez commented 5 years ago

I'm a bit familiar with QP since I am evaluating it right now for an application at my company. I have to agree that the appearance of QP state machines is not on par with Boost.SML, but I think that in part it is intentional. Since QP is targeted at embedded developers which are mostly used to C programming, the framework could not be developed using too much modern C++, otherwise it would have been perceived with something not understandable by its user base. Please note that this is only my opinion. Also, it would be interesting to see some performance comparisons between the two.

The example you cite is not generated by a DSL, but there is a tool called QM, part of QP, that can generate the state machine code from a graphical representation, similar to UML. At the beginning reading through the state machine code can be a little confusing but I have to say that once you understand it, it becomes clear and quite simple to use.

rhvonlehe commented 5 years ago

QP is great, whether you use the entire framework or just the state machine part. I used the whole framework, including QP-nano which is an extremely tiny scheduler. I highly recommend it. My main interest in Boost.SML is that it won't require a commercial license as QP does but should still scale all the way down to extremely small microcontroller footprints.

EDIT: QP's state machine implementation is available in C++ as well (C++98 I believe). EDIT2: I echo that once you use QP, it becomes second nature. I have to say I'm not convinced Boost.SML can do all the things that QP can do, and I really want it to (because it's free). I look at the examples for composite states and I am still left wanting. In the composite example, there are asserts checking each submachine's state as you make your way through a simple hierarchical state machine. That's BS, because you are only ever in one state globally. It makes no sense to check a submachine's state if you aren't in that submachine, but the result in that example shows you are in the "idle" state within that substate even though you haven't visited that substate yet. Ultimately, his abstraction here seems very wrong. Also, there is no good example for a non-trivial HSM given in the SML documentation that I can find. For example, nothing shows how to create a transition out of a nested state into a base state, much less doing this for double-nested state.