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.

Maintainable JavaScript (2014)

90 pointsby akras14almost 9 years ago

8 comments

2pointsomonealmost 9 years ago
Isn't it interesting how React has changed the whole paradigm of "keep html out of javascript"?
评论 #12105645 未加载
评论 #12105721 未加载
评论 #12105852 未加载
benjoffealmost 9 years ago
He uses the following example for when to throw your own errors:<p><pre><code> var Controller = { addClass: function(element, className) { if (!element) { throw new Error(&quot;addClass: 1st argument missing.&quot;); } element.className += &quot; &quot; + className; } }; </code></pre> I don&#x27;t think this is a very good as a native error will have all this information already in a stacktrace, and if you&#x27;re running Chrome dev tools with &#x27;Pause on exceptions&#x27; then you&#x27;ll be shown the exact place this fails. Additionally, you need to now keep the function name in sync with the string (your IDE &#x2F; build tool will not tell you if they get out of sync).<p>Better cases for custom errors are situations where a native error will not be thrown, such as:<p>- in his example method: if className is undefined<p>- valid objects in a state you don&#x27;t expect<p>- switch statements that don&#x27;t match any expected case<p>- etc.
评论 #12105874 未加载
131hnalmost 9 years ago
This is nice video&#x2F;article, but strongly outdated &#x2F; missing &quot;current&quot; javascript maintainability standards.<p>Not so much &quot;javascript&quot; specific advices here.<p>No words on ES6 classes, that help keeping a meaningfull syntax, rest parameters, template strings.<p>No words on nodejs callback as last arg best practice.<p>No words on generator &amp; promises (nor async await) that totally change callback behavior. No word on synchronious throw &#x2F; catch vs callback(err) pattern.<p>No words on code modularisation.<p>This video is 4 years old, believe we, javascript change, a lot (and the &quot;maintainable&quot; best practice)<p>No link to mozilla MDN, when it&#x27;s now a de-factor standard for web &amp; js documentation.
评论 #12108766 未加载
评论 #12106712 未加载
评论 #12107266 未加载
partycoderalmost 9 years ago
The way I evaluate if a recommendation is good or bad is how it filters bad code.<p>The 4 most important things for me to keep under control are:<p>1) Length<p>2) Cyclomatic complexity<p>3) Shared mutable state<p>4) Coupling<p>If you keep those under control, the rest of the maintainability will come by itself. e.g: testability, reusability, thread safety, security and other high level goals are easier when these low level requirements are met.<p>And, of course, consistency. Make sure that things do what they say they do. e.g: make sure the purpose of a variable or function can be explained only through its signature without requiring to look at the code.
oeveralmost 9 years ago
The code examples use ==, which does lossy comparison. Using === is much safer. The tools section mentions JSLint which flags any use of == as an error.<p>JavaScript is such a quirky language that I always want the code to pass JSLint and Closure Compiler with 100% type annotation. I simply do not feel confident about the code otherwise.<p>I&#x27;m surprised about the lack of space after &#x27;if&#x27;. &#x27;if&#x27; is not a function so &#x27;if(&#x27; looks weird.
deevusalmost 9 years ago
Do people still use Grunt these days?
评论 #12106855 未加载
评论 #12107043 未加载
评论 #12109216 未加载
pzhalmost 9 years ago
Maintainable JS? Har har har
nittralmost 9 years ago
can someone summarize it in like 100 words or so