177 points · by davidw · 11y ago · 42 comments
I think the the particular problem (which by the way was super fun, great work @mattetti!) was really well suited for pattern matching, so like OP I gravitated towards those tools.
I had been keeping my solution private until the contest was over on the 28th, but for sake of comparison of Elixir/Erlang idiomatic code (which should be pretty similar), I'll make my repo public now too (which also contains my Go solution):
https://github.com/mroth/golang-challenge-1
BTW, if you enjoy playing around with reverse engineering, I recommend NOT looking at any of these solutions, and doing the challenge yourself first (in whatever language you want). It was amongst the best of the "code challenge exercises" I've attempted.
You want your tools to feel like that.
https://github.com/jlouis/go-challenge-1
If you need a LICENSE, I can slam a MIT or Apache 2.0 on it for you, but...
Are there any good books on this subject?
Thanks.
IIRC, it pattern match first and if the variable is not assign then it'll assign it IIRC. The code and explanation just state that it's Erlang to do assertion.
I think that's an interesting concept at least when I play with Erlang.
If you have a large number of processes, then it is a problem. And do note that Erlang programs have way more pointer-redirections than a typical array-like approach which is common in Go and other imperative languages. That is the memory pressure by default will be higher than what you can achieve in languages with static types.
It tends to be a problem for tight computational kernels, and Erlang programmers usually fall down to C if they prove to become bottlenecks.
I have an older post here describing the schedulers: http://jlouisramblings.blogspot.dk/2013/01/how-erlang-does-s... which is still reasonably up-to-date to give the overview.
It was shorter in LOC than my go version, mainly due to try!, but the lines themselves were longer. The one difference in correctness was that I forgot to close the files in Go, but RAII took care of it automatically in Rust.
I love the looks of Rust because it's C ABI compatible and I could write Python libraries with it.
Erlang because it looks to be the best thing going for webservices, which is much of my work.
Erlang/Elixir is made to build fault-tolerant applications: think a service (which is really tens of thousands of micro-services all running in the Erlang VM), distributed on a cluster, that needs to run 24/7 without any interruption ever. Upgrading the app should not halt the system. A bug somewhere should not require you to restart the app: it should be limited in scope and you just hot patch it away. Erlang is fault tolerance is fault tolerance.
From a Python/SQL background both will have a different set of challenges to learn: Erlang/Elixir means learning functional programming (no for loops, all map/reduce/filter and recursion), while Rust means learning how to handle references/memory ownership.
To build webservices I'd give an edge to Elixir: cowboy + plug (+ phoenix). But that should be fun to build with Rust too... You should learn both :)
> state( "Magic", { consume(16), toString(), assert("SPLICE") } ),
> state( "Length", { consume( 1), fromOrd(), cropInput() } ),
> state( "Version", { consume(32), toString(), setVersion() } ),
> state( "Tempo", { consume( 4), fromFloat(), setTempo() }),
> state( "Instruments", { exhaust([snip]) } ),
The layout, from my abortive attempt to write a parser.http://en.wikipedia.org/wiki/Single-precision_floating-point...
A fun problem!