Live data from Hacker News

Why Ruby Is More Readable Than Python

confuzeus.com

21–30 of 149 posts

Re: Why Ruby Is More Readable Than Python

#22

I find it odd that getters and setters are implemented in Ruby … manually. attr_accessor is the idiomatic way to do it (or attr_reader / attr_writer if you want more granular control).

It's for encapsulation. You can switch them out for a method with logic without changing your interface. I don't know Python very well - is that the same there?

Apologies - I mean “the author implemented their getters / setters in the ruby example by writing actual methods by hand. The idiomatic way to do it in ruby is to simply write: “attr_accessor :title”.

There’s no change in interface needed in the ruby example if you decide that you want to replace that with fully-written getter/setter methods like the post shows; attr_accessor generates exactly those same signatures for you.

Re: Why Ruby Is More Readable Than Python

#23

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

Weird criticism. If I say that halloumi is better than tofu, do you not assume I'm talking about my personal opinion? Do I need to make it painfully clear that it's my subjective opinion? Taste, as much as readability, are subjective so that can be assumed. Also, if you read the post, you'll have noticed the author is constantly saying "I find this more readable", and engaging the reader with "what do you think?" que…

> Do I need to make it painfully clear that it's my subjective opinion?

Yes. Because a sentence written in the Arial font, as much as I might find that font distasteful, is more readable than the same sentence written by a Captcha-generator.

A bubble-sort written in Golang is easier to read than the same bubble-sort written in Brainfuck.

Yes, there are exceptions to the rule (I imagine someone who knows Brainfuck, but doesn't know Golang for example), but the rule is very clear in both cases. The clickbait flamewar-inducing headline is saying, essentially, Ruby is the former in the examples I gave, and Python the latter.

We're not junior-high students trying to one-up one-another with cute gotchas. We're technical professionals. We should expect higher standards of communication skills from other technical professionals.

If you mean "I have a useless opinion that no-one should care about," then state it. If you mean "I have statistical evidence that most technical professionals will be able to comprehend programs written in Ruby better than the same programs written in Python," then state it. But don't expect a good reaction when you say the former, while tricking us into thinking you were saying the latter.

Re: Why Ruby Is More Readable Than Python

#24

I find it odd that getters and setters are implemented in Ruby … manually. attr_accessor is the idiomatic way to do it (or attr_reader / attr_writer if you want more granular control).

It's for encapsulation. You can switch them out for a method with logic without changing your interface. I don't know Python very well - is that the same there?

Yes, you can replace attributes with properties without changing the consuming code. For example:

    >>> class Foo:
    ...     @property
    ...     def bar(self):
    ...         return "hello from a property"
    ...     @bar.setter
    ...     def bar(self, value):
    ...         print(f"tried to replace bar with {value}")
    >>> Foo().bar
    'hello from a property'
    >>> Foo().bar = "asdf"
    tried to replace bar with asdf

Re: Why Ruby Is More Readable Than Python

#25

Earlier quoted context omitted.

It's for encapsulation. You can switch them out for a method with logic without changing your interface. I don't know Python very well - is that the same there?

You can override the relevant dunders, but why would you.

> but why would you

To migrate an API - that's what I said.

Re: Why Ruby Is More Readable Than Python

#26

Earlier quoted context omitted.

It's for encapsulation. You can switch them out for a method with logic without changing your interface. I don't know Python very well - is that the same there?

Yes, you can replace attributes with properties without changing the consuming code. For example: >>> class Foo: ... @property ... def bar(self): ... return "hello from a property" ... @bar.setter ... def bar(self, value): ... print(f"tried to replace bar with {value}") >>> Foo().bar 'hello from a property' >>> Foo().bar = "asdf" tried to replace bar with asdf

I know it's completely subjective and intellectually irrelevant, but wow I think those annotations are super ugly. In Ruby it's all just method calls - properties, methods, user control-flow, everything.

Re: Why Ruby Is More Readable Than Python

#27

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…

That really mirrors my experience as well. Ruby is a very consistent language but I think one of the things people get really enamored with Ruby is the meta programming -- myself included and soon you're going to need a bunch of context in your head to understand all the "magic" that's happening.

Re: Why Ruby Is More Readable Than Python

#28
Ruby, like so many other good things, is best enjoyed alone :-)

I've loved every Ruby codebase that I've written. I still consider it one of my favorite programming languages, and (in pedagogical terms) one of the best languages for learning "practical" functional programming (point-free style, blocks as intuitive closures, &c.). But when I work with others, I find that all of the things that I love are obnoxiously clever to others, and that the things they love are obnoxiously clever to me.

Python isn't immune to that kind of cleverness, but subjectively it's not as common. I chalk that up to the higher pain threshold for doing really obnoxious metaprogramming in Python, a lower community tolerance for unidiomatic interfaces, and (broadly) better QA tooling (RuboCop is great, but MyPy + isort + Black + flake8 is really hard to beat).

Re: Why Ruby Is More Readable Than Python

#29

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…

> 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.

Metaprogramming in application code is one of those trends I'm glad is behind us. Might look cool and work great initially, but a painful refactor is near inevitable once there's been some turnover on the team and the problem space shifts in a way that invalidates the underlying assumptions.

Library code is another matter though.

Re: Why Ruby Is More Readable Than Python

#30
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.

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....

Post reply on HN