5 ms·
anyone know of a language that is just like Ruby, minus the symbols? or javascript, that is procedural first rather than asynchronous? it really bugs me that
by jaequery 8y ago
anyone know of a language that is just like Ruby, minus the symbols?
or javascript, that is procedural first rather than asynchronous?
it really bugs me that there isn't one quite like it, i'm just dying for something like that.
- thefounder 8y agoDid you try Go?
- rajangdavis 8y agoI wouldn't say Go is similar to Ruby, but it is definitely pretty straightforward to pick up like Ruby.
- dom96 8y agoHave you tried Nim?
- chrisseaton 8y ago> anyone know of a language that is just like Ruby, minus the symbols? What’s your issue with symbols in particular? They seem pretty harmless to me.
- jaequery 8y agoHarmless yes, but is it useful? Probably not. I have been teaching people Ruby and till this day, I have a hard time answering whenever a student asks me what the benefit of using Symbols over Strings is. I know it was in place early on for memory / performance reasons but as of Ruby 2.2, there are zero-performance gains using symbols over strings. Unfortunately it's too late to deprecate them since it's a widely adopted practice. When I teach Ruby, I try to evangelize how simple Ruby is but always hits the breaks whenever I have to explain Symbols. And ultimately, no matter how much I try to ignore, I just can't stand how this looks: opts = { adapter: :mysql} It looks like a double wall of some sort which is fine for those who are used to it but not for those beginning. (Especially those coming from other languages like Python, PHP, and JS) Symbols also cause occasional havoc when using 3rd-party libraries because they all have different preference of when to use it and when not to. So IMO, there are no benefit of Symbols and it just creates confusion more than anything. And that is really the point I am making. I have a hard time reasoning with those PHP/Python folks why Symbol exists and it shouldn't really be that way.
- dnautics 8y agoOk so I don't know about Ruby, but in Julia and elixir, symbols have O(1) comparison but more importantly they have key roles in abstract syntax tree manipulation; if you're doing any metaprogramming it makes sense that it exists.
- rokob 8y agoUseful, yes. > as of Ruby 2.2, there are zero-performance gains using symbols over strings This is verifiably false. Run this on a newer Ruby and you will see symbols are faster: ``` require 'benchmark' hashes = [] 1_000_000.times { hashes << { some_key_name: 1, 'some_key_name' => 2 }} Benchmark.bmbm do |x| x.report { hashes.map{|h| h[:some_key_name]} } x.report { hashes.map{|h| h['some_key_name']} } end ``` But that isn't the reason symbols are useful. They signify intent as a constrained set of alternatives. Strings can take on any value, symbols should be limited to a set of things you know. Strings can be modified in-place, symbols are immutable. `opts = { :adapter => :mysql }` is perfectly valid for scenarios where you are using symbol values. But the shorthand syntax for symbol keys was added later, and I agree is a bit ugly. If you are generating symbols from input or from strings then they lose some value. It is easy to explain the existence of symbols in Ruby especially if you are giving proper merit to the Smalltalk lineage. Erlang also has symbols for a lot of the same reasons and most would agree they are very useful there.
- chrisseaton 8y ago> as of Ruby 2.2, there are zero-performance gains using symbols over strings As others have pointed out - this is demonstrably false. # frozen_string_literal: true a = ('fo' + 'o').to_sym :foo == a b = ('fo' + 'o').freeze 'foo' == b The second comparison is a 1.5x slower than the former. This is because if a string comparison fails on identity, it then has to check characters. Symbols are always interned so can always stop as the identity comparison. But I actually just like them as they convey intent - a symbol is a string I know about as the programmer. A string is a string that is runtime data.
- jaequery 8y agoI too like it as you. But I find when dealing with a lot of JSON data (decoding/encoding) the symbols become a hindrance.
- int_19h 8y agoWhich symbols did you have in mind? Variable name sigils like $ and @?
- aboutruby 8y agoSymbols in Ruby are basically concise strings, :id is a symbol, "id" a string. There are some differences of how they are allocated but it's mainly a style preference and a convention. e.g. you would typically do { id: 1, name: "aboutruby" } where id and name are symbols, instead of { "id" => 1, "name" => "aboutruby" } with strings. But really I don't see the point of removing the symbols.
- syrrim 8y agoWhat's wrong with python?
- samatman 8y agoLua comes fairly close to doing both of these things. You would need to get used to doing some things manually which are automatic in Ruby.