Re:Why Is the Migration to Python 3 Taking So Long?
by coldtea on Thursday November 14, 2019 @02:43PM
(#21538648)
>Having to reference self makes it more clear where data is coming from and makes navigating an unfamiliar code base much easier.
I don't understand this. Aside from people seeing an OOP for the first time in their life, are they getting confused about where "this" comes from?
How would an implicit "self" a la "this" make it any less understandable where the data come from?
How is passing self making "navigating an unfamiliar code base much easier"? Aside from total newbs who see an OO codebase with an implicit instance variable for the first time?
Re:Why Is the Migration to Python 3 Taking So Long?
by fireflash38 on Thursday November 14, 2019 @02:57PM
(#21538781)
I believe the original commenter was more referring to the lack of 'this' usage in Java.
So instead of having:
this.x = y
People tend to do: x = y
Which isn't always the most clear that it's referencing an instance variable rather than a scoped variable, especially if you see it midway through a method.
Re:Why Is the Migration to Python 3 Taking So Long?
by coldtea on Thursday November 14, 2019 @03:49PM
(#21539241)
A, alright then. I'd go with making this mandatory in that case.
Re:Why Is the Migration to Python 3 Taking So Long?
by dfinninger on Thursday November 14, 2019 @02:07PM
(#21538319)
To your last point, check out Dataclasses[1].
@dataclass
class Foo:
arg1: str
arg2: int
arg3: int = 5 # default value
I use them a lot in my 3.7+ projects. It helps reduce the boilerplate for typical classes. (Where for me, typical classes are a 1:1 mapping of inputs to attributes)And if you need to compute some values at object initialization, then they have a __post_init__() hook you can use [2].
[1] https://docs.python.org/3/library/dataclasses.html [2] https://docs.python.org/3/library/dataclasses.html#post-init...
Separate from that, I think that would be a much bigger breaking change than you think. __setattr__ and __setattribute__ means that self.y doesn't necessarily refer to a traditional attribute so without self you could end up with either:
1. `x = y` where the expression `y` executes code
or
2. `x = y` where `x = ???` and `x = self.y` where `x = self.__setattr__('y')`.
That said, I do think the language could use something to reduce the size of __init__() since
self.arg1 = arg1
self.arg2 = arg2
self.arg3 = arg3
...
can get pretty verbose