Understanding JavaScript is Vitally Important

转载 2015年07月08日 20:46:56


JavaScript is the standard programming language of the web platform, and increasingly, all software is becoming web software. Productivity apps, mobile apps, games, wearable computing, cloud services, IoT devices… you name it, the trend is the same: They’re all relying more and more on JavaScript.

npm is the largest programming language
package repository in the world.

We all Depend on JavaScript

Software is eating the world, the web is eating software, and JavaScript rules the web. You can code in other languages, of course, but Node.JS is taking over the server side, and compile-to-JavaScript languages make up a tiny fraction of the programming language popularity rankings. Npm, JavaScript’s standard package repository, is the largest package repository in the world, and it’s still growing very quickly.

The fact is, most of the world’s software infrastructure is heavily dependent on JavaScript: perhaps the world’s most misunderstood programming language.

I recently wrote a pair of articles on JavaScript: The Two Pillars of JavaScript part 1 and 2. In those articles, I describe what I consider to be the two most important features of JavaScript: prototypal OO and functional programming.

The Myth of the 10x Developer

It’s very common to hear about developers who are ten times more productive than average developers. The problem with this fuzzy math is that it assumes that the average developer hire is a productive hire. The truth hurts, so brace yourself:

If you hire average developers without an adequate supply of senior developers to monitor commits and mentor them, you are slowing down the productivity of your whole development team. I’m not just talking about a short-term effect that lasts the duration of the developer’s employment. I’m talking about lasting effects: technical debt that will still be causing your team pain potentially long after the average developers move on.

The trouble is, the average developer may close tickets quickly. Managers sometimes confuse them for 10x developers because they blindly charge forward and get things done: but they leave serious damage in their wake.

You’re paying people to
slow the rest of the team down.

A 10x developer doesn’t have to be very good to be 10x better than average. They just have to be competent enough to avoid leaving heaping piles of technical debt in every part of the code they touch, and (if you’re really lucky) competent enough to clean up other people’s technical debt when they find it.

Of course, everybody has to start somewhere, and every developer is going to pass through average developer territory before they become good, productive developers.

Here’s the problem: Most of the developers I interview have at least 1–3 years of experience, and 99 out of 100 lack a basic understanding of the fundamentals: the two pillars of JavaScript.

If you’re one of the 99, it’s time to level up. I’ve seen newbies progress past this stage in less than a year, and go on to be much more productive assets than those who don’t bother to learn this stuff. You want to be better than 99% of other developers at your job? First, assess yourself:

The Interview

Lots of JavaScript interviews will ask questions about basic JavaScript idioms, syntax, and quirks. Questions like “Do you know what hoisting means?”

I used to do that. I used to also include questions about things like event delegation, `this` context binding, the effects of `setTimeout()`, etc…

I don’t ask any of those questions anymore. I start (and frequently end) every interview with two questions that every JavaScript developer should have ready answers to:

Can you show me an example of prototypal inheritance?

When I ask this question, I’m looking for a basic understanding of the essence of prototypal OO. What is it? How is it different from classical inheritance? What are the advantages?

An entire section of my book, “Programming JavaScript Applications” (O’Reilly) is dedicated to this topic. Understanding the pros and cons of various forms of inheritance is vitally important to scalable application development and the usable life of the code you write.

Depend too much on classical inheritance,
and you will be on the fast-track to a painful rewrite.

Can you show me two example use-cases of closures?

Interestingly, this question doesn’t necessarily test functional programming. What it does tell me is whether or not the candidate has a good grasp of one of the things that makes functional programming a usable paradigm in JavaScript. In order to get good at functional programming in JavaScript, you must have a good understanding of closures.

Closures are the key to encapsulation in JavaScript. They enable true data privacy for objects, and protect against function side effects.

Ironically, having a poor understanding of how closures work can cause tight coupling and side-effects when they’re misused, which quickly leads to unmaintainable code and a breeding ground for bugs.

Functional programming can be taught, but only after the developer has a good grasp of closures.

In order to get good at functional programming in JavaScript,
you must have a good understanding of closures.

Learning The Two Pillars of JavaScript

I rate prototypal OO and functional programming as the two most important features of JavaScript. They’re essential components of all JS application architecture. Both prototypes and closures are very heavily used in every large-scale JavaScript app I’ve ever laid eyes on.

99 out of 100 candidates bomb
at one or the other, or both.

In JavaScript, it’s literally impossible to be really effective at asynchronous programming without understanding closures and the negative impact of side-effects. The problem? All JavaScript applications depend heavily on asynchronous programming skills.

Likewise, effective processing and organization of data relies heavily on working with objects. If you don’t know what a prototype is, how to use concatenative inheritance effectively, and how to avoid the pitfalls of class-based programming, it’s going to cause problems.

