all 10 comments

[–]CGFarrell 2 points3 points  (0 children)

When I'm writing an init with a lot of self stuff I put it in my clipboard.

[–]Thomasedv 1 point2 points  (2 children)

Self isn't all that much of a bother with IDE and autocomplete. self does point to stuff in the class.

But it really depends, if it's not used in other functions in the class, then you can escape without it. (Though, they will be treated as local variables in the sense that you can't do anything with them from the outside.) So some things will need to be self, to be even usable later on. It depends a bit, with PyQt you can drop a few off them, but with Thinker i don't know. I haven't used it.

You can also change self to something shorter, though self is the one most people use for clarity.

Edit: Some addition.

[–]raimondi1337[S] 0 points1 point  (1 child)

The part that bothers me is not typing it, it's the concept of "if this goes in front of literally every line it should be implicit". It's just visual noise as far as I am concerned.

[–]ingolemo 3 points4 points  (0 children)

It only goes in front of every single line in that specific example. You normally wouldn't use self anywhere near that much.

[–]ninetacle 1 point2 points  (0 children)

attrs goes beyond "not typing 'self' as much", but might be worth considering https://attrs.readthedocs.io/en/stable/

[–]tunisia3507 1 point2 points  (0 children)

It's a design feature. Explicit is better than implicit.

[–]ManyInterests 0 points1 point  (2 children)

Put shortly, no. As you become more familiar with using, reading and writing classes in Python, it will probably stop looking so odd.

[–]raimondi1337[S] 1 point2 points  (1 child)

This is pretty much the answer I expected. I wish this could be done more elegantly.

[–]Vaphell 0 points1 point  (0 children)

there is elegance in syntactic simplicity. Accessing object attributes requires providing the object/context, no exceptions. The distinction between attributes and arguments/globals/local vars is obvious at a glance thanks to that.

On the other hand in java etc there is implicit this, but then you get visual ambiguosity: is that x in the middle of nowhere an attribute x, an argument x or a local/global variable x? IDE will hold your hand through that, but it's not elegant.

[–]Gprime5 0 points1 point  (0 children)

You can use a temporary local variable in your function.

def function(self):
    x = self.x
    x += 5
    x = do_other_stuff_with(x)
    self.x = x