职业网络成瘾者 • 游戏爱好者 • 技术创造者
职业网络成瘾者 • 游戏爱好者 • 技术创造者

不,我们没有忘记如何编写代码——JavaScript 应该更好

NPM 软件包“left-pad”被移除后,全球数百万个应用程序崩溃了。但这个软件包究竟为何存在呢?
为了方便您使用,本页面由我热情高涨的 AI 实习生从英文翻译而来。他们仍在学习中,因此可能存在一些错误。为了获得最准确的信息,请参考英文版本。
博客 不,我们没有忘记如何编写代码——JavaScript 应该更好

请注意,本博文发布于2016年3月,因此根据您阅读的时间,某些部分可能已过时。遗憾的是,我无法始终保持这些文章的完全更新,以确保信息的准确性。

    I don't usually write opinionated blog articles. So if don't agree with me, please remember these are my personal opinions and I would love to hear your own opinion.

    A quick summary of the npm chaos

    There has been a lot of drama the last couple of days in the npm community, triggered by Azer Koçulu who had a dispute with the company Kik Interactive over who should have access to the npm package named "Kik" - the developer who first published the package with his open source project, or the world wide company who has an 240 million user application called "Kik Messenger".
    Without any lawyers being involved, it ended with npm seized controlled and transferred over the package name to "Kik" to Kik Interactive. In retaliation of the decision, Azer unpublished all of his 273 modules from npm. Among them was package called left-pad. A package with millions of downloads per month and thousands of projects relies on, breaking every single of them and creating chaos. In order to try and save the situation, npm took control over the left-pad package and un-unpublished it.

    The aftermath of opinions and the insults to us JavaScript developers

    The left-pad package is actually, what is refereed to, a "micro-package" since it is only 11 rows of source code that offers only one functionality; pads the left side of a String with any given character, until a given length is reached.
    However, after this incident there has been a lot of drama, blogs, opinions and statements thrown around such as if we JavaScript developers have forgotten how to code since micro-packages such as left-pad exists.
    The truth is; No, we haven't forgotten how to code.
    On the contrary actually, I would say that we JavaScript developers are probably more experienced with crazy, unexpected, non-consistent results which we constantly have to overcome, since our single written source code is often executed on different environments and browsers.
    Our code is not compiled specifically for a deterministic platform, nor is it always executed on deterministic run-time systems as other languages are. I see us JavaScript developers as hurdle-runners where every 30 seconds we need to jump over a new obstacle.

    A quick summary of the npm chaos

    I will be very straightforward and honest here.
    Micro-packages such as left-pad (but you can also include famous libraries such as Underscore, Lodash and Rambda, and even frameworks such as jQuery, and other types of polyfills) are necessary evils in a JavaScript developer's work. We don't like to use them, but we have to. And it's silly that we web developers should spend time to recreating basic wheels instead of focusing on creating high level solutions.
    The only reason why the package left-pad exists, is because the JavaScript language itself is fundamentally flawed and the core APIs is a mess compared to other programming languages.
    So without these micro-packages other polyfills in our toolbox, our work becomes really painful.
    A JavaScript developer without their toolbox
    Another example is that if you are one of those lucky web developers that still needs to support Internet Explorer 9, it means that you you are confined within the rules of EcmaScript 5. This means that if you want to figure out if String contains another String, you need to write:
    if( haystack.indexOf(needle) !== -1 ) { ... }
    Compared to:
    if( haystack.indexOf(needle) !== -1 ) { ... }
    A core API such as String.includes (or String.contains) existed in almost all major programing languages since day 1, but not for JavaScript. That specific API literally was added 18 years after the language was first released, as part of the EcmaScript 6 specification. And this is just one of many examples of basic code APIs that doesn't exist in JavaScript compared to other languages.

    JavaScript is a necessary evil that requires time to improve

    I have never met anyone who has ever said they actually like the JavasScript language and its core APIs. They might like functional programming, the idea of functions are first class citizens and its loosely typed, but never the language itself. JavaScript is actually a language that we are forced to deal whether we like it or not.
    However the process of improving and progressing EcmaScript is not easy though. It is almost like, I assume, building the International Space Station. It's a project where multiple countries needs to sign off and where each country has its own prioritization and budgets to achieve the greater goal. A process like this takes time and the chain will never be as strong as its weakest link.
    International Space Station
    So no, we haven't forgotten how to code. The JavaScript language just needs to become a better language.

    作者:Special Agent Squeaky。首次发布于2016年3月25日。最后更新于2016年3月25日。

    📺 快来看看 Squeaky 的最新视频!

    如何为您的直播添加简单的实时字幕