JavaScript Training is Great… at First

Most JavaScript books and training programs are great at teaching you the basics of imperative and procedural programming. Those are important fundamentals to grasp, to be sure. The problem is that they frequently drop the ball there, or proceed to teach you how to mimic classical inheritance in JavaScript, which is frequently problematic.

It’s problematic even if you don’t realize it. Class related problems tend to sneak up on you, and frequently, programmers familiar with classes don’t even recognize the pain it causes until it’s gone. When I switched from C++ and Java to JavaScript and stopped using classes, it was like coming out of a dark tunnel into the light.

Once you’ve learned about (and practiced) variables, arrays, object literals, loops and if statements, it’s time to crank it up a notch and learn about concatenating objects, callbacks, higher order functions, transforming arrays with `Array.prototype.map()`, and so on.

Most JavaScript books suck at teaching you the essence of prototypes and functional programming: fundamental building blocks of modern web applications.

In order to address these issues (and broader questions like what concerns are important to think about when you build an application), I wrote the book “Programming JavaScript Applications” (O’Reilly).

It’s designed to help somebody with 1–3 years of JavaScript experience level up and become a more productive application developer, and it’s a great resource if you want an overview of what’s involved in programming scalable, production applications.

The trouble is, you only get so much depth from a book. I didn’t spend much time telling war stories about real production apps that I’ve built. I didn’t spend a whole lot of time explaining any particular concept in depth. I feel pretty guilty about how I skimmed over functional programming and didn’t really give the reader new to functional concepts a good grounding.

It’s still the best resource I know of to introduce you to JavaScript application architecture and topics that are frequently neglected in most other programming books, but we can do better.

A New Approach to JavaScript Education

Because of the enormous void in the extremely crowded and confusing JavaScript education space, I’ve spent the past year or so developing a different type of educational experience for people who want to learn JavaScript.

Learn from the mistakes of others.

It seems most JavaScript training programs lean too heavily in one direction or another to impart both practiced skills and wisdom. There are two ways to become a wise programmer: Make a whole lot of mistakes in your own code, or learn from the mistakes of others.

I find the best way to transmit wisdom is to tell stories. If I only tell you that classical inheritance is bad, you probably won’t believe me. If I tell you stories about how it’s wreaked chaos in projects I’ve been involved in, it gives you the opportunity to feel the pain and gain a real understanding.

For story telling, few mediums work as well as video. It’s high bandwidth. It transmits audio, video, body language, vocal inflections, and a lot more. It helps drive home points more easily than you can with text alone… but most of the video based programming lectures I’ve seen rattle on and on without giving students the chance to really absorb things. After about 15–20 minutes, students start to get distracted and their attention drifts.

The best way to learn how to code is to code.

Students need an opportunity to practice a concept before moving on to the next one. Information needs to be soaked up gradually, a little at a time. I find 5–15 minutes of video at a time is ideal.

Video is great, but the best way to learn how to code is to code. Books are a pretty lousy medium for teaching programming skills because you tend to get so wrapped up in reading, you forget to practice.

To be truly effective, every programming course should pack in lots of practice exercises.

Don’t underestimate text. Good text can be instructive and persuasive, and students don’t need a remote control to absorb it at their own pace. Books can also communicate visually with charts, graphs, and illustrations to drive the points home.

Students learn well in groups. Study groups are a fantastic way that students can learn from each other. Only practice is a better teacher than teaching. Tutoring, mentoring, and collaborating with other students will exercise the same skills you’ll be using frequently on the job. The best way to be a 10x developer is to help 5 other people be 2x developers.

Welcome to the Future of JavaScript Training

A really effective JavaScript training program will include all of those elements, and it will focus heavily on the fundamentals. It’s not OK that so many developers have a shaky grasp on the most important concepts in JavaScript. JavaScript is a multi-paradigm programming language, and it’s unwise to ignore any of those paradigms. Eventually, you’ll be faced with code you don’t understand, or challenges you don’t know how to solve effectively.

“Learn JavaScript with Eric Elliott” is a series of courses that focus on transmitting skills, knowledge, and wisdom as efficiently as possible. The courses have been in production for most of 2014, and they’re absolutely packed with important lessons I learned building apps for millions of users over a career that spans more than 15 years.

We’re letting students into the first course soon, but there are killer deals running while the courses are in pre-order. For a very limited time, you can purchase lifetime access to every course. Right now, the courses are “JavaScript Software Testing with Sauce Labs”, “Prototypal OO”, “Functional Programming” and “Node and Express”.

We’re concentrating at first on areas where current training resources are really lacking, and once we’ve bridged that gap, we’ll fill out the courses with other topics, including JavaScript basics, asynchronous programming techniques, and more.

