Hacker News new | ask | show | jobs
by fny 1438 days ago
Ruby's imports aren't magical by default. Autoloading frameworks make them so.
2 comments

The fact that ruby makes this possible means the community will take advantage of it, to the point of abusing it sometimes. This hurts understandability of the code base. Too many times I would open a ruby code base and spend significant amount of time tracing where things are defined (mostly relying on suboptimal searching) because of the lack of explicit imports/requires.
An easy way to do that is to use the Pry gem. If you're in a pry console, you can use `show-method Thing.foo` and it will show you the method, which file and line it's defined in, etc. Pry is a great tool and this feature makes is a blessing.
Python can do this magic too and the community hasn’t abused it. Every part of modules and module loading is swappble, mutable to the point where modules can be arbitrary classes if you want.

It would be 2/10 difficulty to add transparent module autoloading to Python because you can just hook into module loading and arbitrarily modify or replace the module objects.

You wouldn’t even need a courtesy import because the main module is still a module.

Even without an autoloader, Ruby has a single global namespace, so you have access to everything that has been required at any point from anywhere.

If anything autoloaders enforce that constant names match filenames, making it easier to locate the source.