5 ms·
Types are the right solution to fix Ruby performance. Crystal is showing how a language can be simple and performant!
by exabrial 8y ago
Types are the right solution to fix Ruby performance. Crystal is showing how a language can be simple and performant!
- theredbox 8y agoCrystal suffers from other problems. They diverged too much from type annotations and use macros / metaprogramming too much which immensely increases the compile times.
- bjz_ 8y agoI don't know about Crystal's preformance problems specifically, but I would be surprised if macros would take up much compile time. I would have guessed it was more to do with the fiendishly tricky type inference problem that they set for themselves (ie. global inference + subtyping + union types + inheritance + overloaded methods).
- chrisseaton 8y agoThe problem isn’t tricky it just gets very large very quickly.
- alehander42 8y agoMetaprogramming is very fast, this is not a problem: very rarely macros can be the bottleneck
- Maledictus 8y agoRuby has types. Not everyone enjoys working with statically typed languages.
- weberc2 8y agoYou’re still working with types, you just don’t have anything checking your work (except the tests you write). Controversial opinion, but I think many of the folks who don’t like types really just don’t want to be bothered about the bugs they’ve introduced off the happy path. This is based on my experience in a Python shop.
- gxigzigxigxi 8y agoit doesn’t really matter what you enjoy if we are talking about what is needed to make a given language faster. That being said, nodejs on v8 is a lot faster than ruby and dynamically typed, so I do agree with your conclusion that static typing is not necessarily the answer.
- k33n 8y agoRuby has always put developer experience before performance. However, both are improving with each release. Give it time.
- cnasc 8y agoGetting a bit off topic here, but you sound knowledgeable about Ruby. Ruby is a language I've always admired from afar, but never spent much time trying out. I've read the poignant guide, which was amusing but didn't teach me too much. What's the SICP of Ruby? As in, a high quality book that will teach me the ins and outs of the language.
- bambataa 8y agoTry 'Programming Ruby' (aka 'the Pickaxe book') https://pragprog.com/book/ruby/programming-ruby https://pragprog.com/book/ruby/programming-ruby.
- canhascodez 8y agoRuby is a heavily idiomatic language. It's strongly advised to use rubocop or a similar style guide -- and to temper that with good judgment, at least when it recommends avoiding `!!`. In addition to the Pickaxe book, I recommend Metaprogramming Ruby by Paolo Perrotta, and potentially the sequel to that book (which I have yet to read). Ruby lends itself to a very fluid style. One of the things that you may find less common is explicit variable assignment within a method: most of the time your assignment will be in method signatures and block declarations. The following code is illustrative of technique, but not recommended practice: puts(Enumerator.new do |y| loop { y.yield Array.new(rand(1..18)) { [*'a'..'z'].sample }.join } end.lazy.reject(&IO.readlines('/usr/share/dict/words').method(:include?)).first(10).join(' ')) This generates "non-words", which are guaranteed not to exist in the (Unix) system dictionary, without using explicit assignment. First it creates a (lazy) generator object which yields random "words" of varying length. In Ruby, if you are calling a method with only one argument in an inner loop, you can avoid writing the loop explicitly, which is nice here because it also avoids the performance hit of reading the dictionary file repeatedly. The `method` method lets us pass an object-method pair, to be evaluated later, and the '&' there is a sort of cast-to-block, and you'll see that used in other contexts. So, at that point, we have a lazily-evaluated collection of lazily-filtered strings, and we can take an arbitrary number of these out and print them. The nice thing about Ruby is that you can probably express what you want in one statement. This does come at the cost of a fair amount of idiom. Some of it is functionally important, some of it is convenient (like using the `*` operator to destructure ranges), and some is pure window dressing, but enforced by convention just the same. The Pickaxe book is better than anything else that I am aware of for describing Ruby idioms. I'm not sure how well it has aged. It's probably recommended to do a lot of pair programming and code review. At times I have mentored others on the website Exercism, and I would recommend that or a similar site.