Live data from Hacker News

Why Ruby Is More Readable Than Python

confuzeus.com

71–80 of 149 posts

Re: Why Ruby Is More Readable Than Python

#71

Subjective opinion presented as fact? Say it ain't so.

You get facts from measuring devices, not people. And even then, when you read the number on the display, or try to figure out if the device is functioning correctly, the facts instantly become opinion again. If it helps you, prefix everything that everyone ever says from now on with "It is my opinion that..." e.g. "it is my opinion that it is 6 o'clock."

The "that's just your opinion, man" thing is the only thing I'd like to see as a universally ban-worthy offense on the internet. It's an entirely empty statement that can be made about anyone who said anything, is always a bitter defense against somebody who took the risk of putting themself out there, and shouldn't be seen as anything but a troll.

And I'm fully aware that this is my opinion, which is why I said it and not someone else.

Re: Why Ruby Is More Readable Than Python

#73
post #65

Earlier quoted context omitted.

No, unfortunately. This is one thing I've always wished Ruby had.

Ruby is object-oriented, for better or for worse. Similar to Java, you can have static methods, but they have to live in a class (or module in Ruby's case).

I assumed OP was asking if Ruby had a way to import specific functions from a module (i.e. "from math import pi".) the way that many other languages (like Python) support. Instead, Ruby forces you to require the entire module, which makes tracking public interface usage harder.

Re: Why Ruby Is More Readable Than Python

#74

Does Ruby have support for just exporting functions around? All these examples are class based. When I was a Python programmer, we found functions scaled infinitely better over time (with the exception of data classes, unfortunately) for complex business logic especially.

Not sure what you mean. You can do… module Foo extend self def bar “Bar!” end end Foo.bar #=> “Bar!” And you can include that module in other modules. No classes required.

In python you can ‘from foo import bar, buzz’ and get JUST those two functions, without having to prefix them or clobbering your namespace.

This really nice when the one function you need is giantlib.helpers.foobar.convert_baz_to_qux - it’s both less bytes (especially if you are calling it a lot) and more importantly to the next reader of the code it means that c_b_to_q is the only thing you’re using in giantlib

Re: Why Ruby Is More Readable Than Python

#75
post #59
post #9

Earlier quoted context omitted.

This is a matter of style; we encourage writers to write this way and trust that readers know the difference between fact and opinion. Go through a typical college writing class and the teacher will direct you to delete phrases like “I think” and “I believe” from your writing.

What concerns me is that I see quite a lot of writers who don't know the difference between fact and opinion. Without that, the reader doesn't have much hope. Especially when the writer has some incentive to muddy the waters. I'm all for pieces clearly from a personal perspective. There one can drop the redundant "I think" bits. But often dropping the qualifier turns it from a statement about one person to a universa…

> "Which programmers find Ruby more readable than Python?"

What if you don't care about analyzing the psychologies of programmers, and just want to say why one thing is more readable than another thing?

Re: Why Ruby Is More Readable Than Python

#76

Earlier quoted context omitted.

Oh. So this is why clickbait and trolling have increased so dramatically? The kids are being encouraged to do it by their teachers? Eternal September gets worse when their teachers are teaching them bad habits from the get-go.

you think click bait and trolling have increased dramatically In your opinion eternal September....

Not that way - only when it's someone else's opinion, not mine.

Re: Why Ruby Is More Readable Than Python

#77
post #62
post #57

The article closes with this thought: > While both languages are much easier to read than say, PHP or Java, [...blah blah blah...] Which leads me to wonder: Have there been any serious studies of the readability of programming language syntactic and semantic conventions? For instance, a good friend of mine (whose day job is working as a software consultant, and whom I imagine would disagree with the author's assertio…

PHP has a bunch of hacks that are here for technical reasons. Function names are inconsistent and terse because they were inherited from C, and there is the historical name-resolution quirk. The prefixed variable names don't bring anything and are not here for any good reason (compared to shell where "naked" identifiers are interpreted as strings). A lot of the object-oriented features had to settle for unusual token…

I agree with your specific assessments here, but I was trying to get at the question of whether there are meaningful and measurable differences in the broad-scale accessibility of e.g. whitespace-centric syntax vs lispy syntax vs curly-brace syntax.

Admittedly, it's hard to tease this apart from the standard library and communal conventions of any given language: Java occasionally devolving into an endless sequence of ProducerFactoryFactory.newProducerFactory().initializeProducerBuilder(new ProducerBuilder())... certainly impacts its readability in a practical sense, just as the Haskell community's perhaps ill-advised love of point-free programming and highest-order polymorphism doesn't always do it favors on the readability front. Those sort of details seem like they'd really complicate a rigorous and systematic study, but on the other hand, lacking a good methodology has never stopped _other_ supposed quantitative studies of programming languages as they relate to e.g. "developer productivity" and "defect rates," so who's to say...

Re: Why Ruby Is More Readable Than Python

#78

I find Ruby to be more straightforward than Python. In isolation, I’d argue Ruby is greatly more readable and understandable than Python. In practice, Ruby code isn’t. Once someone starts doing advanced meta programming, get the shovel, because you’re going to kill whoever wrote it and need to bury the body. Rails largely gets away with this by having opinionated design, good documentation, and a large user base who…

I think that misses the point. Ruby doesn’t have macros! The metaprogramming makes it possible to create very readable DSLs but it’s all very consistent not “magical” like macros. At the end of the day coding is hard. I’d rather have nice DSLs to learn than verbose spaghetti to read.

Absolutely. DSLs are a great application of metaprogramming. Same with libraries like ActiveRecord.

Metaprogramming in a pull request at work? Nope. I'm going to smack some knuckles with a ruler. :)

Re: Why Ruby Is More Readable Than Python

#79

Does Ruby have support for just exporting functions around? All these examples are class based. When I was a Python programmer, we found functions scaled infinitely better over time (with the exception of data classes, unfortunately) for complex business logic especially.

I think the smallest footprint would be a module ? Importing a module add all the functions declared in the module to your current scope. From memory, you can't restrict to one or two specific functions, but in practice it's rarely an issue.

Re: Why Ruby Is More Readable Than Python

#80

Interesting. Even with the examples given, I found Python considerably easier to follow, with the possible exception of the inheritance example. Just goes to show how subjective it all is!

I agree, ruby's @ and @@ probably will make it a bit harder to read for anyone that is new to both languages, plus it seems more lengthy to me, python wins.

As an aside, it's bad practice to use @@ variables (IMO), they're easily clobbered. Class instance variables are much better[1].

I might also add, if you create getters for an instance variable then you don't need to use the @, except in the getter itself (and you don't even need to do that as there is the `attr_reader` helper for that).

[1] https://maximomussini.com/posts/ruby-class-variables

Post reply on HN