From: Guy K. K. <g....@ma...> - 2009-06-28 02:58:18
|
A bit more on why namespace pollution is bad, particularly in this case: On Sun, 28 Jun 2009 12:50:24 Guy K. Kloss wrote: > from math import * > from numpy import * math and numpy both define certain functions and constants. So there's already a clash happening on the import with the latter import overwriting certain functionality of the former. NumPy provides quite a few functions that behave (almost) the same as the ones from math (e. g. abs(), sin(), ...). But the NumPy versions mostly also work on arrays, whereas the ones from math do not. So there is potentially already quite some confusion for the developer (of the VPython module). Own tests resulted in the math versions of the functions to be more performant than the NumPy version. This is not unusual, as they don't have to deal with arrays and can be launched directly at the passed parameters. If now users also naively import "from visual import *" they will have (A) a totally polluted name space themselves, but (B) also not have the choice any more over what *exact* functions they are using. In many cases that might not matter, but it can be very dangerous in cases of reproducibility or when one *depends* on a specific behaviour! So just for a minor convenience or laziness of the developer everybody further downstream is potentially suffering of the snowball imports. There *are* valid use cases for snowball imports, but they are not like this (e. g. developing a package to offer functions, which in turn are implemented in various sub modules. Then the __init__ of the package may snowball import these to expose the API to the outside.). So, please let's help clean up this mess! Guy -- Guy K. Kloss Institute of Information and Mathematical Sciences Te Kura Pūtaiao o Mōhiohio me Pāngarau Massey University, Albany (North Shore City, Auckland) 473 State Highway 17, Gate 1, Mailroom, Quad B Building voice: +64 9 414-0800 ext. 9585 fax: +64 9 441-8181 G....@ma... http://www.massey.ac.nz/~gkloss |