TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Why do we need modules at all? (2011)

151 点作者 matthews2大约 1 个月前

31 条评论

ludston大约 1 个月前
We need modules so that my search results aren&#x27;t cluttered with contamination from code that is optimised to be found rather than designed to solve my specific problem.<p>We need then so that we can find all functions that are core to a given purpose, and have been written with consideration of their performance and a unified purpose rather than also finding a grab bag of everybody&#x27;s crappy utilities that weren&#x27;t designed to scale for my use case.<p>We need them so that people don&#x27;t have to have 80 character long function names prefixed with Hungarian notation for every distinct domain that shares the same words with different meanings.
评论 #43580487 未加载
评论 #43583252 未加载
评论 #43579883 未加载
评论 #43584509 未加载
评论 #43580048 未加载
评论 #43580086 未加载
rdtsc大约 1 个月前
I miss Joe, he left us too early. He always had wild ideas like that. For a while he had this idea of a git + bittorrent he called it gittorrent, only to find out someone had already used the name. I think it was a bit of an extension of this universal functions idea.<p>If you expand some of the comments below, he and other members of the community at the time have a nice discussion about hierarchical namespace.<p>I particularly like his &quot;flat beer and chips&quot; comment:<p><a href="https:&#x2F;&#x2F;groups.google.com&#x2F;g&#x2F;erlang-programming&#x2F;c&#x2F;LKLesmrss2k" rel="nofollow">https:&#x2F;&#x2F;groups.google.com&#x2F;g&#x2F;erlang-programming&#x2F;c&#x2F;LKLesmrss2k</a><p>---<p>&gt; I&#x27;d like to know if there will be hierarchial modules in Erlang, because tree of packages is a rather good idea:<p>No it&#x27;s not - this has been the subject of long and heated discussion and is why packages are NOT in Erlang - many people - myself included - dislike the idea of hierarchical namespaces. The <i>dot</i> in the name has no semantics it&#x27;s just a separator. The name could equally well be encoders.mpg.erlyvideo or mpg.applications.erlvideo.encoder - there is no logical way to organise the package name and it does not scale -<p>erlyvideo.mpegts.encoder erlyvideo.rtp.encoder<p>But plain module namespace is also ok. It would be impossible for me to work with 30K LOC with plain function namespace.<p>The English language has a flat namespace.<p>I&#x27;d like a drink.alcoholic.beer with my food.unhealthy.hamburger and my food.unhealthy.national.french.fries<p>I have no problem with flat beer and chips.<p>&#x2F;Joe<p>---
评论 #43586711 未加载
评论 #43587397 未加载
评论 #43585850 未加载
评论 #43588199 未加载
评论 #43590460 未加载
neongreen大约 1 个月前
&gt; database of functions<p>This is exactly what Unison (<a href="https:&#x2F;&#x2F;www.unison-lang.org&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.unison-lang.org&#x2F;</a>) does. It’s kinda neat. Renaming identifiers is free. Uh… probably something else is neat (I haven’t used Unison irl)
评论 #43583799 未加载
评论 #43588129 未加载
anonzzzies大约 1 个月前
Makes me think of Unison [0]. I never used it but I found it interesting to read about.<p>[0] <a href="https:&#x2F;&#x2F;www.unison-lang.org" rel="nofollow">https:&#x2F;&#x2F;www.unison-lang.org</a>
评论 #43581168 未加载
评论 #43581635 未加载
评论 #43596797 未加载
jonnycat大约 1 个月前
This is one of those things where I don’t agree with the argument, but know the person making it knows <i>way</i> more than I do on the subject and has given it <i>way</i> more thought. In these cases it’s usually best to sit back and listen a bit...
GrantMoyer大约 1 个月前
I think Hoogle[1] is proof this concept could work. Haskell has modules, of course, but even if it didn&#x27;t, Hoogle would keep it still pretty usuable.<p>The import piece here which is mentioned but not very emphasized in TFA is that Hoogle lets you search by meta data instead of just by name. If a function takes the type I have, and transforms it to the type I want, and the docs say it does what I want, I don&#x27;t really care what module or package it&#x27;s from. In fact, that&#x27;s often how I use Hoogle, finding the function I need across all Stack packages.<p>That said, while I think it could work, I&#x27;m not convinced it&#x27;d have any benefit over the statys quo in practice.<p>[1]: <a href="https:&#x2F;&#x2F;hoogle.haskell.org&#x2F;" rel="nofollow">https:&#x2F;&#x2F;hoogle.haskell.org&#x2F;</a>
评论 #43587561 未加载
VMG大约 1 个月前
Functions are not isolated values.<p>They are nodes in a graph, where the other nodes are the input types, output types and other functions.<p>It makes sense to cluster closely associated notes, hence Modules.
Etheryte大约 1 个月前
As with other similar proposals, doesn&#x27;t this simply move the complexity around without changing anything else? Now instead of looking for the right module or whatnot, you&#x27;ll be sifting through billions of function definitions, trying to find the very specific one that does what you need, buried between countless almost but not quite similar functions.
jasode大约 1 个月前
If there are no modules but a &quot;flat&quot; global namespace which requires every function name to be unique to avoid collisions... it means people would inevitably <i>re-invent pseudo&#x2F;fake &quot;modules&quot; and hierarchy in metadata tags</i> in large non-trivial codebases.<p>Consider a function name: <i>log()</i><p>Is it a function to log an event for audit history?<p>Or is it a function to get the mathematical natural logarithm of a number?<p>The global namespace forces the functions to be named differently (maybe use underscore &#x27;_&#x27;) in &quot;audit_log()&quot; and the other &quot;math_log()&quot;. With modules, the names would isolated be colons &quot;::&quot; or a period &#x27;.&#x27; : Audit.log() and Math.log(). Audit and Math are isolated namespaces. You still have potential global namespace collisions but it happens at the higher level of <i>module names</i> instead of the leaf function names. Coordinating the naming at the level of modules to avoid conflicts is much less frequent and more manageable.<p>Same issue in os file systems with proposing no folders&#x2F;directories and only a flat global namespace with metadata tags. The filenames themselves would have embedded substrings with underscores to recreate fake folder names. People would reinvent hierarchy in tag names with concatenated substrings like &quot;tag:docs_taxes_archive&quot; to recreate pseudo folders&#x2F;directories of &quot;&#x2F;docs&#x2F;taxes&#x2F;archive&quot;. Yes, some users could deliberately avoid hiearchies and only name tags as 1-level such as &quot;docs&quot;, &quot;taxes&quot;, &quot;archive&quot; ... but that creates new organizational problems because some have &quot;work docs&quot; vs &quot;personal docs&quot; ... which gravitates towards a hierarchical organization again.
评论 #43579955 未加载
评论 #43584440 未加载
bionhoward大约 1 个月前
IMHO, aren’t modules necessary for big projects to limit the amount of complexity we have to deal with at any one time?<p>Our minds can (allegedly) only handle 7+&#x2F;-2 concepts in working memory at once. Your whole codebase has way more than that, right? But one module could easily fit in that range.
TOGoS大约 1 个月前
Unison of course works this way, as has been mentioned.<p>I like Deno for similar reason. It&#x27;s a coarser level of granularity, and not explicitly content-addressed, but you can import specific versions of modules that are ostensibly immutable, and if you want, you could do single-function modules.<p>I like the idea so much that I&#x27;m now kind of put off by any language&#x2F;runtime that requires users of my app&#x2F;library to do a separate &#x27;package install&#x27; step. Python being the most egregious, but even languages that I am otherwise interested in, like Racket, I avoid because &quot;I want imports to be unambiguous and automatically downloaded.&quot;<p>Having a one-step way to run a program where all dependencies are completely unambiguous might be my #1 requirement for programming languages. I am weird.<p>One reason not to do things this way is if you want to be able to upgrade some library independently of other components that depend on it, but &quot;that&#x27;s what dependency injection is for&quot;. i.e. have your library take the other library as an argument, with the types&#x2F;APIs being in a separate one. TypeScript&#x27;s type system in particular makes this work very easily. I have done this in Deno projects to great effect. From what I&#x27;ve heard from Rich Hickey[1] the pattern should also work well in Clojure<p>[1] something something union types being superior to what you might call &#x27;sum types&#x27;; can&#x27;t find the link right now. I think this causes some trouble in functional languages where instead of something being A|B it has to be a C, where C = C A | C B. In the former case an A is a valid A|B, but a C A is not an A, so you can&#x27;t expand the set of values a function takes without breaking the API. Basically what union types require is that every value in the language extends some universal tagged type; if you need to add a tag to your union then it won&#x27;t work.
bjourne大约 1 个月前
This is an all-time classic, but, sadly, most HN commenters just don&#x27;t &quot;get it&quot;. Perhaps because they have no experience with the Erlang VM so they don&#x27;t understand Joe&#x27;s premises The Erlang VM is best described as a dynamic process manager and a &quot;function&quot; is just a callstack template. You want to fix a bug in your <i>executing</i> function <i>without stopping it</i>? Sure, no problem. Just reload the function and have the VM seamlessly upgrade the callstack to the new template. Since data is immutable it mostly just works. Now since functions forms the basic unit of work in Erlang modules are kind of irrelevant. Recompiling a module is the same as recompiling every function in the module. Hence, what use does the abstraction serve? The proliferation of &quot;utils&quot; or &quot;misc&quot; modules in not only Erlang but many other languages supports his point.<p>Btw, the more experienced I&#x27;ve gotten the more I&#x27;ve found that organizing code is mostly pointless. A 5000-line source file (e.g., module) isn&#x27;t necessarily worse than five 1000-line files.
评论 #43584532 未加载
评论 #43585300 未加载
jiggawatts大约 1 个月前
I had a vaguely similar notion of a global proof database. Picture something like a blockchain (actually a &quot;blockgraph&quot;) of Lean theorems built up from other theorems and axioms also on the same distributed global data structure.<p>A use-case could be optimising compilers. These need to search for alternative (faster) series of statements that are <i>provably equivalent</i> to the original given some axioms about the behaviour of the underlying machine code and basic boolean algebra and integer mathematics.<p>This could be monetised: Theorems along the shortest path from a desired proof to the axioms are rewarded. New theorems can be added by anyone at any time, but would generate zero income unless they improve the state-of-the-art. Shortest-path searches through the data structure would remain efficient because of this incentive.<p>Client tools such as compilers could come with monthly subscriptions and&#x2F;or some other mechanism for payments, possibly reusing some existing crypto coin. These tools advertise desired proofs -- just like how blockchain clients advertise transactions they like to complete along with a fee -- and then the community can find new theorems to reach those proofs, hoping not just for the one-time payment, but the ongoing reward if the theorems are general and reusable for other purposes.<p>Imagine you&#x27;re a FAANG and there&#x27;s some core algorithm that uses 1% of your global compute. You could advertise a desire to improve the algorithm or the assembly code to be twice as efficient for $1M. Almost certainly, this is worth it. If no proof turns up, there&#x27;s no payment. If a proof does turn up, a smart contract debits the FAANG&#x27;s crypto account and they receive the chain of theorems proving that there&#x27;s a more efficient algorithm, which will save them millions of USD in infrastructure costs. Maths geeks, AI bots, and whomever else contributed to the proof get their share of the $1M prize.<p>It&#x27;s like... Uber for Fields medals, used for industrial computing.<p>Fully automated gig work for computer scientists and mathematicians.
评论 #43588139 未加载
rapjr9大约 1 个月前
Code reuse used to be thought of as the ultimate destiny for computer code. Eventually you would never have to write new code, it would all exist in some form and you would just reuse it. We may actually be getting something like that through the use of AI for coding now. The problems with code reuse are many though. A function written in C for a microcontroller often won&#x27;t work in a python program, especially not without all the include files, libraries, and a wrapper. How do you find the function that matches your needs? Coding language and function parameters offer some clues but are not sufficient. For example one function may do rounding on return values while another does not. Do you need a function optimized for speed, for object size, for time latency? Will the function work in your computing space? For example one function might use a loop, another might use recursion so running on an MCU one might work and the other might crash your stack. This might be a set of problems a LLM could sort out, but it would need some most excellant training data, not random stuff off the web. Even existing, working, industrial code bases would not be sufficient since there are huge sections of code in them that are legacy and mostly no longer used or relevant. It would probably have to be a constantly curated training database. And there is an inherent ambiguity in code, who is to say one implentation is better than another if they both work? This could make debugging challenging if the coding style is different in all the code snippets.
codethief大约 1 个月前
&gt; all functions go into a global (searchable) Key-value database<p>Very much related: <a href="https:&#x2F;&#x2F;scrapscript.org&#x2F;" rel="nofollow">https:&#x2F;&#x2F;scrapscript.org&#x2F;</a>
lorentzoh大约 1 个月前
I sometimes want to save a useful python script, or a function in github, but don&#x27;t want to create a whole repository with README, name, description and so on. This model would be nice for that. But then, the access control system (e.g. private&#x2F;public repos) would be completely different. Perhaps you could have groups of users, and give group access to individual objects (classes&#x2F;functions) in your repo. But giving access to each object one by one would probably be tedious, so you need some kind of modules, or other way of grouping objects (maybe tags?). I also thought of tags on one of my jobs as DevOps. We had a lot of types of repos, that we needed to organize, and enforce access control: - code repos like backend and frontend - infrastructure repos with k8s manifests, helm charts etc. - also a lot of microservice&#x2F;microfrontend repos The team lead was trying to come up with a hierarchy for all this, but struggled. If github allowed for a flat namespace of repos, and tags-based access control, we could create tags like &#x27;frontend&#x27;, &#x27;devops&#x27;, &#x27;backend&#x27;, give the tags to people and repos.
surprisetalk大约 1 个月前
This post was a huge inspiration for scrapscript!<p>[0] <a href="https:&#x2F;&#x2F;scrapscript.org" rel="nofollow">https:&#x2F;&#x2F;scrapscript.org</a>
immibis大约 1 个月前
I think they already tried this &quot;single flat key&#x2F;value namespace of all functions&quot; in the JavaScript ecosystem - it was called npm. It was a mess when someone claimed a function based on a trademark and someone else deleted the function for padding a string to a certain length with spaces on the left in retaliation.
layer8大约 1 个月前
Aside from grouping functions together that work together, for example working with data types&#x2F;structures also defined in or by the module, modules also serve the purpose to hide implementation-detail code (“private” functions) shared between those functions. Modules provide a form of information hiding.<p>Furthermore, modules are the unit of versioning. While one could version each individual function separately, that would make managing the dependency graph with version compatibility considerably more complex.<p>There is the adage “version together what changes together”. That carries over to modules: “group together in a module what changes together”. And typically things change together that are designed together.<p>Namespaces are an orthogonal issue. You can have modules without namespaces, and namespaces without modules.
friendzis大约 1 个月前
Global namespace clobbering has huge implications. With modules&#x2F;namespaces you have a well defined and limited blast radius: a change is limited to a module and calling code.<p>Now, imagine your environment of choice supported dynamic runtime loading of code where the code is just dropped to the global namespace. This screams &quot;insecure&quot; and &quot;how do I know if I call the code I want to call?&quot;.<p>Now imagine the only mitigating mechanism was `include_once`. It would make sense software written in this environment requires own CVE namespace as new security vulns are discovered every second
评论 #43583085 未加载
kazinator大约 1 个月前
Modules are often about a single function. But the function has helper functions that are not part of the API. Then maybe some functions that <i>are</i> part of the API which help use that function. Sometimes functions beget families.<p>If a function is built on several helper functions, it may be that those same helper functions can also be used to make other, related things which round out the functionality area. Perhaps they provide an API that&#x27;s easier to use for different scenarios or whatever.
MrBuddyCasino大约 1 个月前
We need modules because they demarcate social units of collaboration.
评论 #43580075 未加载
gatinsama大约 1 个月前
&quot;Namespaces are one honking great idea -- let&#x27;s do more of those!&quot; Zen of Python
waynesonfire大约 1 个月前
Here is the link for elib1_misc.erl,<p><a href="https:&#x2F;&#x2F;github.com&#x2F;joearms&#x2F;elib1&#x2F;blob&#x2F;master&#x2F;src&#x2F;elib1_misc.erl">https:&#x2F;&#x2F;github.com&#x2F;joearms&#x2F;elib1&#x2F;blob&#x2F;master&#x2F;src&#x2F;elib1_misc....</a>
nsonha大约 1 个月前
This is the same to &quot;why do we need inheritance&quot;, although less obvious. Grouping things is humans&#x27; instinct, but it may not map nicely to reality where everything belongs to more than one categories.
wruza大约 1 个月前
That would be too useful. Imagine adding tags to functions and generally treat them as &quot;items&quot; which you can multi-categorize, search through, select, etc like with any dataset. Way too advanced.
评论 #43579823 未加载
porkbrain大约 1 个月前
1. Have a global append-only function key-value store.<p>2. A key of a function is something like `keccak256(function&#x27;s signature + docstring)`<p>3. A value is a list of the function&#x27;s implementation (index being the implementation&#x27;s version) and some other useful metadata such as the contributor&#x27;s signature and preferred function name. (Compiler emits a warning that needs to be explicitly silenced if preferred name is not used.)<p>4. IDE hints and the developer confirms to auto import the function from the global KV store.<p>5. Import hash can be prepended with a signers name that&#x27;s defined in some config file. This makes it obvious in git diffs if a function changes its author. Additionally, the compiler only accepts a short hash in import statements if used with a signer.<p>package.toml<p><pre><code> [signers] mojmir = &quot;mojmir&#x27;s pubkey&quot; radislava = &quot;radislava&#x27;s pubkey&quot; </code></pre> source.file<p><pre><code> &#x2F;&#x2F; use publisher and short hash import &quot;mojmir@51973ec9d4c1929b@1&quot; as log_v1; &#x2F;&#x2F; or full hash import &quot;51973ec9d4c1929bdd5b149c064d46aee47e92a7e2bb5f7a20c7b9cfb0d13b39&quot; as log_latest; import &quot;radislava@c81915ad12f36c33&quot; as ln; log_v1(&quot;Hello&quot;); log_latest(ln(0));</code></pre>
评论 #43583115 未加载
andrewcl大约 1 个月前
Hard to see a world without modules as a means of compartmentalization for various reasons. You do have to appreciate the exercise what a world without them looks like &#x2F; the implications.
DarkNova6大约 1 个月前
Should have put on the (2011) label
unwind大约 1 个月前
Meta: this needs &quot;(2011)&quot; in the title, please.
landsman大约 1 个月前
What a mess