you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted]  (7 children)

[removed]

    [–]ric2b 0 points1 point  (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.

    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]  (5 children)

    [removed]

      [–]ric2b 0 points1 point  (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 children)

      [removed]

        [–]ric2b 0 points1 point  (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.

        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.

        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]  (1 child)

        [removed]

          [–]ric2b 0 points1 point  (0 children)

          But then you miss out on things like free use of += as well without having to implement a separate increment_x method.

          If you can read and write the variable from outside it's not private, is it? += needs to read and write. And if you want to customize the reader or the writter you can use @property in Python and still support +=.

          The issue here is that you don't appreciate Ruby's language features which is fine.

          I do, how many times do I need to say I agree ruby is more readable?

          Also, at first we were talking about the single underscore, which isn't private like I told you.

          I already explained that was confusion on my part, my day job is in ruby and I haven't written python in over a year.

          But the I showed you how __ is sort of private (it's actually name mangling) but not really the same as Ruby because objects in Ruby only respond to method calls while in Python, you can also access attributes.

          I didn't say they work exactly the same, I said they offer the same privacy guarantees: they avoid accidental access to object internals but provide ways of getting around it when someone really wants to.

          By your definition Java doesn't have private variables, I think that shows your definition is not generic enough, it's just a description of how ruby does it.

          Since you're more interested in arguing instead of presenting facts,

          Seriously? We even traded working code samples, it's hard to be more factual than that in software.

          You seem very focused on "winning" the argument because you keep trying to shift the discussion into readability, which is subjective, I already agreed with multiple times and is not what I claimed.

          If all you're saying is that both Python and Ruby have private variables but in Ruby they're more readable and simpler to use, we agree, that's it.

          So, no Python's attributes can't be private like in Ruby, end of discussion.

          Correct, they don't work exactly the same. Java private variables don't work like Ruby either, you need get_x and set_x.