News for hackers. Stuff that matters.
Re:Self Hell in Python by fred256 on Sunday January 04, 2015 @12:08PM (#8835002)
Note that the name "self" is a convention, not a requirement. If it's just the amount of keystrokes that you're concerned about, name it something else like "o".

Of course, good luck having someone else understand your code...

Re:Self Hell in Python by anindyabd on Sunday January 04, 2015 @12:14PM (#8835030)
Did not know this. Thought self was equivalent to this in Java. Mind = blown.
Re:Self Hell in Python by raverbashing on Sunday January 04, 2015 @12:53PM (#8835160)
See, you pass it as a parameter

So it can be called anything you want

BUT DON'T DO IT! Because you'll break the convention and anyone who maintains your code after that will hate you.

Re:Self Hell in Python by eatonphil on Sunday January 04, 2015 @02:20PM (#8835451)
You can ALSO declare a class member function in a different file. Since it just accepts self as the first parameter... It still works.
Re:Self Hell in Python by abecedarius on Sunday January 04, 2015 @12:32PM (#8835091)
Peter Norvig once proposed using '_' but got shot down.
Re:Self Hell in Python by kevin_thibedeau on Sunday January 04, 2015 @12:54PM (#8835165)
'_' is already idiomatic for throwaway variables. It wouldn't help matters to use it for OOP.
Re:Self Hell in Python by raymondh on Sunday January 04, 2015 @01:33PM (#8835307)
In the Python world, '_' is used in three different ways:

* As a throw-away variable:

    >>> a, b, _, c, d = f(t)
* As a gettext call:

    >>> print _('Welcome to Python')
* And at the interactive prompt as the result of the previous expression:

    >>> 3 + 4
    7
    >>> _ * 10
    70
Re:Self Hell in Python by pluma on Sunday January 04, 2015 @02:14PM (#8835431)
As most of my Python involves localized Django, I twitch every time I see `_` used for anything other than some variation of gettext.
Re:Self Hell in Python by lazzlazzlazz on Sunday January 04, 2015 @03:19PM (#8835660)
Weird, since the gettext use-case is definitely the least idiomatic and least common use of `_`.
Re:Self Hell in Python by pluma on Monday January 05, 2015 @04:41AM (#8838039)
As I said, most of my Python involves localized Django. So gettext is used everywhere and (apart from the REPL) it's the other uses of `_` that are the odd ones out.
Re:Self Hell in Python by Walkman on Sunday January 04, 2015 @02:34PM (#8835503)
that's why you should use '__' as throw-away variable (two underscores)
Re:Self Hell in Python by bobisme on Sunday January 04, 2015 @05:03PM (#8836051)
Wow. How did I go years without knowing this about the repl?
Re:Self Hell in Python by collyw on Sunday January 04, 2015 @04:59PM (#8836037)
Its a really crap variable name as well. I posted on Stack Overflow asking what it was doing, assuming it was some Python syntax, only to be pointed to the import at the top of the file, which was being renamed to "_". Give variables meaningful names please.