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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

JavaScript Modularity Shaming

140 点作者 fogus超过 10 年前

11 条评论

imslavko超过 10 年前
Same people who shame other&#x27;s work for not being modular enough for their taste, would worship a one-line module[0] that is modular down to every subroutine.<p>[0]: <a href="https://github.com/blakeembrey/is-upper-case/blob/master/is-upper-case.js" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;blakeembrey&#x2F;is-upper-case&#x2F;blob&#x2F;master&#x2F;is-...</a>
评论 #8854168 未加载
评论 #8853527 未加载
评论 #8853865 未加载
评论 #8855020 未加载
评论 #8856377 未加载
city41超过 10 年前
I&#x27;m a fan of ClojureScript and one reason being how easy it makes it to take advantage of the Closure compiler. But it can be a double edged sword. At times the advanced compilation mode breaks your code, and it can be <i>extremely</i> difficult to track down why. The combination of symbol renaming and dead code elimination usually means final JavaScript that looks utterly nothing like the ClojureScript you started out with.<p>Just today I had an issue where the Closure compiler decided my call to (set!) wasn&#x27;t necessary, and so it removed it, completely breaking my app. The best solution I could find was a work around involving a pretty large let block. I was just happy to get it working, debugging optimized Closure compiled code is not fun at all.
评论 #8854952 未加载
nwienert超过 10 年前
Relevant discussion thread on github[1].<p>Max Ogden&#x27;s last comment irks me. After a long and fairly productive discussion, he generalizes &#x2F; calls out people, and doesn&#x27;t explicate on what he&#x27;s trying to point out.<p>[1] <a href="https://gist.github.com/substack/68f8d502be42d5cd4942" rel="nofollow">https:&#x2F;&#x2F;gist.github.com&#x2F;substack&#x2F;68f8d502be42d5cd4942</a>
评论 #8854816 未加载
juandopazo超过 10 年前
This is an area where the new syntax for modules in EcmaScript 6 does really well. Since exports are static, a dead code elimination tool can figure out which exports from a module are being used and remove the ones that are not being used. As mentioned in comments about how the Closure Compiler works, you can&#x27;t really do this with purely dynamic code, but you can do it with static imports&#x2F;exports.
serve_yay超过 10 年前
This is a strange post, it&#x27;s about two completely separate things.<p>I do agree with the &quot;modularity shaming&quot; idea though, the JS community does seem to be overzealous about that. However I think it better to err in that direction than the other direction.
ianbicking超过 10 年前
Is the Closure Compiler specifically good at dead code elimination in Closure libraries? Theoretically I would imagine that it could be applied to anything, though I&#x27;m sure there are many Javascript tricks that would make dead code detection ineffective.
评论 #8853436 未加载
评论 #8853724 未加载
评论 #8853827 未加载
amelius超过 10 年前
Why don&#x27;t we just let browsers treat javascript files as modules, just like we have shared libraries on our OS?<p>This way, libraries such as JQuery, could be cached, and shared between websites.
评论 #8853751 未加载
评论 #8853729 未加载
评论 #8853292 未加载
thomasreggi超过 10 年前
I had a twitter convo with David DeSandro about this exact thing today <a href="https://twitter.com/thomasreggi/status/552903079142883329" rel="nofollow">https:&#x2F;&#x2F;twitter.com&#x2F;thomasreggi&#x2F;status&#x2F;552903079142883329</a>. I&#x27;ve really taken to projects like <a href="https://github.com/tjmehta/101" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;tjmehta&#x2F;101</a> where you are forced (there&#x27;s an error if you include the index) to include the files &#x2F; functions that you need directly. He raised some good points.
skybrian超过 10 年前
Of course GWT and Dart also do dead code elimination (also known as tree-shaking). There&#x27;s a reason Google&#x27;s JavaScript-targeted compilers implement this.<p>On the other hand, the consistent dedication to writing tiny libraries in JavaScript ecosystem is not a bug. Tree-shaking compilers make it somewhat harder to tell where the bloat is coming from, and that encourages people writing libraries to get sloppy.
评论 #8856228 未加载
mattdesl超过 10 年前
I responded a while back in another thread about &quot;small modules&quot; in npm. Filesize is only one (rather small) facet of why some people prefer this approach to the &quot;put everything under the same hood&quot;.<p><a href="https://news.ycombinator.com/item?id=8830058" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=8830058</a>
zubairq超过 10 年前
<a href="https://www.youtube.com/watch?v=dtnQ3Mwp0KQ" rel="nofollow">https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=dtnQ3Mwp0KQ</a>