Why Ruby Is More Readable Than Python
21–30 of 149 posts
Re: Why Ruby Is More Readable Than Python
#22I 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?
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
#23Subjective 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…
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
#24I 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?
>>> 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 asdfRe: Why Ruby Is More Readable Than Python
#25Earlier 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.
To migrate an API - that's what I said.
Re: Why Ruby Is More Readable Than Python
#26Earlier 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
Re: Why Ruby Is More Readable Than Python
#27I 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…
Re: Why Ruby Is More Readable Than Python
#28I'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
#29I 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…
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
#30Earlier 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.
In your opinion eternal September....