4 ms·
This might be tangental, but the syntax of having magic methods be surrounded by double underscores always drives me insane. For a language designed around rea
by zanny 15y ago
This might be tangental, but the syntax of having magic methods be surrounded by double underscores always drives me insane. For a language designed around readability, it seems like the python dev team just kicked the can on things like __init_ and said "Sure, we have a few dozen english words already restricted usage in the language, but let's kick the whole "pretty" thing out and start wrapping every special statement in ugly underscores like its 1995 again!".
They probably started this trend around 1995, now that I think about it, ya know. since the language is that old and all.
It is still really annoying, I just cringe when I use __init__ constructors because they look so ugly in otherwise very English-document-like source.
</rant>
- njharman 15y agoSpecial methods are special. It is a feature that they look different and stand out.
- batista 15y agoWell, they could stand out with some better say. How about a "special" keyboard? def special init() How about @? def @init() or :: def special::init() or, all caps, like Go does initial-cap for exported members: def INIT()
- lclarkmichalek 15y agoWell @ is taken by decorator syntax. I like the python way however (probably due to using python a lot). Special methods are special so it does make sense that they look different, and python all ready the convention that underscores in front of them function name indicate the function shouldn't be accessed directly, and that is true for special methods. When was the last time you called __init__ directly (discounting uses inside another __init__ method)? Most likely never. I guess it's personal preference, but that naming convention saves me a lot of time when calling die on an object; I know I can basically ignore anything after the first name beginning with an underscore.
- njharman 15y agoI find all caps much more horrid than __foo__. Welcome to the bikeshed.
- nyellin 15y agoPersonally, I love the __names__, as they instantly identify magic methods and there are never naming conflicts. Contrast this with Java where a newcomer might name their own method toString() or readObject() by accident.
- Ingaz 15y agoI like underscores for all magic methods. And I think you're right about __init__ - constructors are not magic. But in fact, I like "word" __init__ even more outside of python. I use it to name directories for all new, incoming, uncategorized stuff. For example: I have "music" with subdirectories named by artist, and I have __init__ where I put all artists I found recently. Same for "books", "docs", "work", etc. I like it because "__init__" is always on top. Compare it with "new", "incoming", "now", "unclassified".