Live data from Hacker News

Ruby 3.2.0 is from another dimension

tomaszs2.medium.com

271–280 of 341 posts

Re: Ruby 3.2.0 is from another dimension

#271
post #187

Earlier quoted context omitted.

> I would argue Python is very consistent in its design, it aims to only have one obvious way to do things This argument is dead the second one stumbles upon the string interpolation/formatting situation. Or the list comprehensions, ew.

For the benefit of those not familiar with the Python string interpolation/formatting situation, I present 4 ways to perform the same string formatting: who='World' #1 - string concatenation 'Hello, ' + who + '!' #2 - % operator 'Hello, %s!' % who #3 - format() method 'Hello, {}!'.format(who) #4 - f-strings f'Hello, {who}!'

Don't forget all the variations on how to use the format() method.

    # In order
    'Hello, {}!'.format(who)
    
    # Numbered
    'Hello, {0}!'.format(who)

    # Named
    'Hello, {name}!'.format(name = who)

Re: Ruby 3.2.0 is from another dimension

#272

Ruby 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…

So, how do you reconcile this opinion with the fact that Ruby can't even do a proper REPL on Windows? It just starts showing weird output, overwriting lines and doubling up other ones... that other language just works. And look, I LOVE Ruby. I come from twentyish years of Perl, and I really like the way Ruby feels when banging out a script but these days, time is in short supply, and I just don't have time to screw a…

> I don't think it's quite fair to throw this much shade at Python when Ruby hasn't really addressed any of the things that makes Python so popular

My issue is that most companies using Python probably don't need the Python-only libraries. Aside from the fantasy AI point I originally mentioned, I think Python is the PHB's choice (like the mauve database) because that's what they've read in or heard in their circles, or because the first person building the webapp wants Django's built-in admin interface (which always becomes a problem later, like apps in Excel become problems later).

> Rubocop

Yes, it is fairly standard. And I dislike it like I dislike Black (Python's PEP8 dominatrix). Although Rubocop goes well beyond by giving you often helpful advice about optimization choices or unnecessary code. I like it for that, but I want to format in a more column-oriented way than Rubocop or Black allow (without config mods).

Black is a horror show to me. It's almost like it was designed to chew up as much vertical whitespace as possible. It's not as bad as PHP norms, but it really does like to turn pleasant tight blocks into twice as many lines and extra ( ) (out of necessity, since Python can't deal with linebreaks well).

Re: Ruby 3.2.0 is from another dimension

#273

Earlier quoted context omitted.

[dead]

Honestly I don’t agree. In my experience Rails easily becomes a rat’s nest of magical code that is nearly impossible to read. A bajillion imports leads to code being pulled in from who knows where.

This is really a matter (or problem) of how people use Rails. I am very much not a fan of magic, and I prefer explicit over implicit.

You cannot use the same approaches for serious, big Rails projects as you might for quick and dirty proof of concepts. And by that I mean OO, mixins, fat models, overemphasis of ORM, etc. will hurt down the road. But most of these same points are true for Django too.

The better way to use Rails is for the core features, and then keep the business logic in modules in "services" (just domain specific organized modules which have little or no dependency on Rails, and are therefore super easy to write complete tests for).

An organically grown Rails project that started as an MVP will predictably turn into a ball of sadness if not refactored significantly at various stages in the life of the project.

Re: Ruby 3.2.0 is from another dimension

#274
post #46

Earlier quoted context omitted.

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…

> * Ruby was created as a personal, hobby project; Python was created while Guido worked in research institutions, and it helped Python gain recognition in academia environment As a data point, I remember interviewing for an internship in a research institution doing some work on medical images around 2002/2003 and the supervisor telling me that Python was the lingua franca in this domain (from a research and POC dev…

While I was at CERN during early 2000's, it was already being used for the build tooling and package management of HLT.

Trainings for getting Python skills were a common offering.

Re: Ruby 3.2.0 is from another dimension

#275
post #222

Earlier quoted context omitted.

PHP got popular coz it could get barely code-literate HTML/CSS web designer to write a dynamic app, and host it easily Ruby got popular coz Rails could get barely code-literate graduate to write CRUD app and so it was cheap (famous 15 minutes to blog tutorial) for companies. JS got popular coz, well you ain't got fucking choice on frontend and having your then-frontend JS/HTML/CSS designer be able to also do backend…

I'm gonna disagree with "Ruby got popular coz Rails could get barely code-literate graduate to write CRUD app and so it was cheap (famous 15 minutes to blog tutorial) for companies." That's not what happened, instead Ruby got popular with advanced web developers working in Java who saw that Rails was had better answers than J2EE. If you were barely code-literate graduate you wouldn't recognize that Rails was offering…

I was doing J2EE and was hardly surprised with Rails.

We did Rails one decade earlier with our own version of AOLServer.

The very reason we went to .NET (as beta testers during its availability only to MSFT partners) was because we were fed up having to rewrite TCL into C due to performance issues.

All the Active Record stuff was already something that AOLServer introduced, and we had an improved approach on our product.

The founders of that company went on to create OutSystems based on our learnings.

Re: Ruby 3.2.0 is from another dimension

#276
post #250
post #222

Earlier quoted context omitted.

PHP got popular coz it could get barely code-literate HTML/CSS web designer to write a dynamic app, and host it easily Ruby got popular coz Rails could get barely code-literate graduate to write CRUD app and so it was cheap (famous 15 minutes to blog tutorial) for companies. JS got popular coz, well you ain't got fucking choice on frontend and having your then-frontend JS/HTML/CSS designer be able to also do backend…

> JS got popular coz, well you ain't got fucking choice on frontend and having your then-frontend JS/HTML/CSS designer be able to also do backend is, well, again, easy and cheap. IIRC, a bigger reason for Node's popularity (at least at the very beginning of its popularity) was the fact that it had event-based I/O, which let a single process handle a lot more in-flight requests than Ruby (where the concurrency model w…

Famous TCL paper from 1995, regarding event based programming.

"Why Threads Are A Bad Idea (for most purposes)"

https://web.stanford.edu/~ouster/cgi-bin/papers/threads.pdf

Re: Ruby 3.2.0 is from another dimension

#277

Earlier quoted context omitted.

Python lambdas are not great but Ruby not having first-class functions is also not great. Neither are perfect and there is no syntactic reason outside of variations of personal taste to choose one language over the other. There are a boatload of compelling reasons to choose Python for its libraries and documentation and adoption level, though.

I didn't know Ruby didn't have first-class functions but that's already a massive no for me. You don't need to convince me regarding Python though - it's too convenient to pass up. And despite its shortcomings it's certainly not a language devoid of elegance like some in this thread are painting... Like the old adage goes, there's the languages nobody uses, and there's the languages people talk shit about. Or in simp…

I have no idea what they mean by Ruby not having first-class functions. Of course it does. It's a fundamental feature of the language.

Re: Ruby 3.2.0 is from another dimension

#278

Ruby 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…

If this comment is indicative of the general attitude of the Ruby / RoR community then I can’t exactly say that I’m jumping up and down to get involved. I feel like I’ve been transported 10-15 years back in time with this ridiculous negativity. Django and RoR are much of a muchness. Ruby and Python are too, to a lesser extent. This whole thing stinks of narcissism of small differences and sour grapes. To imply that e…

I refer to The Blub Paradox - http://www.paulgraham.com/avg.html

I have used both languages extensively, off and on for nearly 20 years. I've also used C, C++, Java, and built some small projects with Clojure and Elixir.

Of course people have differing sensibilities when it comes to aesthetics, but at a certain point equally observed options can be compared - with one being recognized as better.

I don't put down Python or Pythonistas because I dislike them; I just voiced my frustration that so many companies choose Python when I obviously believe there are better choices (particularly similar complexity/feature options like Ruby).

Clumsy, an incomplete comparison:

Python

OOP

Having to explicitly pass self.

Not having public/protected/private members. Ruby does, including convenience attribute reader/writer functions. And in Ruby you can still provide your own custom methods. In Python, you have to keep an internal _attrname and then have some set_attrname function if you want to provide special logic on your setter.

General recommendation to not use dunders, except that you should define dunders such as __init__ and __str__ for many classes. Ruby's class initializer is an optional method called... "initialize". (Principle of least surprise.) It also has a standard of to_something() methods which return the object in different formats, such as to_str, to_i, to_f, etc. More on this later.

Built-in functions:

sorted(), a past tense verb, doesn't "sorted" a list, it gives you a sorted copy of a list. Not to be confused with list.sort(), which also sorts but returns nothing and mutates list.

next(), which mutates the iterator you pass it. Most other built-ins do not mutate their arguments.

int(), float(), sorted(), next(), etc. all only work for certain argument types. The way to know is just to know. In Ruby, these would be object methods. And you could know if you could do foo.to_i (convert to int) just by asking "abc".respond_to?(:to_i).

Incidentally, Python's int("abcd") raises an exception, while int("1") works as expected. You can't ask the string "can you be converted to int?" Now maybe converting strings to ints is unwise in general, and that's fair. But the ergonomics here are... not good.

And regarding sorted() vs foo.sort(), in Ruby we have foo.sort (non-destructive, returning a sorted list), and foo.sort! (mutates in place). The ! indicates a more significant impact of the function compared to the non-bang version.

Elsewhere in the threads I illustrate list comprehension vs Ruby's collection methods and blocks.

Ternary operator:

Many languages: flag_set ? 1 : 0

Python: 1 if flag_set else 0

This is an if else. So written as an if else, it would be:

if flag_set

  1
else

  0
The Python ternary operator rearranges this logic.

But! In Python you can't do "1 if flag_set". Ironically, that's fine in Ruby.

Speaking of block return values... (from the imperative if/else above)...

Ruby:

x = if flag_set

  1
else

  0
end

You cannot do this in Python because conditional blocks do not return a value.

It is common in Ruby to say x = case(foo) ... and each match will have a value. The value of the expression in the case which matches is used to set x. In Python (now that you finally, as of 3.10 actually have a switch statement), you must repeat the x = expr for each match.

I will say I'm amazed that after so long of no switch statement in Python, they chose to build one with pattern matching reminiscent of Elixir's.

If I were to dig through my memory I could find more examples of Python oddities. My decision to merely compress it all into one word - clumsy - was to avoid getting into these details, particularly since the assumed audience was Ruby users based on the topic.

Re: Ruby 3.2.0 is from another dimension

#279
post #37

Earlier quoted context omitted.

> Maybe like blockchain, once the AI/ML fantasy hype dies down Two minutes of silence for the poor sods who still thinks that AI/ML is pure hype. (Granted, there is hype. But there is much real stuff.) And, also, blockchain and ML/AI are nothing similar, except for Twitter bottom-feeders trying to milk each. AI/ML already has real applications with hundreds of millions of dollars actual value created. And just like C…

>AI/ML already has real applications with hundreds of millions of dollars actual value created. Hundreds of billions a year probably (and that may be low) if you count online advertising and large consumer facing sites in general. If you turned off the ML behind Facebook/Google/Netflix/Amazon then you'd be lucky to only lose 50% revenue based on my personal experience of adding ML on top of such products.

[deleted]

Re: Ruby 3.2.0 is from another dimension

#280

Ruby 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…

>once the AI/ML fantasy hype dies Sure. Once all of online advertising, search (web, ecommerce, specialized sites, etc.), image editing, spell checking, recommendations (streaming, ecommerce, email, marketing, etc.) and a hundred other things cease to exist. Or more broadly once every large consumer facing company decides, for whatever reason, that it'd prefer to make significantly less money. People talking about th…

What percentage of companies (including startups) that use Python are using anything more than Django/Flask/sqlalchemy and the usual network modules?

I did not say that AI/ML is not useful. But I'm quite sure that some (many) of the companies using Python are not doing any of that - even if they say on their pitch deck that they are or will.

Post reply on HN