Skip to content

Instantly share code, notes, and snippets.

@ar5had
Forked from rtoal/JSFirst.md
Created May 11, 2017 15:51
Show Gist options
  • Select an option

  • Save ar5had/dd1a4d4925489833cc48f00dfb1e9c2a to your computer and use it in GitHub Desktop.

Select an option

Save ar5had/dd1a4d4925489833cc48f00dfb1e9c2a to your computer and use it in GitHub Desktop.
JSFirst

JSFirst

About This Manifesto

Have you ever argued for or against teaching language X as the first language in a university computer science curriculum? I hope that your arguments:

  • were first and foremost about students, not about your pithy language preferences (in other words, you should answer the question “What do we want to students to gain from their experience with a first language?”, NOT “Is language X better than language Y?” because people hate that latter question);
  • kept in mind that ultimately we want to train polyglots, so the first language is never the only language; and
  • took into account previous work from computing educators, and education theorists and practitioners in general.

I've taught introductory programming courses at the university level on and off since 1986 and have used Pascal, Modula-2, Ada, C++, Java, and, since 2009, JavaScript. Colleagues at my University have also used Python, Racket, and MATLAB as first languages. My first programming language was HP-65 machine language (hey, I was 11 years old and didn’t know any better) and as far as I know it did not cause me brain damage.

Why JavaScript FIRST?

We want students to learn and love computer science, and acquiring programming skils helps the field become alive to them, and allows them to make their own contributions to the wealth of human knowledge. To give them this enjoyment, we have to kindle their interest early and keep them from getting discouraged. I’ve found that starting with JavaScript helps! In no particular order, here are things I consider to be in JavaScript’s favor for a first (CS1) language:

  • No batteries required. There’s nothing to install to write JavaScript: no compilers, no IDEs. Visit CodePen or JSFiddle and just start programming!

  • Students can follow along with you. On sites like JSFiddle you can code a little, share a URL, and students can add their own changes at a fresh URL, which you can then project to the class. When a nice solution to a seemingly hard problem comes up, students have been known to clap for each other.

  • You can write “fun” code, with graphics and animation, on day one (with no special tooling). In my own CS1 course, we make simple pictures and animations with Khan Academy Computer Programming. Students grow the examples into a solution to their first assignment that says only "Make the plane land." I’m very often pleased with how creative many students are with this. Sometimes the plane comes in from the side, sometimes head on, and once the plane looked like a character from a Mario Brothers game. But everyone solves the problem. And they feel good for doing something interesting on their very first day of class. Confidence!

  • It’s NOT the language of high school AP Computer Science. An introductory computer science course in Java with a mix of first-time programmers and AP CS veterans risks some of the first-timers feeling intimidation when seeing the veterans, and risks veterans being overconfident. Granted, you may have incoming freshmen with previous JavaScript experience, and if so, you might want to take an approach like Harvey Mudd College’s Green-Gold-Black courses.

  • You can do internationalization with one line of code, also on day one!. Run any one of these lines in a browser console.

I’ve done these programs before and students who speak Arabic, Hindi, Chinese, or come from countries with different date formats experience a very pleasant sense of recognition and start shedding their misconceptions of programming being an American thing.

  • No magic to hand-wave away. Well this is picking on Java again, because Python and Ruby can do a nice Hello World, but really, what beginner wants to look at public static void main(String[] args)?

  • It is one of the most popular programming languages in the world, and it runs on every device: laptop, Android, iOS. You can write lovely JavaScript programs on Android (you don’t need Java) and lovely JavaScript programs on iOS (you don’t need Swift). Will the native programs look better? Uh, have you remmbered that we are only talking about a first language? You can learn plenty of other languages soon enough. With JavaScript, though, students will know they are learning a real-world language, which often makes their parents happy. Yes, it’s one of those languages that helps them get a job.

  • It has first-class functions and closures for Chrissake. No explanation needed for this one! (Of course, you need to know how to teach this stuff to beginners, so use care if you take a recursion-first approach). Do you think that languages-that-help-you-get-a-job are mutually exclusive from languages-that-provide-a-good-CS-foundation? Provided you stick to the good parts of JavaScript, you get some good overlap.

  • Asynchronicity and Events! Back to putting everyone on an equal footing in CS1: My favorite first-week experience is when introducing animation, I ask the students “how do we move this airplane (or balloon) across the screen?” and some will shout out “For loop” or “While loop” and I get to say ”Actually, that’s a nice idea, but that’s not how we do it.” This is one of the hot shots’ first experience in things being done in a radically different way from what they were previously taught. Imagine: just draw the frame in response to a clock. The system (the animation engine) calls your code. This mindblowing insight (for many students) is just beautifully, natively, wired into JavaScript. No listener or observer interfaces required.

  • It’s Flexible. Just write array literals and object literals; you don’t need a schema. Did I just say I prefer dynamic typing? Of course not. What am I getting at? I want the static things to come later! I want them to experience the fun of making an object or a list (and perhaps animating something), and only after they have done that, generalize. Where is the fun of building, or designing, up-front, a class (with getters and setters, ugh!) before being able to do anything? Doing such a design first does a disservice to the bricoleurs in your class. What is a bricoleur? You need to read Turkle and Papert’s Epistemological Plurarlism to find out.

  • *Unit Testing is Probably Much Easier to do than You Think. See what I did here?

  • It naturally teaches separation of concerns. Computing educators know about computing principles. One is separation of concerns. When you do JavaScript in the browser, you naturally, almost necessarily, show students how to separate content (HTML), presentation (CSS), and interactivity (JavaScript). And oh guess what, the first two are declarative. How nice to teach beginners the ease and importance of what is essentially modeling.

