Roy Smith <[EMAIL PROTECTED]> writes: > Terry Hancock <[EMAIL PROTECTED]> wrote:
>> However, there is a slightly less onerous method which >> is perfectly legit in present Python -- just use "s" >> for "self": > This is being different for the sake of being different. Everybody *knows* > what self means. If you write your code with s instead of self, it just > makes it that much harder for other people to understand it. I always use "s" rather than "self". Are the Python police going to come and arrest me? Have I committed the terrible crime of being unPythonic? (Or should that be un_pythonic?) I rarely find code that follows clear coding conventions to be hard to understand, as long as the coding convention is reasonable and consistent. Something that I do find difficult to understand, as a contrasting example, is C++ code that doesn't prefix instance variables with "_" or "m_" (or what have you), or access them via "this". Without such a cue, I have a hard time figuring out where such variables are coming from. Regarding why I use "s" rather than "self", I don't do this to be different; I do it because I find "self" to be large enough that it is distracting. It's also a word, which demands to be read. (Cognitive psychologists have shown that when words are displayed to you your brain is compelled to read them, even if you don't want to. I experience this personally when I watch TV with my girlfriend who is hearing impaired. The captioning is very annoying to me, because it's hard not to read them, even though I don't want to. The same thing is true of "self".) With too many "self"s everywhere, my brain finds it harder to locate the stuff I'm really interested in. "s." is small enough that I can ignore it, yet big enough to see when I need to know that information. It's not a word, so my brain doesn't feel compelled to read it when I don't want to, and it's shorter, so I can fit more useful code on a line. Breaking up some code onto multiple lines often makes it significantly less readable. (Just ask a typical mathematician, who when shown notations that Computer Science people often use, laugh in puzzlement at their verbosity. Mathematicians probably could not do what they do without having the more succinct notations that they use.) Don't take any of this to mean that succinctness is always better than brevity. It quite often is not. Brevity is good for things that you do over and over and over again. Just ask Python -- it often knows this. It's why there are no "begin" and "end" statements in Python. It's why semicolons aren't required to separate statements that are on different lines. That stuff is extra text that serves little purpose other than to clutter up the typical case. |>oug -- http://mail.python.org/mailman/listinfo/python-list