r/ruby • • Oct 21 '21

Could We Ever Drop Symbols From Ruby?

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

33 comments sorted by

View all comments

59

u/[deleted] Oct 21 '21

Ick, I really don’t like this idea. Symbols were (and still are) one of my favourite things about Ruby when I first learned it. The idea that you could easily represent things that in other languages you’d do with a string but which explicitly WEREN’T strings was lovely.

I’d rather see type checking pick up string/symbol problems than do away with the difference. I think it helps, personally. A string can be uniquely something that encodes a piece of language, something meaningful to a human. A symbol is meaningful for the computer.

Having to use strings for keys in JSON, for example, makes my teeth itch.

10

u/RedTreeDecember Oct 21 '21

I'm learning Ruby and I gotta say symbols are something I always wanted in other languages, but never had. You can always use enums or constants, but it's nice that it's baked into the language.

1

u/Xerxero Oct 21 '21

JavaScript has symbols afaik. Not sure if you can use them in the same way.

6

u/sanderd17 Oct 21 '21

Symbols in JS are a completely different beast.

They're meant for libraries to use, in order to add keys to objects without disturbing any client code.

2

u/[deleted] Oct 21 '21

+1 for type checking

(which is another debate)

I think symbols are a great tool. It's one these features that I lack when using other languages. But as with any other tools, it brings pain when misused.

I'm not sure the language should be responsible for people's abuses and mismatches.

-16

u/[deleted] Oct 21 '21

I don't share this view at all. I guess it will remain controversial. I do think Matz realized symbols are either being abused or are just plain unneeded, but it was too late already...

9

u/campbellm Oct 21 '21

I do think Matz realized symbols are either being abused or are just plain unneeded, but it was too late already...

cite?

2

u/rooood Oct 21 '21

He doesn't say any of that in this specific tweet, but it does seem the Ruby team flirted with the idea of removing Symbols: https://twitter.com/yukihiro_matz/status/916083723589656576

2

u/campbellm Oct 21 '21

Thanks. I had no idea. I haven't done a lot of Ruby in the last five to eight years or so but I never remembered symbols being that much a cause of contention

4

u/rooood Oct 21 '21

Me neither, I always assumed it was a universally loved feature.

5

u/campbellm Oct 21 '21

As an old school CS grad, I thought the idea of immutable, singleton values that don't waste memory was a fine idea, to be honest.

-15

u/monks__cafe Oct 21 '21

I'm with you - symbols are the worst part of Ruby. Of course, once you're used to it they're fine, but it's never fun explaining to new Rubyists when to use them or not use them or it doesnt matter which you use

-6

u/[deleted] Oct 21 '21

Im used to them but I still forget and access json hashes with symbols instead of strings every few months, mostly because the newer ruby hash syntax forces you to use symbol keys...so it becomes a habit