Ruby 3.2.0 is from another dimension
231–240 of 341 posts
Re: Ruby 3.2.0 is from another dimension
#232Earlier quoted context omitted.
You are obviously referring to Python and so I would like to note a few things. (I have nothing against Ruby) > Ruby ... its combined attributes of brevity, expressive power, and feature consistency. > [Python] lacks the elegance and consistency First I would argue Python is very consistent in its design, it aims to only have one obvious way to do things and so it's easy to guess how apis will work. It also aims for…
I explored this topic a while ago on my blog [0] In essence, I don't think it has anything to do with elegance, syntax, or "easiness". It's more about timing + origin + corporate adoption: * Python was created in Europe, Ruby was created in Japan - when Ruby gained more recognition in English-speaking world (~2004), Python has already been present and used worldwide for a decade * Ruby was created as a personal, hobb…
Re: Ruby 3.2.0 is from another dimension
#233- Static typing
We have RBS but that is written to a separate file, the only thing I see being close is the Contracts gem
- Lots of first class scientific libraries and other cool libs
http://sciruby.com is working towards lowering that barrier
Re: Ruby 3.2.0 is from another dimension
#234Earlier quoted context omitted.
You are obviously referring to Python and so I would like to note a few things. (I have nothing against Ruby) > Ruby ... its combined attributes of brevity, expressive power, and feature consistency. > [Python] lacks the elegance and consistency First I would argue Python is very consistent in its design, it aims to only have one obvious way to do things and so it's easy to guess how apis will work. It also aims for…
> Ultimately I think that's why Python has gained more traction than Ruby, it's an "easer" language to follow and start with. Ruby is probably a more fun and intellectually stimulating language to work with though. Working with various Ruby-adjacent stuff for 10+ years and nothing about Ruby was even "fun" to work with, it was mix of "WTF" and "who designs language like that!". Python is also not "easier" to start wi…
Re: Ruby 3.2.0 is from another dimension
#235Ruby is my favorite language, and often it is a joy to use because of its combined attributes of brevity, expressive power, and feature consistency. It's disappointing that there are so many more jobs for another popular language - one that lacks the elegance and consistency but which has a larger ecosystem. As far as I know, the only well known reason for a company to choose Ruby is if they want Rails (and obviously…
Rails is quite the double-edged sword, too. Even putting aside the controversial close ties to DHH (which is a hell of an exception to be making), the dominating presence of Rails within the Ruby ecosystem means that any Ruby-adjacent project either becomes a Rails-adjacent project (and possibly gets absorbed into Rails itself) or fades into irrelevance. It makes expanding the language into non-web framework domains…
Re: Ruby 3.2.0 is from another dimension
#236Earlier quoted context omitted.
Yes, but there is an interesting clarification here. RE2 has used the "caching" approach documented in the Ruby bug ticket linked for quite some time (since its birth?): https://github.com/google/re2/blob/954656f47fe8fb505d4818da1... It is mentioned only briefly in Cox's article on regex matching in the wild. Look for the word "bitstate": https://swtch.com/~rsc/regexp/regexp3.html I didn't know Perl had implemented t…
One of the authors mirrored the paper: https://fservant.github.io/papers/DavisServantLee-SelectiveM...
Re: Ruby 3.2.0 is from another dimension
#237Earlier quoted context omitted.
> it does have different meanings too the meaning is the same high level: it has side effects, being it a destructive update, an in place operation or throwing an exception. > `sorted` is a general function that gives you a sorted list from any iterable iterable in Python is a very loose concept though. And it's not very consistent too sorted("gheliabciou") ['a', 'b', 'c', 'e', 'g', 'h', 'i', 'i', 'l', 'o', 'u'] you…
Lots of objects don't have a natural way to return a sorted version of themselves, especially inplace (what's the reverse sort of a range, for example). You get the same in Ruby, as you've just demonstrated. Sorting into a list is the only thing that makes sense in all cases. In that way `sorted` _is_ totally consistent - it always takes an iterable and returns a list of the elements. If we can't agree on that then I…
except Iterable is the wrong "interface"
in Python it is defined as
> An iterable is any Python object capable of returning its members one at a time, permitting it to be iterated over in a for-loop.
which is not always what you want for sorting
quicksort doesn't work one element at a time
so basically you have to extract all the elements before sorting them
what about infinite streams?
At least Ruby Enumerable mixins explicitly states that
> The Enumerable mixin provides collection classes with several traversal and searching methods, and with the ability to __sort__.
Another problem with sorted is that it accepts any iterable, true, returning a list of items, but it is not clear how you can tell if the object is an iterbale or not
>>> sorted(123)
Traceback (most recent call last):
File "", line 1, in
TypeError: 'int' object is not iterable
ok >>> isinstance(123, iterable)
Traceback (most recent call last):
File "", line 1, in
NameError: name 'iterable' is not defined
mmmmmaybe it's because int is not iterable?
>>> isinstace("abc", iterable)
Traceback (most recent call last):
File "", line 1, in
NameError: name 'iterable' is not defined
so the solutions are # fails for strings in Python 2
>>> try:
_ = iter(some_object)
except TypeError as te:
print('is not iterable')
or # if 2.6 >= Python = 3.3
from collections.abc import Iterable # >> isinstance("abc", Iterable)
True
not only it's very ugly, but it can also fail in mysterious ways. As per documentationChecking isinstance(obj, Iterable) detects classes that are registered as Iterable or that have an __iter__() method, but it does not detect classes that iterate with the __getitem__() method. The only reliable way to determine whether an object is iterable is to call iter(obj).
while in Ruby it's straightforward
[3] pry(main)> [1, 2].is_a? Enumerable
=> true
[4] pry(main)> "abc".is_a? Enumerable
=> false
[5] pry(main)> "abc".chars.is_a? Enumerable
=> trueRe: Ruby 3.2.0 is from another dimension
#238Re: Ruby 3.2.0 is from another dimension
#239Earlier quoted context omitted.
> I think the Ruby solution is more readable. I disagree and I’ve used both professionally for about the same amount of code.
I think this is purely a personal preference but I also think there is a bias towards list comprehensions being more difficult to mentally parse. I do a lot of contract work and chatted with a ton of folks ranging from beginners to veterans. A lot of them (well more than half) avoid list compressions, especially when working with teams because it's such a mixed bag of either being able to instantly understand them or…