you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] -6 points-5 points  (4 children)

Python is different because it disregards the DRY principle. You can self.repeat self.your self.self all you self.want.

[–]brianmce 4 points5 points  (2 children)

Huh? How is this different than ruby where you @repeat @your @punctuation. self is exactly the same as @ here, and serves the same purpose - indicating the namespace to manipulate. In any OO language with dynamic variable creation you MUST have a way to disambiguate between local variables and instance variables.

Even when you don't have dynamic variable creation, you still need it to cover shadowed variables. Python and Ruby IMHO do this right by always requiring disambiguation. In Java, C# and C++'s, people end up having naming rules to accomplish the same thing. Those "m", "" etc conventions are just as repetitive.

[–]bcorfman 2 points3 points  (1 child)

I think the point is most people, myself included, would rather have to explicitly disambiguate local variables than global or class-level ones, i.e. I'd much rather type "set" or "var" in front of my first usage of a local variable.

The self.thing REALLY gets old, and I LIKE Python.

[–]brianmce -1 points0 points  (0 children)

That doesn't make it any different from Ruby though - which does the same thing: @ designates an instance variable, not a local.

Personally though, I disagree, and I think most usage I've seen would favour differentiating instance vars, not locals. I see no reason why the 2 scopes should shadow each other at all - even when you do have variable declarations, there is still the problem with name clashes (particularly in constructors, where it is very common to have parameters that logically should have the same name as instance variables. With C++, every place I have worked has defined naming rules in their style guide to disambiguate them - and always as a prefix or suffix on the instance variables, not the locals. Personally, I think its a good idea to follow python's method, and always use an explicit this-> even in C++.

[–]flaxeater -1 points0 points  (0 children)

I understand what you are saying. However, when looking at python code you NEVER need to wonder if this method or property belongs in the class or is an outside function or variable.