Hacker News new | past | comments | ask | show | jobs | submit login
NTP Implementation in Elixir (0x7f.dev)
69 points by signa11 on July 19, 2023 | hide | past | favorite | 12 comments



Really enjoy working with bits & bytes in Elixir. The syntax looks weird at first but pattern matching against an incoming message via individual bytes is very nice. I've found the gen_tcp / gen_udp stuff's documentation to be a little hard to grok as most of it only gives deep in the Erlang modules but once you "get it" you really get it. It plays very nicely with GenServer's too for super reliable, fault tolerant, tcp/udp acceptor clients. Thanks for the article, this will be a good resource for everyone to learn more about gen_tcp/udp directly!


My "learn elixir" project was writing a full API/client for communication with a NEO-M8 GPS chip via i2c bus. I have never done any i2c hardware programming in my life. Suffice to say I bit off way more than I can chew and it barely works - but it's definitely been incredibly rewarding to use such a high level language to do such low level things with relative ease.


Completely agreed, I had to reverse engineer and communicate with an undocumented telnet interface last year at work. It was a brutal pain until I decided to do it in elixir, where it was merely annoying.

The nomenclature around binary/bitstream/charlist/iolist is fairly messy though. But to be fair I think most or maybe all of that shit is just straight from erlang. OTP is a rock solid standard lib but we used to joke that they just took turns naming modules and functions. "Everyone gets to do one!" There's no consistency.


I really like how well the pattern-matching system in Elixir works with decoding binary data. It can even extract on non-byte boundaries.


What’s fantastic is you can reference an unpacked variable immediately within the bitstring.

This is super handy if you have variable length sections with a header, such as a DNS packet, saving having to do it in two operations.


Compared to the bit packing I had to do in C in the 80s Elixir is a joy. The bit operations in a pattern-matched functional language is what got me hooked on Elixir.


I would think that a language like Elixir would have latency issues that would be a problem for NTP. I didn't see any discussion of this in the article -- can Elixir be deterministic?


Since the NTP client is usually just drifting towards the server time with clock skew maybe this would only manifest as doing this process a little slower. If latency was even a problem in the first place.


[flagged]


Calling dupe on a post in favour of one with no discussion just wastes everyones time.


This was a really fun read.

It's interesting to think about why the prior submission by the author himself didn't get any comments or traction and this resubmission did. Timing?

As of right now, there are really only two non-meta comments here after all. Which is too bad, this is a great write-up and very fun.


whoopsie ! not much discussion on that, perhaps we might see some action this time around.


[flagged]


It was submitted by a different person each time.




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

Search: