7 ms·
Why do we need modules at all? (2011)
- leblancfg 7y agoThe whole thread has interesting discussions. Keep in mind it's 8 years old: http://erlang.org/pipermail/erlang-questions/2011-May/thread.html#58772 http://erlang.org/pipermail/erlang-questions/2011-May/thread...
- kasperni 7y agoThat's a great idea! Let's try and deploy this 'left-pad' function that everyone can use... But seriously, I know his description is a bit different, but I think NPM has shown that such a model is really difficult to maintain.
- tosh 7y agoFunctions in a global persistent database would solve the "dependency suddenly disappearing" problem.
- jakear 7y ago“Global persistence” is a lie. The second copyright law or malware become involved, practice separates from theory. Look at the hackage rollback, for instance. (https://hackage.haskell.org/package/Facebook-Password-Hacker-Online-Latest-Version-1.0.1 https://hackage.haskell.org/package/Facebook-Password-Hacker... <- downloads what used to be a Hackage package to your computer. Now, its a text file with the word "Gone")
- tosh 7y agobittorrent, blockchains
- christophilus 7y agoI don't think it's just the persistence that's the problem. NPM is now persistent (I think). But it's the fact that you can upgrade the functions. So, maybe if the references were immutable, it'd make more sense. But then it's the fact that you've got a bunch of one-off functions which are a security nightmare to audit, not to mention accidentally slurping in several MB of functions due to the dependency graph.
- interactivecode 7y agoIsn't a major major point that package registries and or modules don't need review board? thus eliminating gatekeeping?
- tosh 7y agoI read the review board as optional extension to the idea. The database / infrastructure could be permissionless and you could still define curated subsets of functions in addition to that.
- pjc50 7y agoThe gatekeeping can be a feature; centralising security review is definitely worthwhile.
- nickjj 7y agoI really like the idea of a no module system. If you look at the /usr/bin directory of a Linux system there aren't any namespaces. There's 1,000+ binaries thrown into 1 folder, each with a distinct name and things work nicely. Imagine if you tried to group those binaries into 1 or more folder driven namespaces. Where would things go? The amount of bike shedding would be endless and I don't think it would be a better solution in the end even if you managed to pull it off. All of Joe's points in that post are spot on.
- dmitriid 7y agoThere are namespaces, you just don't see them. That's why there's python and python3, cmake and cmake2 (IIRC) etc. With functions it's worse. In a flat namespace you will inevitably run into a problem of two people coming up with the same name.
- tosh 7y agoYou could use something like uuids for naming functions and attach meta data (including e.g. human readable names and/or namespaces).
- pjc50 7y ago> uuids for naming functions Microsoft COM would like a word. {20D04FE0-3AEA-1069-A2D8-08002B30309D}
- ChrisSD 7y agoPeople on HN keep reinventing COM. I swear every other week we have discussions like the above in at least one thread.
- pjc50 7y agoYup. There's a lot of factors at play. We're a very ahistorical field; lots of folks are self-taught and therefore reinventing everything is normal to them; the dev universe is heavily siloed into "Web+UNIX" versus "Microsoft" versus some now moribund siloes (Websphere! Solaris! Alpha!); Microsoft have almost no community compared to the FLOSS world (although .net is changing this a bit); and finally the simple fact that COM and you and I are very, very old. I'm not even sure that reinventing COM would be a bad idea - you can definitely do some great things with it, and the specific implementation details of COM are crufty. But doing so deliberately rather than accidentally would be better, with a review of benefits and problems of COM approaches.
- kristiandupont 7y agoI think this idea makes a lot of sense. I recently published a tiny library on NPM for changing the case of strings (snake_case, etc.). It felt so small and silly that I was tempted to add some other string manipulation functions, to make it a more "serious" library. But it struck me that this would just be silly. How often do you need a whole collection of string manipulation functions? Never! It would just add to the size of dist folders everywhere, with no gain whatsoever. I suspect this applies in many situations.
- strlen0 7y ago> How often do you need a whole collection of string manipulation functions? All the time. It’s called a standard library and most sane languages have one.
- pierreyoda 7y ago> How often do you need a whole collection of string manipulation functions? Never! It would just add to the size of dist folders everywhere, with no gain whatsoever. I mean that's where proper tree shaking would void this argument. When you include lodash (or lodash-es more precisely) for instance only the used functions are in the final bundle with a modern bundler.
- WillDaSilva 7y agoThere's no way I'd ever import a tiny library like that. Verifying that a library does what I expect it to do, uses an appropriate license for my project, isn't likely to break my project in the future, etc., is a fair bit of work, and it only increases as more tiny packages are added. The worrying over increasing the size of the dist folder is a symptom of using a bad package manager. I do believe that packages shouldn't be bloated, and should mainly focus on a single goal, but that goal should be at least somewhat broad in scope. Manipulating strings is a good objective for a package, but changing the case of strings seems too small to be worth it.
- Ididntdothis 7y ago" How often do you need a whole collection of string manipulation functions? Never! " Always! The Javascript world lacks a good standard library or something like STL that covers most of what you need during normal development. Instead you have thousands of little packages of varying quality. I would much prefer a few big libraries with more power and consistency.
- rexpress 7y agoThe proposed key-value function database mentioned in the article sounds like the recently launched Function Repository in the Wolfram Language... https://resources.wolframcloud.com/FunctionRepository/ https://resources.wolframcloud.com/FunctionRepository/
- pjc50 7y agoThis is one of those ideas that sounds very tempting at the small to medium scale but will definitely fall over at the large scale. Zooko's Triangle is one obvious problem as the namespace gets full. It also looks like this is only suitable for functional languages, and possibly just non-OO languages? What about the type signatures of these functions? What do they look like? How well can different types be substituted? Do we have to version the types as well? How do we handle testing in this scenario? Every version of every function? How about combinations of functions? How about deprecation? This is hard enough to do with standard library functions; how long has gets() been deprecated, for example?
- jstimpfle 7y agoConsider that if you control a large codebase, the need for "decentralisation" (as in Zooko's triangle) is not there. You can just rename things. When integrating across maintenance boundaries, renaming isn't possible but a simple prefix is almost as good as a namespace.
- pjc50 7y agoAt the point where the article talks about ""the open source Key-Value database of all functions"", you can't rename things.
- jstimpfle 7y agoYou are right, I'm off on a tangent here.
- coding123 7y agoWhat if the key is module.fn
- pharke 7y agoThe name shouldn't matter. What I mean is, we should only care about the output produced by a given input. The keys could simply be unique hashes but we also associate a full description of the interface, tests, and text describing how it should be used. We would just need tooling that makes it easy to search, run the tests with our data, and locally alias the function to something we understand.
- jbverschoor 7y agoPlease stop the insanity called software “engineering”
- msluyter 7y agoWhatever you think of the idea, I think the reasoning here is interesting and instructive. 1. Start by questioning a long held assumption ("Do we need modules? Why? Is it because we stored functions in files?" Etc...) 2. Consider alternatives / what ifs. ("What if we used a database instead of files?") 3. Think through implications of the alternatives ("How would we identify functions?") IMHO, this is a powerful technique for generating new ideas. Step 4, not explicitly performed here, might be to take ideas generated from steps 2 & 3 and apply them to other domains. ("Ok, perhaps a database of functions wouldn't be great for code, but perhaps it (or something similar) would be great for some other domain...")
- ajavascriptdude 7y agoand voila, serverless is born
- Anonymous4C54D6 7y agoServerless is about running functions this is about distributing their code. I agree that there is some overlap but different problems are being solved.
- macintux 7y agoJoe was always good at thinking differently. Talking to him was such a treat; that combination of irreverence and experience meant a conversation was always educational.
- slifin 7y agohttp://blog.datomic.com/2012/10/codeq.html http://blog.datomic.com/2012/10/codeq.html I think codeq 2 is being worked on
- z3t4 7y agoI love lexically scoped modules. Its like global functions, but without the complexity. Node.js got this right, where modules are like an extension of the standard lib (node.js framework) too bad its too slow. But in compiled languages like for example D there is no performance penalty! Some programmers make fun of small pure functions/modules ... Then they cut their own code up into tiny small pieces that all depend on each other, without any reusability.
- jstimpfle 7y ago> all functions have unique distinct names > To avoid all mental anguish when I need a small function that should be somewhere else and isn't I stick it in a module elib1_misc.erl. I can totally relate. It doesn't reduce collisions significantly if a function is named Foo::Bar() instead of Foo_Bar(). But the latter has the advantage that we are free to move the function (avoiding initial decision paralysis, and later it's easier to clean up) and being required to reference this function with fully qualified name leads to much more readable code (IMO). What I've been doing lately is I just make descriptive function names. I don't even use a prefix, but may still include type names in the function name. Example, slightly long name: copy_from_StreamsChain_to_Textnode(). That's totally fine in terms of avoiding (the FUD concerning) collisions and it flows very naturally. Just like with Objects/methods, not doing namespaces leads to a significant reduction in decision paralysis (time consuming taxonomic concerns - "where should I put...?") for me.
- pjc50 7y agoThe converse question to "where should I put" is "where could I find". Namespaces and objects make it easier to find related functionality so you don't have to reinvent it. Without good techniques for locating relevant useful functions, you're just writing write-only code. And the technique of "if I was going to write this, where would I put it" doesn't even work when I'm trying to find my keys, let alone among all the developers of the world.
- jstimpfle 7y agoThat's an interesting thought. But consider - If "where should I put" is unclear, "where should I find" is equally unclear. - Code should be mostly "local" anyway (what's the word again?) - Text search exists, and IDEs nowadays even do fuzzy search. - I didn't say we should make a total mess. If there is an obvious organizational strategy, just go for it! But namespaces are not that important; you can still get most of the organizational advantages of namespaces by just grouping in files and maybe prefixing.
- Oreb 7y ago“Where could I find” is indeed an important question, but it is not obvious to me that hierarchical namespaces are the best solution. Couldn’t something like a list of tags attached to every function/type/whatever be at least as effective?
- jakear 7y ago“Global key-value store of functions with their metadata” sounds a lot like Hoogle to me. As for getting rid of modules and replacing them with namespaces... I’m not sure I see what is gained. You still have function names plus an additional identifier.
- christophilus 7y agoWhen people criticize NPM for having millions of downloads for single-function packages, this is exactly the letter I always think of. When Joe Armstrong proposed this, I thought, "Hm, that's an interesting idea." But I think NPM has shown that it isn't such a great idea in practice.
- _pmf_ 7y agoIn Joe Armstrong's concept, the standard library still exists, it's just organized differently (i.e. while it's possible to switch out parts with high granularity, but not the default us case). NPM's stance is "there is no standard library, just use something and hope for the best". I.e. the release would still contain a curated, officially supported set of function that a) work together and b) are reasonably sure to not execute miners, not display ads and not post your environment variables to pastebin.
- Crinus 7y agoAssuming "package" is not just another name for "module" and that it goes away once "installed" (i do not know about NPM), what would be the difference between 1000 single function packages and a single 1000 function package?
- TeMPOraL 7y ago1000x as much metadata, and with small packages, you get more metadata than real code.
- erikpukinskis 7y agoFor what it’s worth, many of us are quite happy writing and using small NPM packages with clear responsibilities. Maybe it’s self evident to you that this is a horrible thing, but it’s not to me. But if you care to share, I would be happy to learn about the horrible things that will befall me, before they happen!
- sgt101 7y agoHello Julia - and it's unreasonably effective multiple dispatch system. https://www.youtube.com/watch?v=kc9HwsxE1OY https://www.youtube.com/watch?v=kc9HwsxE1OY f(x1,x2){} < x1.f(x2){x1} < f(x1,x2){x1,x2} But modules are useful for organising code and choosing what to bother the compiler with.
- pezo1919 7y agoSo the "database" is the new module? So an entity can share its whole database or nothing? Everything smaller than the whole database seems a module to me.
- zachrose 7y agoHow about a global K/V store for data structures?
- wazHFsRy 7y agoI think the Unison language goes exactly in that direction http://unisonweb.org/ http://unisonweb.org/
- choeger 7y agoWhat about module-level programming? Has the author ever heard of functors? How about information hiding and coupling data structures with their functions? I need just a glance to the ML world to find lots of valid use casea for modules, way more than just "provide a compilation unit structure".
- dmix 7y agoI'm sure Joe Armstrong is familiar with functors.
- choeger 7y agoThen why is he completely ignoring this topic in his argument?
- macintux 7y agoHe wrote this as a rumination to an Erlang audience about the Erlang language. It wasn’t really necessary to explore every angle about other languages’ use of modules. He does discuss information hiding in an Erlang context, so he didn’t completely ignore your concern. I’m not sure why you felt the need to (tonally) attack him.
- cammil 7y agoI feel the same way about scope
- tudelo 7y agoexplain?
- xixixao 7y agoOn the topic of "where do I put this function", for "library/utility" functions, I really like the Hack Standard Library approach: Organize namespaces by the types of return values (or arguments). So we have Vec/Keyset/Dict namespaces for all library functions which return vec/keyset/dict, and the C (Collection) namespace for functions which take any collection and return something else (either element or a number). I'm sure this can be extended, and I'm always toying with the idea of replacing lodash with a library that follows this convention. Here the objective is really discoverability - you usually know the types of return value/argument, while you often don't remember the function name.
- wruza 7y agoAlso maybe mark arguments which are essential or auxiliary (and defaults), like functions receiving Lists of Foos are not really List-related, but Foo-related. I always wanted a code completion tool which I could ask: hey, I have these two values, say, one field and one pango layout, but forgot what to do next. And it would figure out that I want pango_layout_set_text( layout, gtk_entry_get_text(entry), -1); among the others. Soo cool.
- soheilpro 7y agoWe already have this in JavaScript: isArray, is-even, left-pad, etc. And the (searchable) database is called npm.
- makz 7y agoWhy do we need anything at all?
- dgulino 7y agoAnyone have a copy of his elib1_misc.erl?
- tabtab 7y agoTable-Oriented-Programming (TOP) philosophy is that while it's good to apply categories to snippets of code, one shouldn't be forced to have one and only one category per snippet. The hierarchical and file-based view of grouping or categorizing code is seen as obsolete under TOP's way of looking at things. We use RDBMS to manage large quantities of physical objects, so why not also use them to manage large quantities of code snippets, such as event handlers. Early databases were hierarchical also, but over time hierarchies ran out of steam. TOP believes eventually the same lesson will be learned about code management. Take MVC for example. Some code maintenance tasks are by entity and not just M or V or C. For instance, adding a new column to a given table. So if one could run a little query to list links to all modules/files/snippets for a given entity, then entity-based tasks are easier.
- dang 7y agoThread from 2015: https://news.ycombinator.com/item?id=10409507 https://news.ycombinator.com/item?id=10409507 2014: https://news.ycombinator.com/item?id=8572600 https://news.ycombinator.com/item?id=8572600 2011: https://news.ycombinator.com/item?id=2580383 https://news.ycombinator.com/item?id=2580383
- Mikhail_Edoshin 7y agoAn interesting thing about XML namespaces is that they are basically a way to autonomously create globally unique names that are still human-readable and writable. (As opposed to GUIDs, for example.) Like `foo:bar`, where `foo` is a local alias for a long and unique string, often an URN. (Of course, this wasn't an original idea of XML.)
- twhitmore 7y agoNope. Not convinced this is an idea, or even a good thought provoker. Organization of code at a larger granularity than individual functions, is something that's really useful and important in most non-trivial applications. Topicality and meaningfulness of organization is something that should be valued. Removing or skipping it because Joe can't be bothered separating his String, Text File and Process funcs would be foolishness. Resulting in only a new form of spaghetti.