R

Rafe Kettler

rafekettler.com · Personal blog · on HN since 2011

Rafe Kettler, a developer, wrote a guide to Python's magic methods and posts on design and the LulzSec password leak.

What HN saysHN links it for the magic methods guide, cited as a reference, though one commenter says some of its patterns are incomplete or frowned upon.
16HN people shared it
9linked it in comments
7stories submitted
402story points
10 years agolast shared
2011people per year2026

Most-shared posts

  1. 1
    A Guide to Python's Magic Methods
    15 people · 399 points · first shared 2011 · 27 comments on HN
  2. 2
    Design for developers
    1 people · 3 points · first shared 2012 · discussion on HN
  3. 3
    Analyzing the lulzsec password leak
    1 people · first shared 2013

What HN people wrote when they linked it

tomkinstinch · 2014-11-27
ivank · 2016-05-30
http://www.rafekettler.com/magicmethods.html#appendix1 and you can call them directly: >>> (3).__neg__() -3
orf · 2015-12-21
More than just built in functions, any object that defines a __len__ and a __index__ method (that provide len(x) and x[0] respectively) can also be iterated over in a for loop ('for item in instance'). A good reference for magic methods is [1] for anyone interested. 1. http://www.rafekettler.com/magicmethods.html
bru · 2014-02-28
Several of those patterns are incomplete or frowned upon: * if a method does not use the object's state (no `self` usage) make it a `class-` or `staticmethod`. * Some magic methods are presented. There's more to them[0]. * one should not write `class MyClass:` but `class MyClass(object):` (new style class[1]) * the last one (`return None`) make me very dubious * Cascading methods: that's a big no. The idiom is that if a method may change the state of the object then it should return None (eg `set.add`) 0: well-written and comprehensive guide: http://www.rafekettler.com/magicmethods.html 1: http://www.python.org/doc/newstyle/
goldenkey · 2013-12-23
Methods taking "self" as an argument is a dirty hack, ain't no magic there. The language is just pretty ugly. It's got the whole whitespace thing going on, which is forced, and some might think it gives a good aesthetic but that is dust in the wind in terms of help for Python's ease on the eyes. The whole standard namespacing and mix of oop/procedural global functions is just..schizophrenic, the capitalization scheme is dastardly. I haven't seen many languages that look more _basic_ than python. It's a frankenstein of Perl/Ruby and Basic. Forced verbosity is egh. Here's your magic methods and properties: http://www.rafekettler.com/magicmethods.html Those magic methods kind of remind me of clever hacks while coding in PHP.
rafekett · 2013-11-03
yen223 · 2013-04-11
A nifty resource for those who are exploring Python's magic methods: http://www.rafekettler.com/magicmethods.html
jmount · 2012-11-25
The ongoing obsession with direct to github store links is irritating. Why not post a link to a designed start of reading point like: http://www.rafekettler.com/magicmethods.html ? Or to https://github.com/RafeKettler/magicmethods/raw/master/magicmethods.pd… so we can share the pleasure of the Scribd cabal screwing up the link and "annoyance wall" the content.
scott_s · 2012-03-18
Honestly, I'm not sure if you can do that in Python - one of the side-effects of not writing classes in Python is that I'm also ignorant of the behind-the-scenes stuff that goes on with them. You may be able to get something close to what I wrote with a function that returns a closure, but I don't think you can get exactly the for x in y syntax. As explained in another post on HN's front page, "A Guide to Python's Magic Methods": http://www.rafekettler.com/magicmethods.html#sequence, you need to define the __iter__(self) method on an object to support that style of iteration. (And that method needs to return an iterator object.) And that brings us back to the same point I already made, but I think it's so important that I'll say it again: the abstractions you choose to represent concepts in your program will be determined by what is easy in the language you're using.

Keyboard shortcuts

/Search
j kNext / previous blog
EnterOpen selected blog
vVisit the blog site
fFollow / unfollow
lSwitch grid / list view
dSwitch dark mode
g hHome
g pTop posts
g tTopics
g fFollowing
g lLiked
g yHistory
g qFAQ
EscBack / close