In my attempt to learn Elixir, I've converted an Erlang version of a Python script I wrote years ago. It takes a pipe of numeric values and plots lines in a character terminal. Super simple, but handy sometimes.
Now, I know line count is a horrible way to compare code, but here it is:
150 tgraph.py https://gist.github.com/dgulino/4750099
136 tgraph.escript https://gist.github.com/dgulino/4750118
106 tgraph.ex https://gist.github.com/dgulino/298516f7977c57199a4a
The python code is many years old. Maybe I've learned something since then, but I don't write very compactly, on purpose. I only use standard libraries since I don't have the luxury of installing stuff on some of the systems I want to run this on, so can't use some of the cool libraries out there.
It's hard to compare the python code to the Erlang/Elixir.
The Erlang code has added cruft on top to run as Escript (so I don't have to compile changes). I've yet to figure how to enable piping of stdin to Elixir without running a build ('mix escript.build'). So I get to compile my interpreted code!
Otherwise, the Elixir code is easier to read and more concise than Erlang, which is no suprise. Elixir +1.
No comments:
Post a Comment