2 ms·
Is there any language that makes breaking out code into separate files as simple as maybe just importing a file. c and cpp i guess with quote includes, even tha
by tayo42 3y ago
Is there any language that makes breaking out code into separate files as simple as maybe just importing a file. c and cpp i guess with quote includes, even that is annoying with header files and linking args when compiling.
- knome 3y agogolang is pretty good for this. you can stick a bunch of files together and just mark them as being in the same package and all their functions will get wadded together in the resultant package for other stuff to import.
- guy4261 3y agoPackage visibility is actually one of the things I dislike the most about golang :( Coming from Python, I got used to the "explicit is better than implicit" Zen. With "import *" being discouraged, usually when you see something in your Python code, you know exactly where it came from. When I started out with golang, seeing references to things that came out of nowhere (to my eyes) annoyed the hell out of me. I still consider this a cognitive burden.
- w7 3y agoI'm not sure I understand. Generally in Go: functions, structs, and consts are namespaced in a way I think is familiar to most, by package origin. If something is not, then it's either a function/struct in the same namespace (same file, or directory), variable in same scope, or it's a built-in. Built-ins like `append`, are not much different than say `map`, `filter`, `max`, etc in Python. Anything sourced from a subdirectory, parent directory, or sibling directory needs to be explicitly imported via the module path.
- knome 3y agoI discovered how it works by fighting with the compiler far longer than I will admit trying to force it to import the other files in the directory :)
- lanstin 3y agoYeah that is counter intuitive till you forget not knowing it.
- hetman 3y agoYes, Ruby. But there's tradeoffs and frankly Python's file name = namespace name approach makes finding things much easier when you don't know where they've been imported from. In Ruby people achieve something similar by convention (explicitly creating a namespace and keeping the names in sync with the file name), but not everyone follows convention and things can turn into a mess. If I had to suggest one flaw in Ruby it would be this, in many other ways I find it nicer to code in then Python, but honestly this one thing is enough to really sour the experience.
- cortesoft 3y agoThe ability to open and modify any class at any time really prevents filenames from being the namespace. It is both a powerful feature and a hindrance to code discoverability. Discoverability in Ruby is usually done via IRB, and you can call "source_location" on a method to find where in code it the method is defined (or redefined, as can happen in Ruby)
- kristaps 3y agoFor all the things wrong with node, I envy the relative filename importing they have when writing Python.
- DemocracyFTW2 3y agowhen I moved from Python to NodeJS years ago the way that `require( './path/to/file.js' );` works was a total revelation. There are still arguments being mafe about NodeJS's `require` rules being too complicated (e.g. using optionally implicit extensions) but even with that, NodeJS's `require()` method is hands down superior to Python's `import` statement.
- rrdharan 3y agoPHP