Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

binary pattern matching is also a godsend for network protocols.

I generally prefer using a blocking recv loop when writing network protocol servers in elixir.

I learned some really cool things from this blog post, namely the stuff about multicast membership and groups.



Yes. I recently wrote an Elixir driver for MonetDB. I also wrote a CLI tool in Go for MonetDB and had to write a subset of the driver.

Pattern matching in general, and binary pattern matching specifically, made the experience (and the resulting code quality) night and day.

The big issue I have with pattern matching / binaries (aka, strings) in elixir / erlang is that doing it efficiently is, at best, a dark art and, at worst, impossible. This was drastically improved in OTP 22, but it's still opaque.


> The big issue I have with pattern matching / binaries (aka, strings) in elixir / erlang is that doing it efficiently is, at best, a dark art and, at worst, impossible.

Sorry, can you elaborate what you mean by impossible? Or maybe what you mean by efficient.

Thanks!


I just spent some time looking at some old code, and it does seem like OTP 22 solved any of the issues that I had run into at the time. My mistake, sorry about that.

(Though I maintain that it's still opaque)


There's a section about pattern matching and binaries at https://erlang.org/doc/efficiency_guide/binaryhandling.html

Compiling with the bin_opt_info flag (erlc +bin_opt_info Mod.erl) will list the points in your code where binaries are created during pattern match, or any other points where binaries could be shared, but are not.


I really wish more languages had better handling for binary, such as in Erlang. I'm working on an implementation of a rather old networking protocol where frames are very bit oriented and writing code to to read and write individual bits feels so tedious.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: