Hacker News new | past | comments | ask | show | jobs | submit login

`add1` isn't a method, it's a function.

Besides, "static methods" are a hack:

If it's a behaviour of the class rather than its instances, then make it a method of the class. You'd only need static methods for this if your language doesn't treat classes as objects (ie. it's not a particularly OO language). The example is in Python, where classes are objects, so no statics are needed.

Alternatively, it may be a completely standalone piece of code, in which case it has no business being inside a class. Just make it a standalone function, and stick it in a module to avoid name clashes. You'd only need static methods for this if your language doesn't allow standalone functions, or doesn't have a module system. Since Python has both, there's no need to abuse classes like that.




Please read the article. I was referring to the method in the Java example. You cannot access `add1` from main since main is static


Ah yes, I replied too soon :)

Still, it's just a Java quirk that's irrelevant to the article.




Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact

Search: