News for hackers. Stuff that matters.
Re:An Ode to Ruby by Mikeb85 on Monday January 10, 2022 @10:51AM (#29876664)
Nope. Can't stand that Python uses built-in functions for basic things like list, map, fold, etc... instead of methods on base classes. Here's a super basic example. Add one to an array [1,2,3] and print results.

Python: print(list(map(lambda x: x + 1, [1,2,3])))

Ruby: print [1,2,3].map {|x| x + 1}

So much more readable, easy to write, etc... Ruby keeps it consistent by making pretty much everything an object and you just call methods. Even Haskell has dot notation to chain functions since it's just so much easier to read and write...

Re:An Ode to Ruby by trufas on Monday January 10, 2022 @11:02AM (#29876824)
To be fair, you almost never should use the map builtin instead of the pythonic equivalent, list comprehensions.

`print([x + 1 for x in [1, 2, 3])`

I agree that the ruby approach is better in terms of consistency, but most developers will be aware of the conventions python uses.

Re:An Ode to Ruby by Mikeb85 on Monday January 10, 2022 @11:06AM (#29876903)
Ok, that's a nicer result (obviously I don't write Python lol) but still seems inconsistent to me (putting the function before the array) considering Python is an OO language and most people are going to be writing methods for classes where you call methods with dot. I just remember list comprehensions from Coffee-script and not going to lie, I hate them. It's like reading backwards.
Re:An Ode to Ruby by knodi123 on Monday January 10, 2022 @12:05PM (#29877860)
> still seems inconsistent to me (putting the function before the array)

I'm experienced in ruby, and learning python for a project. I don't think I'll ever not wince when using python's ternary;

ruby: size = (waist > 30) ? 'large' : 'small'

python: size = 'large' if (waist > 30) else 'small'

Re:An Ode to Ruby by cle on Monday January 10, 2022 @12:31PM (#29878306)
I've always assumed this was to maintain syntactic consistency with comprehensions like [x for x in arr if x > 2].
Re:An Ode to Ruby by iterati on Monday January 10, 2022 @11:08AM (#29876932)
Python is a multi-paradigm language, of which OO is one paradigm it supports.
Re:An Ode to Ruby by Mikeb85 on Monday January 10, 2022 @11:21AM (#29877143)
Ruby has map, filter, reduce and a bunch of other functional methods. It's more about the consistency of wondering what's a function versus what's a method and then things like list comprehensions and for loops. Python also doesn't have a lot of the goodies of a real functional language, it encourages for loops and seems to be even more procedural than Ruby but less OO?
Re:An Ode to Ruby by cutler on Monday January 10, 2022 @10:04PM (#29886860)
Not really. Python 3 is all OO under the hood including what appear to be procedural functions. It's just not as elegant as Ruby's OO.
Re:An Ode to Ruby by jimbokun on Monday January 10, 2022 @02:46PM (#29880813)
Ruby is a strongly OO language, which arguably also has better support for functional programming than Python.
Re:An Ode to Ruby by cutler on Monday January 10, 2022 @10:05PM (#29886876)
Yes, that's the Zen of Ruby and why I love it.
Re:An Ode to Ruby by junoper on Monday January 10, 2022 @11:52AM (#29877645)
Python, I think, has n number of ways of doing the same thing while Ruby's everything is object approach forces you down a single approach. So while reading ruby code, you usually don't have to shift your mental model from OOP to procedural/list comprehension etc.

If Ruby gets a good machine learning library on par with something like Pytorch, I am sure many folks will shift to it and we might see new DSL emerge.

Re:An Ode to Ruby by regularfry on Monday January 10, 2022 @12:24PM (#29878175)
Which is ironic, given that "There should be one-- and preferably only one --obvious way to do it" is in PEP 20.
Re:An Ode to Ruby by burlesona on Monday January 10, 2022 @08:53PM (#29886170)
I agree. This has always driven me crazy. Python is supposed to be “there’s one way to do it” but I find it quite inconsistent!
Re:An Ode to Ruby by busterarm on Monday January 10, 2022 @01:58PM (#29879783)
The vast majority of Python code that I have had to interact with professionally seems to ignore the fact that PEP even exists.
Re:An Ode to Ruby by cutler on Monday January 10, 2022 @10:08PM (#29886898)
How I wish that was a possibility. Unfortunately Python's dominance of ML and AI is a fait accompli. If anything is going to replace Python in this domain it won't be another scripting language with similar performance.
Re:An Ode to Ruby by runjake on Monday January 10, 2022 @11:13AM (#29877009)
You're splitting hairs about what the op said. How about len() ?
Re:An Ode to Ruby by marquis_andras on Monday January 10, 2022 @11:43AM (#29877501)
[1,2,3].__len__()
Re:An Ode to Ruby by cutler on Monday January 10, 2022 @10:11PM (#29886938)
Yes, Python is all OO under the hood just like Ruby but ugly as sin.
Re:An Ode to Ruby by regularfry on Monday January 10, 2022 @12:28PM (#29878252)
For me it's annotations. Looked at from a distance, what appears to have happened is that the implementation hit a certain level of complexity before class methods got implemented, and it ended up being easier to do them with "@classmethod" than with "def self.foo", or to fix whatever reason it is that makes "def foo(a,b,c)" not act like a class method if "a" isn't "self".
Re:An Ode to Ruby by cutler on Monday January 10, 2022 @10:12PM (#29886946)
For me it's crippled lambda and __dunders__.
Re:An Ode to Ruby by j_mo on Monday January 10, 2022 @04:55PM (#29883253)
This is what really put me off Python as somebody who learned Ruby as their first proper (professional 9-5 usage) programming language.

There are other things too, like how print used to be written like a keyword not a function for some reason, and enforced indentation instead of braces or "end" keywords, all just really bugged me. It felt like somebody made YAML Turing complete...

Re:An Ode to Ruby by iterati on Monday January 10, 2022 @10:59AM (#29876788)
print([x + 1 for x in [1,2,3]])
Re:An Ode to Ruby by KerrAvon on Monday January 10, 2022 @01:10PM (#29878911)
This really goes to the heart of the problem with modern Python. It's lost the simplicity of the language which was the whole point of it in the first place. OO and functional paradigms were bolted on to varying degrees of success, but an outsider can no longer look at average Python code and understand it at a glance.
Re:An Ode to Ruby by gmfawcett on Monday January 10, 2022 @07:39PM (#29885407)
List comprehensions were added to Python in version 2.0, which was released 21 years ago. That was about six years after Python 1.0 was released. Are you seriously pining for the simplicity of Python 1.x? (Most of the "outsiders" you're talking about were in elementary school at the time, I don't think they were reading a lot of Python!)
Re:An Ode to Ruby by travv0 on Monday January 10, 2022 @02:47PM (#29880853)
> Even Haskell has dot notation to chain functions since it's just so much easier to read and write...

Are you referring to function composition?