Crystal: Ruby-like suggestions?

Created on 11 May 2018  路  15Comments  路  Source: crystal-lang/crystal

Hi there, I'm a long-time Ruby developer new to Crystal and loving my experience!

One decision that was made (which I applaud) was to have only one way of doing something. Coming from Ruby this means more than once I've done something like array.length or array.inject and been puzzled for a few minutes trying to figure out what went wrong.

What would you guys say to adding some ruby-like suggestions (somewhere in crystal/semantic?) so that calling array.inject produces undefined method 'inject' for Array(T) (did you mean 'reduce'?)

I don't think we need an exhaustive list of these Ruby changes, but if there was a place in semantics where we could store a JSON of them or something along with some logic, it would add just one more cool feature to an already bursting-at-the-seams-with-cool-features project.

shard-idea

Most helpful comment

@ysbaddaden What if instead of failing fast, all error messages would be printed at compile time? It's not satisfying in producing a working program but at least shows all such errors at once ;)

All 15 comments

This will probably never be added to the compiler, however an external tool for this kind of feature could be made one day to ease the passage from Ruby to Crystal!

Cool, make sense. Thanks for the quick response and again thanks for the awesome language!

The first step would be to create a list of these suggestions.

Having a ruby-compat shard that delegates methods and prints nice messages for common ruby aliases/methods would be very nice.

I don't think a ruby compact shard is a good idea, having one that has all the ruby methods with instructional compiler errors is a far better idea. This can be done with macro raise

I prefer a compat because it works (it's satisfying) but prints helpful messages (annoying). This is better than failing with a helpful message (just annoying).

Furthermore, if you make 3 compat calls, with a compat library you get 3 messages printed at once (allright, I must fix 3 calls). Failing hard, on the other hand, means you get 1 failure, fix it, then 1 more, fix it, then... when will that end?

@ysbaddaden Given a compat library is only useful when learning the language (deploying it into production would be pointless), then you won't need the library for long and also won't have written much code between compiles (because you're exploring the language) so I don't think it's a big deal. Encouraging people to lean on a compat library as a crutch for not learning crystal's stdlib is far worse in my opinion.

Well, we disagree. I believe knowing you have issues (and how many of them), yet still having a result, and possibly adding an encouragement when there are 0 issues is more rewarding, helpful and engaging in the long run, than failing hard with not end in sight which would be quite discouraging.

Renaming a method call then running the compiler 5 times is hardly an ordeal.

@RX14 hardly a pleasant and motivating experience either.

Crystal isn't only inspired by Ruby, but also by Python, Go, Rust, C#...
If we start to add suggestions based on Ruby, logically we'll have to do it for other languages. That's quite ambitious. I really doubt it's worth it.
This would better fit to an external tool, that helps beginners comming from X language.

@j8r hardly, you have it even stated as a first thing on crystal-lang.org website (_Fast as C, slick as Ruby_, then later on, _Crystal鈥檚 syntax is heavily inspired by Ruby鈥檚, so it feels natural to read and easy to write, and has the added benefit of a lower learning curve for experienced Ruby devs._) - it makes total sense to ease the transition.

Just look at the amount of issues opened by Ruby newcomers - obviously you ain't gonna find one opened by people coming from Python, Rust or C# - for a reason...

@ysbaddaden What if instead of failing fast, all error messages would be printed at compile time? It's not satisfying in producing a working program but at least shows all such errors at once ;)

@straight-shoota if you can make it work in macros go ahead

Na, I don't think this can work with macros. It would need information about the callsite to be anywhere near useful. So it's probably only going to happen either as a compiler feature or third party tool.

Was this page helpful?
0 / 5 - 0 ratings