Skip to content

Comment on Is Go an Object-Oriented Language?parent

Comments

You still have to explicitly pass a `this` to that function, which is kind of my earmark for telling methods and functions apart. (In this regard, Python treads a fine line where it has an explicit `self` parameter that is passed in automatically).

You can manually pass in the `self` parameter to unbound methods if you like.

    import itertools

    class Test():
        def __init__( self, number ):
            self._number = number
            return

        def aaa( self ):
            print 'AAA<%s>' % str( self._number )
            return

        def bbb( self ):
            print 'BBB<%s>' % str( self._number )

    def main():
        instances = [ Test( n ) for n in range( 100 ) ]
        functions = [ Test.aaa, Test.bbb ]

        for instance, function in zip( instances, itertools.cycle( functions ) ):
            function( instance )

    if __name__ == '__main__':
        main()
AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.