News for hackers. Stuff that matters.
Re:Say “no” to import side‐effects in Python by TazeTSchnitzel on Saturday April 05, 2014 @09:23AM (#7536993)
This is one reason why I prefer Haskell ;)
Re:Say “no” to import side‐effects in Python by mercurial on Saturday April 05, 2014 @09:40AM (#7537043)
I think most statically typed languages don't care for this kind of shenanigans.
Re:Say “no” to import side‐effects in Python by Argorak on Saturday April 05, 2014 @10:23AM (#7537150)
Java for example runs arbitrary code when a class is loaded (static {} blocks).

Windows has DllMain, which lets you run code at load of a shared lib and similar things are possible on Linux, using the -init linker flag and friends.

Finally, Haskell has features that allow you to load, compile and run Haskell (through the GHCMonad, if installed), which allows precisely for those shenanigans.

All those lack the habit that the OP is describing (and which broke for him): the use runtime introspection during development time (possibly in a REPL), but that's another pair of shoes.

Re:Say “no” to import side‐effects in Python by pcwalton on Saturday April 05, 2014 @03:02PM (#7538052)
In addition to the many other languages listed here, Go allows side effects on import.
Re:Say “no” to import side‐effects in Python by colin_mccabe on Saturday April 05, 2014 @09:17PM (#7539206)
That's interesting. I can see the motivation... it's helpful to have modules come into the world fully initialized, and initialization often involves side effects.

Is Rust going to allow side effects on initialization?

Re:Say “no” to import side‐effects in Python by pcwalton on Sunday April 06, 2014 @04:04AM (#7540223)
No. Having module import perform side effects delays program startup unnecessarily and makes the semantics of the program depend on the order in which modules got initialized, which is confusing.
Re:Say “no” to import side‐effects in Python by TazeTSchnitzel on Saturday April 05, 2014 @12:44PM (#7537551)
I was referring more to Haskell's lack of side effects. I don't think you can do this in modules.
Re:Say “no” to import side‐effects in Python by jerf on Saturday April 05, 2014 @09:31PM (#7539250)
You can, with unsafePerformIO. Unlike many instances where we can just wave away unsafePerformIO and declare it's an exception that you'll probably never encounter unless you ask for it, this is one instance you may encounter "in the wild" that may not be entirely safe, or may introduce a global scope where you weren't necessarily expecting one. In particular, this usually takes the form of creating a Reference of some kind at initialization time (IORef, STM TVar, etc).