Spot any errors? let me know, but Unleash your pedant politely please.

Friday 19 June 2009

from x import *

Damn. I instinctively knew this was was bad, but it was in the examples I was given before I got stuck in, and before things got complicated, and stupidly without looking to find out if there was a better way.

I have from x import * and from x import name1, name2 all through my code.

It hasn't actually bitten me yet, but I know that I need to change this. Everywhere.

In some languages, there would be no better way. This kind of import is the way things work, and if there's an ambiguity, it's a compile time issue, where things need to be made explicit/qualified when names are used, or it simply won't work.

There's a similar thing in Ada, where with x; is essentially the same as import x, but everything must be qualified. There's a use x; statement that exposes everything in x. It's not dangerous, like Python's *, but it does make it a bastard to find things. The first rule of Ada was "Never use use".

Note to self: next time I try a new language and something looks like a use, figure out how to not use that 'feature'.

No comments:

Post a Comment