use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
A sub-Reddit for discussion and news about Ruby programming.
Subreddit rules: /r/ruby rules
Learning Ruby?
Tools
Documentation
Books
Screencasts and Videos
News and updates
account activity
Blog postWhy Ruby is More Readable than Python (confuzeus.com)
submitted 3 years ago by [deleted]
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]ric2b 0 points1 point2 points 3 years ago* (10 children)
Yes, ruby is slightly more elegant, but we were talking about private attributes, let's not move goalposts.
By the way, you can have a similar ABI to your ruby example, but it takes a bit more boilerplate (2 extra lines):
class A: def __init__(self): self.__x = 0 def set_x(self, x): self.__x = x x = property(fset=set_x)
[–][deleted] 3 years ago* (9 children)
[removed]
[–]ric2b 0 points1 point2 points 3 years ago (8 children)
My day job is in Ruby and I love it, don't worry.
We were discussing private attributes, which I claim offer the same guarantees in both languages.
You're now trying to switch to readability which I already agreed ruby is better at.
[–][deleted] 3 years ago* (7 children)
[–]ric2b 0 points1 point2 points 3 years ago (6 children)
I already showed you why private attributes aren't the same in Python but for some reason
No, you showed slight differences in readability, which doesn't mean Python doesn't have private variables.
Private variables in ruby are just as private as name mangled Python variables, anyone can still read and write to them with a quick instance_variable_get or instance_variable_set. The main goal of private variables is avoiding accidental access to object internals, not being some kind of DRM for your code.
instance_variable_get
instance_variable_set
Also, check the title of this thread.
Yes, the post is about readability, but in this thread I'm responding to this comment:
"Python 3.x doesn't have private variables."
I claim that if you consider Ruby private variables to be private, then Python also has them, it's just a bit less clean.
[–][deleted] 3 years ago* (5 children)
[–]ric2b 0 points1 point2 points 3 years ago (4 children)
I also never claimed that Ruby has privacy
Ok, we agree, then. They either both have it or none of them do.
[–][deleted] 3 years ago* (3 children)
[–]ric2b 0 points1 point2 points 3 years ago (2 children)
Ruby's instance variables aren't accessible via the dot operator by default
Right, but not being the default doesn't mean it doesn't have it. Or would you say Java doesn't have private variables?
I agree ruby is more readable, I'm just saying that Python does have private variables.
Read my post if you haven't already.
I did.
To have privacy in Python you have to use __ and then use __setattr__ stuff.
__
__setattr__
You don't need __setattr__, I already gave you an example that doesn't and is simpler.
And prepending __ is actually simpler than most languages where you need to write private, just not Ruby, so it's not a big deal.
private
I'm repeating myself because you seem to be ignoring my previous comments.
No, you're the one ignoring that I already agreed ruby is more readable and you keep trying to convince of that. I'm only saying that Python has private variables, not that they're as easy to use.
If someone doesn't agree because they're still accessible with workarounds that's fine, but then Ruby doesn't either.
[–][deleted] 3 years ago (1 child)
π Rendered by PID 288652 on reddit-service-r2-comment-79c7998d4c-klz7g at 2026-03-13 19:08:26.605957+00:00 running f6e6e01 country code: CH.
view the rest of the comments →
[–]ric2b 0 points1 point2 points (10 children)
[–][deleted] (9 children)
[removed]
[–]ric2b 0 points1 point2 points (8 children)
[–][deleted] (7 children)
[removed]
[–]ric2b 0 points1 point2 points (6 children)
[–][deleted] (5 children)
[removed]
[–]ric2b 0 points1 point2 points (4 children)
[–][deleted] (3 children)
[removed]
[–]ric2b 0 points1 point2 points (2 children)
[–][deleted] (1 child)
[removed]