I’ve been experimenting with Elixir for a few years off and on and have really enjoyed it so far. I can’t use it professionally, so all I’ve been able to do is some Exercism exercises (which I highly recommend) along with some other random projects. For example, I used it a fair bit to solve many of the Advent of Code 2022 puzzles (here’s a link to my repo of solutions).
I’m not sure that I’m ready to call myself an expert and definitely wouldn’t say it has replaced Ruby as my favorite language, but it has been fun so far. More than fun, actually; I’ve learned a lot and it has influenced how I write code in other languages. It isn’t just that it is a functional language; there are several other aspects that feel worth carrying along with me. I love Elixir’s pattern matching and while Ruby has introduced it, it isn’t quite as powerful as Elixir’s. I assign fewer variables now, instead favoring small functions that I can chain together (thanks to
|> in Elixir). Tests in code comments — especially right above functions/methods, called Doctests — are amazing. I wish I could bring that with me to Ruby. Finally, I get why Elixirists refer to functions by their name and arity (like
foo/2) and how different Elixir is from Ruby.
If you’ve thought about picking up another language, I would highly recommend Elixir. You’ll probably learn something new!
In Ruby, especially while writing low-level protocols, you may have encountered
String#unpack(). If you’ve ever experimented with them, they may seem mysterious; they take a cryptic string as a parameter (maybe something like
w*) and seem to return gibberish (or, conversely, convert gibberish into something humans can understand). I’m not going to go into tons of detail, nor am I going to cover every format that these methods accept, but I’ll cover a few that I’ve used.
What led me to writing this post was actually some recent experimenting that I’ve been doing with Crystal. I’m trying my hand at writing a simple BER parser/encoder as a part of my journey to writing an LDAP library for Crystal. The lack of an LDAP library is honestly the biggest reason I haven’t used Crystal for more things. Since BER is a binary method of encoding, the Ruby LDAP BER code uses a ton of
String#unpack(). Unfortunately, Crystal doesn’t have analogous methods for its
Array class or
String struct so I’ve had to write my own.
Here, I’ll describe a few of the formats supported by
#pack and write some compatible examples in Crystal.
Continue reading Rewriting Ruby’s #pack and #unpack Methods in Crystal
I have a horrible memory. I don’t mean just that I misplace things or forget names; it takes a lot of effort to commit arbitrary facts, figures, dates, etc., to my long-term memory. So throughout my school years, most of my studying was for things like History, trying hard to remember dates and statistics that I would quickly eject from my mind after my next exam. I seldom had to study for Math or Science though, because I figured out something that worked for me there: learning how and why things work rather than just memorizing formulas. This worked well for those subjects, but I do remember stumbling in algebra when I was not able to factor quadratic functions. There was a handy Swiss army knife of sorts for this, of course, in the Quadratic Formula.
I avoided this formula as much as possible, usually by spending way too much time trying to guess the factors myself, or by converting from “standard form” to “vertex form”, or guessing, or skipping that question. This was almost entirely because I could not bring myself to memorize the formula. Call it laziness, or foolishness, or whatever you’d like.
Well, recently I decided to brush up on my math skills. After yet again encountering the need for this equation, I decided enough is enough. Since I can’t memorize the equation, I will instead learn where it comes from by deriving it from the standard form of a quadratic function. This is my attempt to do so.
Continue reading Quadratic Confusion