5 ms·
One of Ruby’s pillars is metaprogramming. Crystal lacks that entirely, making it a non-option for many Rubyists.
by block_dagger 6y ago
One of Ruby’s pillars is metaprogramming. Crystal lacks that entirely, making it a non-option for many Rubyists.
- chrisseaton 6y agoCrystal has compile-time metaprogramming, which is it's own thing and has many sensible uses... but yes it's not the metaprogramming people are used to in Ruby and that the entire Ruby ecosystem is pretty fundamentally built on.
- deleted 6y ago[deleted]
- vasilakisfil 6y agoCrystal has macros which is the metaprogramming for static/compiled languages. And last time I checked, there are way more things that you can do with Crystal macros than Rust's macros. And crystal's macros feel very familiar to the language itself, are easy to understand and use them whereas Rust's macros..
- lytigas 6y agoAccording to [1], Crystal Macros "receive AST nodes at compile-time and produce code that is pasted into a program." This is basically the same as Rust procedural macros[2]. You're probably thinking of "Macros by example"[3] [1] https://crystal-lang.org/reference/syntax_and_semantics/macros.html https://crystal-lang.org/reference/syntax_and_semantics/macr... [2] https://doc.rust-lang.org/reference/procedural-macros.html https://doc.rust-lang.org/reference/procedural-macros.html [3] https://doc.rust-lang.org/reference/macros-by-example.html https://doc.rust-lang.org/reference/macros-by-example.html
- vasilakisfil 6y agoBeing able to receive AST in crystal is only good. However have a look here [1], 90% of your macros are covered with those helpers. In Rust doing the same things are either more difficult or impossible. For instance, I wanted in rust to inject allow/warn kind of derives based in env var. Nope. [1] https://crystal-lang.org/reference/syntax_and_semantics/macros.html https://crystal-lang.org/reference/syntax_and_semantics/macr...
- ricardobeat 6y agoWhich is fine since the language is not really aimed at replacing Ruby (despite this blog post's headline)
- viraptor 6y agoIt's true the runtime meta programming is missing. Other comments mentioned some compile time options. But in my experience most Ruby doesn't really use metaprogramming for really hard cases. I've translated some larger modules to crystal recently and while there are magic things like activerecord out there, most metaprogramming is... simple. Often a glorified "I'd rather write a loop than repeat 3 similar method implementations". Outside of generic framework code I never ran into something meta which can't be trivially expanded to slightly repeating (and more readable) code.