5 ms·
Reducing the maximum latency of a bound buffer in Erlang
- qaq 10y agoAs always a very informative post by Saša Jurić. If anyone is looking for quality Elixir study material would highly recommend his "Elixir in action" book.
- plainOldText 10y agoAnother comprehensive and well organized source for learning Elixir I might add: https://elixirschool.com https://elixirschool.com It covers numerous things: from the basics, all the way to OTP, meta-programming, and even certain popular libraries such as Plug and Ecto.
- crusso 10y agoIt's really instructive to just look through and try to grok Saša's code on github. https://github.com/sasa1977 https://github.com/sasa1977
- aetherson 10y agoI really want to love Elixir, but man, it fundamentally hasn't succeeded in producing a readable, expressive language. Look at his implementations! They're a mess of gobbledegook just like Erlang, plus a bunch of weird magic on top that's not very intuitive. Syntax aside, the final implementation of this feels like, okay, well, you have access to an in-memory store that's outside of the GC and which works well for your use case here. I'd actually be more interested in further optimizations of the first approach, in-GC, which seem like they'd be more generalizable to other tasks.
- naringas 10y agoI'm interested in Elixir, but I don't know all that much about it (yet). Could you elaborate on what you mean by "mess of gobbledegook just like Erlang"? thanks
- tomphoolery 10y agoIn my opinion, Elixir is still a more expressive and readable language than Erlang, and if you want to do OTP programming it's the best we have so far. Learning more about OTP has warmed me a little to the syntax of both Elixir and Erlang, because I'm now able to understand the syntactical choices that were made in order to express what's going on under the hood more clearly. As a Rubyist, I also enjoy Elixir's similarities to Ruby, and had to get over how it looked to me for a while before I really understood why it felt so weird to write. It might be a form of Stockholm Syndrome, but these days it makes sense to me so I sort-of enjoy how it works and looks.
- ShaneWilton 10y agoI'm curious about what aspects of the syntax you consider to be unreadable. Elixir code tends to be terse (though less terse than something like Haskell), but I wouldn't call it gobbledegook. The server implementation [0], for example, is 25 lines and handles a lot behind the scenes. Those 25 lines are all you need to define a process that can leverage all of the supervision and hot code reloading benefits offered by OTP. There's a lot going on, but it's mostly just pattern matching tuples and maps, and it only takes a few hours of messing around with Erlang or Elixir before that kind of thing stops looking so scary. [0] https://github.com/sasa1977/erlangelist/blob/master/examples/buffer/lib/buffer/server.ex https://github.com/sasa1977/erlangelist/blob/master/examples...
- aetherson 10y agoSure, like this: %__MODULE__{buffer | size: buffer.size + 1, queue: :queue.in(item, buffer.queue)} So that involves a bunch of operators that are very specialized to Elixir -- the %, the | are both very unclear in my opinion. And the __MODULE__ construction is clumsy. Or worse: {:ok, { :ets.lookup_element(buffer.ets, pull_index, 2), %__MODULE__{buffer | size: buffer.size - 1, pull_index: rem(pull_index + 1, buffer.max_size) } }} Same problem as above, plus the nested set structures that Erlang loves, but which rapidly become super difficult to decipher. Oh, and also the overloading of atoms to work like pseudo-objects.
- ShaneWilton 10y agoI agree that your second code example is difficult to read, but I think that is more a result of a lot of logic being inlined into one call, than it is a property of the language. % and | are going to be unclear if you're an outsider looking in on the language, but that is true for any sort of specialization. I'd be interested to know what languages you find to be readable, because I can all but guarantee that there's aspects of that language that I'd find arcane -- not because they are, but because I don't know the language. I'm not terribly interested in discussing whether a language is readable or not, because a lot of that is going to come down to subjective opinion, but at the end of the day, I find that Elixir lets me quickly write maintainable code. I'm not entirely sure what you mean by "overloading of atoms to work like pseudo-objects", do you mind elaborating?
- plainOldText 10y agoI personally find Elixir to be a very readable, expressive and thoughtful language. I agree, Erlang not so much. Would you care to elaborate which parts you consider to be "gobbledegook"? The code supplied is just a few lines of code. I don't know how familiar are you with the language, but the magical aspect of it will quickly disappear once your learn a few OTP patterns. I personally started initially with Erlang, but when I discovered Elixir, I switched, as I found it way more pleasurable. Python and Elixir are actually the only two languages that make me happy when writing code, and I've tried quite a few of them, from C all the way to Haskell.
- ShaneWilton 10y ago> I agree, Erlang not so much. I thought the same thing once, until I actually sat down and tried to learn Erlang. It turns out that a lot of the decisions that I originally thought were asinine, actually make a lot of sense. Line terminators for example (, ; .) tend to receive a lot of flak, but they really aren't as crazy as they first seem. Commas come after normal lines of code (you can read them as and), semicolons come at the end of clauses in if or case statements (and you can read them as or), and periods mark the end of a function. It's a little more verbose than something like Javascript or Ruby, but it really isn't as confusing as critics tend to claim!
- plainOldText 10y agoOh, absolutely. I'm sure the Erlang inventors weren't crazy, and most of their choices have some reasoning behind them. But I personally find Erlang more difficult to read than other languages.
- pselbert 10y agoThe things that have always tripped me up for Erlang are capitalized variables, lowercase modules, and bare word atoms. There certainly isn't anything wrong with those choices, but it is counter to everything I'm used to from other languages that it presents some cognitive overhead. In the end, even as somebody who cares about the look of code a lot, it doesn't matter to me. The BEAM and OTP are elegant enough to compensate for any syntax.
- deleted 10y ago[deleted]
- macintux 10y agoWouldn't be a thread about BEAM languages without someone complaining that their education was confined to languages that don't look like Erlang and thus Erlang is awful to read.
- BoorishBears 10y agoI learned Erlang before learning (of) Elixir as someone who'd only used C-like languages after an acquaintance recommended it for a project I was working on. The thing that seemed magical about Erlang was how efficient it's syntax managed to be without being ambiguous. In a weekend I picked up the syntax, and in days I was being productive with it. I've heard Elixir described as "Rubyfied-Erlang" which would explain why I don't particularly love it, since I don't love Ruby syntax (and I secretly harbor a tiny bit of resentment for Elixir for taking off and essentially cementing Erlang's place outside the spotlight), but it's not bad either and doesn't add that much syntax. And it's not like the syntax of C-like languages hasn't evolved towards something that looks "different" anyways. Lambdas + Rx/Promises + Streams practically looks like it's own language in most C-like languages...
- vertex-four 10y agoI'd be programming Erlang for my current project, except that its library position is a bit of a mess - full of 4-year-old projects on github that haven't been touched since they were uploaded. At least Elixir bringing in some Rubyists means there's some decent libraries for connecting to external systems now.
- 10y ago