TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

JavaScript Modularity Shaming

140 pointsby fogusover 10 years ago

11 comments

imslavkoover 10 years ago
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 未加载
city41over 10 years ago
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 未加载
nwienertover 10 years ago
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 未加载
juandopazoover 10 years ago
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_yayover 10 years ago
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.
ianbickingover 10 years ago
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 未加载
ameliusover 10 years ago
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 未加载
thomasreggiover 10 years ago
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.
skybrianover 10 years ago
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 未加载
mattdeslover 10 years ago
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>
zubairqover 10 years ago
<a href="https://www.youtube.com/watch?v=dtnQ3Mwp0KQ" rel="nofollow">https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=dtnQ3Mwp0KQ</a>