4 ms·
only thing I don't like about Ruby is the "symbols". if there was a new language that copied everything about Ruby minus the symbols, I'd be all over it. what
by jaequery 8y ago
only thing I don't like about Ruby is the "symbols". if there was a new language that copied everything about Ruby minus the symbols, I'd be all over it.
what is the reasoning for a language like Crystal to support symbols? i am under the impression that is just a relic of the past due to performance reasons but it is not the case anymore.
- yebyen 8y agoWhat have you got against symbols exactly? I don't know enough about the reasons why they are implemented to argue this strongly, but I know that they are immutable and that they are one step closer to the language in the sense that, constructions which you may not use in an unquoted symbol, are also not allowed to be used in a Ruby method name. That seems like a handy data structure to have around next to a string (and nobody's stopping you from using a string if you wanted a string and not a symbol, ...or are they?)
- samatman 8y agoIn Lua, symbols are just strings, all strings are immutable via internment, and the symbol rules constrain the parser, not the runtime. So obj.field is shorthand for obj["field"], you can have obj["="] if you want, it means obj.= but that is of course a syntax error. I find this approach more comfortable and easy to reason about than a separate Symbol class.
- yebyen 8y agoThanks! Pretty sure you can get progressive versions of this type of behavior (where obj["field"] is equivalent to obj[:field] or obj.field) by using Ruby's HashWithIndifferentAccess and/or OpenStruct classes, but those are both obviously more obscure than something which is a built-in default language feature.
- samatman 8y agoIt's one of several decisions that make Lua's type system easy to reason about. Another one is that environments themselves are simply tables, the global is _G, and environments can be set and retrieved on functions. Kinda like mutable Mars ^_^
- Mikeb85 8y agoSymbols make it easier to parse when you read it. Also less keywords. You're right though, they're not essential and just a design choice.
- jaequery 8y agonot when you now have hashes that look like this { type: :something } that looks like two walls. it was ok with hash rocket styles though