Rust for Rubyists
matthias-endler.de
matthias-endler.de
Docs: https://doc.rust-lang.org/std/result/enum.Result.html#method...
even_numbers = [1, 2, 3, 4, 5].find_all { |element| element.even? }
or
even_numbers = [1, 2, 3, 4, 5].find_all(&:even?)
instead of:
even_numbers = [1, 2, 3, 4, 5].map { |element| element if element.even? }
If I were interviewing a a Ruby dev, anything other than Array#select indicates lack of experience.
I haven’t talked to you in years. I wrote some DM plugins back in the day.
Hope you’re doing well!
Are you working on any interesting open source projects?
I'm doing really well, although I did kind of fall off OSS work as I got busier with kids and family stuff. I still hack on lots of different things, but nothing that I've been able to open source. I've been busy learning Haskell these days, although I tend to write Ruby for work.
Reads nicer sometimes, sure.
In fact, the article specifically calls out that in Rust, even if expressions have a value, which is also true in Ruby, every expression has a value (though it is sometimes nil).
Any sufficiently complicated C or Fortran program contains an ad-hoc, informally-specified, bug-ridden, slow implementation of half of Common Lisp.
> With into_iter(), you take ownership over the vector. After the iteration, the vector will be gone. In Rust terminology, it will have moved.
I stopped reading right there. No Rubist or actually nobody, except real time system developers, should care about ownership.
It makes programming so much more complicated without any real benefit, again apart from real time systems.
Don't say Rust is useless. Do say you don't need Rust.
> Don't say Rust is useless
Read it again. What I said was that the complexity added by the concept of ownership is not a worth the benefit of not having a garbage collector, except in a few cases.
I am not necessarily comparing it with Ruby. I am comparing it with languages equally fast, Go, OCaml, Haskell, that are garbage collected.
Instead of telling me what to say and not, why do you try to convince me that my argument is wrong. That's what this forum is about, no?
In the section about converting a vector of strings into integers the article says that the Result returned from parse() is converted to a bool via Result::ok(). However, Result::ok() actually converts the Result<T, E> into a Option<T> which is what filter_map() expects.