But “What About....?” You May Ask

As one of the most popular programming languages in the world, JavaScript has passionate lovers and haters. Its creator, Brendan Eich, freely admits some less-than-good design choices (https://youtu.be/1EyRscXrehw#t=04m57s). There is much to poke fun at. Yes, JavaScript is featured in the famous WAT Video. Douglas Crockford’s JavaScript: The Good Parts has sections of JavaScript’s Bad Parts and Awful Parts. You can take a rigid, intolerant view and claim the language’s shortcomings disqualify it from consideration for your curriculum lest it poison your young student’s minds. Or you can be a reasonable, pragmatic, citizen of the world, and use these flaws as teaching moments.

  • Weak typing is error prone, yes, but use the potential pitfalls to talk about implicit conversion, and its dangers.

  • Is the language too dyanmic? Flexibility comes with serious tradeoffs. I’ve seen multiple students misspell constructor (as contructor) and somewhere down the line they see undefined. Start a discussion with the students to see how to prevent these errors. (That’s right: unit testing will come up!)

  • That string concatenation tho! Yeah, yeah "2" + "2" === "22". Hang on, why are you concatenating strings anyway? Protip: students don’t mind string interpolation. This brings up a general point. The students will be ready, at some point, for a linter. Most of the silly WAT stuff can be caught by a linter.

  • Too high-level. Too far removed from the machine.

JavaScript is not the only language with flaws.

Can’t Other Languages Do What JavaScript Can Do?

In 2006, Joel Spolsky wrote Can Your Programming Language do This? While certainly not a treatise in favor of JavaScript for CS1, he does use JavaScript as an example of a language in which functional abstraction is easy to do (not to mention important), and links to another article of his on the danger of “Java schools” so he’s got some thoughts on education.

What about its competitors? If you want simplicity and ubiquity, and ease of expression, Python is ready. It’s not a bad CS1 language. But we don’t quite get the HTML and the CSS, we don’t get the just-get-started-in-the-browswer. We get async and await and other goodies but we need Python 3.5 and up. We have ubuiquity on the server side, but not the client side. If we want safety and security, we have Java and C#, but these are a bit verbose. Some students will not mind this; others might get overwhelmed (remember, we are talking about an intro language). Type inference to the rescue? Haskell, Standard ML, OCaml? I think we lost ubiquity.

JavaScript has a lot in its favor.

We’ll never all agree

I’ve just laid out a few things I like about JavaScript as a CS1 language. I’m not trying to convince anyone that it’s the best language for this purpose. I don’t even want to convince you of anything, really. Some people will agree with me and some will not. Speaking of agreement, even if we all agree that setting a good foundation for further study is a good CS1 goal, some people will see that foundation as the lambda calculus and functional abstraction (a la SICP), and others might see it as an appreciation for memory management and the connection to the underlying machine. Some will want students to learn design-first, abstraction-first; others will want students to prototype first, and work from the concrete to the abstract. Should we design experiments (with control groups) to see which of these is best? Have such experiments been done?

You know what we might find, right? That some students prefer learning one way over another, while other students prefer the exact opposite. Some students will gravitate to and love functional programming; others will prefer state-based imperative computation. One size does not fit all.

It doesn’t have to. All I want to say is JavaScript is, IMHO, a good vehicle for CS1. JavaScript + HTML + CSS, setting students on the road to becoming polygot computer scientists. Teaching JavaScript FIRST or Python FIRST or Java FIRST or OCaml FIRST or Racket FIRST does not mean we ignore other languages. We want to choose a first language that gets students hooked rather than discouraged. And, by the way, if you feel that your students are so weak that the first language they see will be forever burned into their mind, that all the bad habits and weaknesses of that first language will instill in them bad habits for the rest of their lives, then ask yourselves or your colleagues how you might serve your students by preventing such a poor approach to lifelong learning take hold in them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment