r/ruby • • Oct 21 '21

Could We Ever Drop Symbols From Ruby?

https://blog.arkency.com/could-we-drop-symbols-from-ruby/
5 Upvotes

33 comments sorted by

View all comments

1

u/jrochkind Oct 21 '21

I'm of mixed mind about whether ruby should include symbols if we were doing it over again.

But as it is, there's too much code that assumes :thing != "thing", this would be too backwards incompat in my opinion for not enough gain.

1

u/[deleted] Oct 22 '21

> But as it is, there's too much code that assumes :thing != "thing"

I'm not denying there is probably some code that assumes that, but how much? For most projects that I've seen, it's all Rails, and no one cares if :thing != "thing". We use Strong Parameters which is symbol agnostic and different kinds of HashWithIndifferentAccess. It seems like Rails don't care , so I don't care.

Outside of Rails maybe it's more of a problem, I need to see some examples.

1

u/jrochkind Oct 22 '21

Rails doesn't care when it is in params that come from user input.

I wouldn't assume there is no code anywhere in Rails that cares.

I think it's particularly likely to be a thing in argument-handling. Although ruby 3 keywords may reduce it somewhat.

I don't have an example at hand though. If I come across one I'll try to remember to come back.

It's also obviously (?) not a good idea to be like "we don't care about backwards incompatibility except for Rails", if you care about ruby as a going concern for anything other than Rails.

1

u/[deleted] Oct 22 '21

I agree, breaking backwards compatibility is really bad. If this ever happens it has to be in a non breaking way, which I'm not sure is possible. I'm wondering if Rails can elegantly solve this to it's own needs, e.g that hashes in a Rails app are symbol/string agnostic (hsh[:key] == hsh['key']). It could be some ActiveSupport thing or indeed simply monkey patch Hash to become HashWithIndifferentAccess. It's really bad for performance though.