[Tutor] Good Taste Question: Using SQLite3 in Python

Alan Gauld alan.gauld at btinternet.com
Wed Apr 29 18:43:19 CEST 2015


On 29/04/15 17:03, Jugurtha Hadjar wrote:

>>>          (__, cursor) = self.init_db()
>>
>> Don't use the __ 'variable' here, be explicit, it makes
>> maintenance much easier.
>>
>
> I actually searched specifically for something like this. In MATLAB,
> there's the ~ that does this. I'm not trying to write Python in a MATLAB
> style, but I was glad I found it here:
>
> http://docs.python-guide.org/en/latest/writing/style/#create-an-ignored-variable

I've seen this before and strongly disagree with it.
I suspect the author has never had to run a major
maintenance project!

A single underscore is, I agree, far worse that a dunder symbol
but both are a maintenance nightmare. They are ambiguous,
difficult to remember, easy to overlook and if you change
your mind and decide you need to use it later it's a whole
new name to go back and introduce (or worse be tempted to use the 
meaningless symbol). And if you need another 'throw-away' name
later you use the same one, then forget there are two uses
and try to use it anyway (even in debugging) and get
completely wrong values, that may or may not look different
to what you expect. (looking different is good - you can
detect it easily, looking similar is very, very, bad!)...
its just a horror story waiting to trip you up.

It's far better to have a short meaningful name that is never
used than a bland, meaningless, generic symbol.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Tutor mailing list