[ragel-users] Re: Any suggestions on implementing SMTP protocol inRagel?
Zed A. Shaw
zeds... at zedshaw.com
Wed May 14 06:09:10 UTC 2008
On Tue, 13 May 2008 06:43:39 -0700
Erich Ocean <er... at atlasocean.com> wrote:
> Statecharts are trivial to code by hand, using case and switch
> statements, and result in roughly the same amount of code as a
> straight Ragel implementation would. In addition, the hand-coded
> variants are more flexible, since you can implement the full "spec" as
> designed by Harel. You can also easily embed Ragel regex-style
> machines in the various states as needed when you hand code, and
> Adrian's code generation approach makes that particularly easy.
It is easy to code simple ones, but hand-coded ones have the following
1) Nobody can read the mass of case/switch crap later on, not even the
dude who wrote it initially.
2) Debugging them is a pain in the ass, usually involving tracing
3) The compiler can't tell you if you have cycles, invalid
transitions, and doesn't minimize your states. Ragel does all that.
4) You can't generate dot graphs from your stuff.
Now, what I've done in the past to remove 1-3 is to use statecharts
implemented as C macros and function call semantics. You should also
Ignore the hyperbole about "quantum programming" and just buy the
book. Miro Samek knows tons and tons and tons about doing statecharts
in hand-coded C++ and is also able to explain many concepts about
But still, it's a pain in the ass compared to using Ragel.
> Bottom-line: hand-code statecharts. The hard part is creating the
> statecharts themselves (I use OmniGraffle), not coding them up.
That's only because the distance from drawing to implementation is so
wide. When you use Ragel the same syntax produces the diagram and the
code, so the distance is much shorter.
> That said, I wouldn't create a protocol handler without them. They are
> extraordinarily efficient, **easy** to debug, and quick to modify. I
> create and modify statechart-based code daily at my day job, and use
> statecharts on my own projects.
I totally agree with this. Servers that don't have them are so much
harder to use. I'm working on a new HTTP server/proxy and I'm totally
taking the methods I worked up for Utu in this one. It's so much
> Zed Shaw has done some work with Ragel and statecharts if you still
> want to go down that path:
I'll be doing a new one of that for my new web server project. Stay
tuned, I'll drop an announce here.
Zed A. Shaw
- Hate: http://savingtheinternetwithhate.com/
- Good: http://www.zedshaw.com/
- Evil: http://yearofevil.com/
More information about the ragel-users