Hacker News new | ask | show | jobs
by tln 2435 days ago
Avoiding module side effects and making classes and modules immutable seem like two separate concerns
1 comments

Not really. Mutation in general, and in modules in particular, inhibit a lot of reasoning about the code, and thus stops a whole lot of optimizations from being possible. Guile (a scheme dialect) recently got declarative modules for that reason, where a top level binding cannot change (i.e. you cannot set! a binding, but you can wrap in it a mutable container and change the contents of that container). This makes procedure calls and variable lookup a lot faster. Andy Wingo wrote about it here: https://wingolog.org/archives/2019/06/26/fibs-lies-and-bench... .

Those optimizations won't mean much for cpython, since Cpython doesn't try to run things fast, but for something like pypy this could be a big deal.

To quote the article (from.memory): "adding static modules is probably the single most important optimization guile can do in the near future".

The quote is probably wrong, but it is right in spirit.