If you’re ready to level up, you can pre-order your lifetime access pass athttps://ericelliottjs.com/.

Fighting Poverty with Code

I’ve spent several years commuting to work in San Francisco, passing hundreds of homeless people in the subways and on the streets every day. The San Francisco bay area offers the best selection of opportunities for programmers available anywhere in the world, but that opportunity comes at great cost. City laws place artificial restrictions on the height of buildings, and San Francisco has a very limited area of land to build on.

The result of these forces should be obvious: San Francisco’s housing costs are three times the US national average. The costs are so outrageous, even developers making six figure incomes struggle to afford rent in San Francisco. Every area within a reasonable commuting distance of San Francisco also has elevated rent prices. What’s worse, the buyer’s market is dominated by investors, which puts home ownership out of reach of all but the highest income earners.

The homeless problem isn’t just limited to the bay area, though. It’s just particularly visible and impossible to ignore there. Nation wide, 12.5 Million American families live paycheck to paycheck. Millions of children experience homelessness each year.

There is hope, however — There is a global housing-first movement that has taken root in the US. The evidence is in: Housing-first works. We’re working on a program to make our courses and other CS training resources available to housing-first job training programs so that people in need have the opportunity to learn skills that can keep them off the streets permanently.

When you purchase our training program, your contribution is helping us expand our resources and make the vision of JavaScript training for the homeless a reality. We’ve spoken to many homeless and formerly homeless individuals who have learned JavaScript. They’re walking testimonies of your ability to transform lives with your purchase.

If you’re interested in helping, the first step is to buy your lifetime access pass to “Learn JavaScript with Eric Elliott” while they’re still available.

Lock in your lifetime membership now.

To learn more about our housing-first program, read “Fighting Poverty with Code”.

【再思考】1013. Battle Over Cities (25)

1013. Battle Over Cities (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 160...
  • fynjy
  • fynjy
  • 2015年08月07日 10:44
  • 763

[PAT (Advanced Level) ]1013.Battle Over Cities 解题文档

1013. Battle Over Cities (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 160...
  • u010536377
  • u010536377
  • 2015年10月21日 22:35
  • 329


2011.8.11 多年以来,我看到大量关于javascript函数调用的困惑。尤其,许多人抱怨函数调用中“this”的语意是混乱的。 在我看来,大量这样的混乱可以通过理解核心函数调用原语被清...
  • littlechang
  • littlechang
  • 2012年11月13日 22:11
  • 2718


原文:http://www.ibm.com/developerworks/cn/web/1207_wangqf_jsthis/ JavaScript 是一种脚本语言,因此被很多人认为是简单易学的...
  • Quincylk
  • Quincylk
  • 2016年08月11日 16:40
  • 555


这三个东西虽然一直再用,也用的很顺手,知道它的用法,也知道它的区别,但是最近在攻克设计模式这个高地时总感觉缺点什么,没得办法,就只好重新学习一下。并总结了些许个人心得,分享给大家。 this ...
  • weixin_41559723
  • weixin_41559723
  • 2018年01月03日 18:36
  • 52

1001. Battle Over Cities - Hard Version (35)

It is vitally important to have all the cities connected by highways in a war. If a city is conquere...
  • zorelemn
  • zorelemn
  • 2015年03月11日 19:26
  • 3869

利用js修改 css样式 注意点 !important

当你发现 你利用js 脚本修改 css样式变量的时候,命名 脚本写的正确,但是修改不过来,则查看 css样式中 是否使用了  !important;...
  • chenyongtu110
  • chenyongtu110
  • 2015年10月25日 10:38
  • 1992


今天在html文件头部写了一段js用来修改外部CSS文件的一个样式,其中外部文件中的该样式在应用到不同的media 中时各重写了一遍。 调用js修改后每个media下的该样式都被改写。 修改其中一个m...
  • Big_Old_Fish
  • Big_Old_Fish
  • 2016年10月11日 10:22
  • 1620


之前在网上看到一篇讲述CSS HACK的文章,主要用来区分的为\9,*,_,!important这四个。今天实验了一下,发现与文章中有一些出入,下面为IE各版本对于这几个的支持   ...
  • qingliuFu
  • qingliuFu
  • 2016年09月21日 11:02
  • 1375

CNN入门必读经典:Visualizing and Understanding Convolutional Networks

本文主要是借助deconvnet来可视化卷积网络,这对于理解卷积网络还是非常重要的,同时本文又是13年ImageNet分类任务的冠军。 代码: https://github.com/guruucs...
  • bea_tree
  • bea_tree
  • 2017年04月03日 12:55
  • 1588
您举报文章:Understanding JavaScript is Vitally Important