JavaScript for Impatient Programmers
exploringjs.com
exploringjs.com
Don't know how to setup node.js? Google should lead you to `npm init` or a starter. Getting some weird syntax error? Google it. Once you learn the basics, want to do X? Google it and determine a) how to do X, or b) if X can't be done / is bad practice.
Just by diving head-first into whatever you're trying to accomplish (or a toy project if you just want to learn), eventually you'll start to get the hand of syntax, libraries, and general programming style. But read articles every once in a while on best practices so you aren't learning the "wrong" way to do things.
The big drawback is that there are a lot of Google results that are outdated, novice, or flat-out wrong. You have to really learn how to do research on the internet. But this is a skill you should learn because you can apply it to anything. My general advice: consult official docs whenever possible; Stack Overflow is reliable but check the answer's comments to see if it's outdated; use Reddit to compare X vs. Y; try to avoid long wordy articles on bloated sites, generally the better the writer = the better the article and more likely it's accurate.
Sometimes you have to engage with someone else to solve a problem, but there are hundreds of people willing to do just that at literally any given time of day.
For context, I use javascript & basic html css to make simple apps for my own use. apps.bydav.in
One "patience" problem I have is that problems are usually much more complex than they appear. Node is giving you some random dependency error? It's because you need to install X. But to install X you need to install Y. But to install Y you need to install Z. But Z requires some specific node version. But that specific node version will break A, and to not break A you need to install B which requires you to disable your Mac's SIP so that it can work with X. If I sniff that I problem will lead me to a hole like this I get so annoyed that I start avoiding that specific platform as much as I can.
Software is so fragmented nowadays that even setting up something simple requires you to handle tons of difference pieces for no good reason. Monopoly aside, this is one reason I like Apple having full control of iOS development.
I recently discovered Vite (with pnpm) and so far I haven't had any annoying JS/npm/engine issues, so that would be my recommendation. Generally to setup something I either a) run `<build-tool> init`, b) "create new project" in IntelliJ, or c) clone a medium-sized project on GitHub, then remove the code and leave the configuration files.
For the parent: Java is completely different to JavaScript - the similarity is an accident of marketing and an original vision of the Web (in which most code was written in Java not JavaScript.)
If I pick up something new and just try to piece things together using a sample project or whatever, I tend to think in ways from the most familiar language I work in.
Also without familiarity, you can’t judge if the sample you picked is super opinionated or does things in a weird way.
Javascript traditionally had NO good language guides, and this one looks pretty like the one you should read in advance. Other resources are either more library reference-like, very situative or for unclear standard, not exhaustive, or just stupid and wrong. I’ve read a language guide A to Z for every PL I used in my life (a bunch), and can say by skimming through few rough/key topics that it is definitely a good one. No offense, but my advice is to not apply your advice when there is a good guide. You’ll save both your own time and the one’s who will come after.
nowadays I usually refer to MDN docs and one of the guides like above when guidance is needed.
In my experience, this is a terrible advice. However, many of my students follow this advice over my protests and only a handful of them actually learn anything at the end of a long masters program.
a) "I learn what I need to accomplish this task". This is observed as question/answer and only the simplest version of the answer is needed. So something like "how do I create a variable x and assign 10 into it. All he's looking for is x = 10
b) The second kind wants to understand the nuance of what's happening, so they can apply that nuance to future code. They are looking for an answer, but the are interested in the working that leads to the answer. So in the above example they want x = 10 var x = 10 let x = 10 options{x:10}
and so on. They digest when to use one and when to use another, and they delight in using the correct form in the correct place.
In my experience (a) programmers will get through tasks quickly, but with shallow understanding. They will eventually have all the tools, but lack the ability to see the big picture. They struggle to read other people's code.
On the other hand (b) programmers learn much more slowly, they take a lot of time to accomplish tasks because they are being distracted by their curiosity. But after that investment they easily outstrip their peers in productivity, and more importantly can do things that an (a) type programmer can never do.
What I've come to accept though is that giving a (b) answer to an (a) questioner just leaves them confused. They asked about assignment, and a discussion of scope just leaves them befuddled (since they don't know what scope is anyway). Which can be frustrating to the answerer who is a type (b).
Type (a) should not be doing a Masters program in the first place, so I feel your pain in that regard. Google is great when you're out in the world, but it's a terrible way to "big picture" learn.
I've [1] adopted the approach of meeting the student where they are answering their question, then trying to take them one step further. I try to encourage good habits, and at the same time ceasely mock bad habits (in a gentle, running-joke, kind of way.)
That said I also demonstrate the use of Google in answering a bunch of questions, for which the internet is overflowing with answers. Google is a fantastic resource and there's a lot of great stuff out there.
[1] I am not an academic, and my "students" are not in school. They are typically professionals, trained in another discipline, who were around when computers started, and there was no software so they had to write their own. They have 40 odd years of programming experience, but usually with zero formal training. Seeing individuals in this age-group make breakthroughs though is immensely rewarding.
The most important thing impatient programmers need to learn is TO NOT BE IMPATIENT, not how to learn a programming language in X minutes.
Learning patience will help you in all aspects of life.
Do you really want to share the road with somebody who learned to drive in 5 minutes, and doesn't have the patience not to speed, tailgate, run stop signs, red lights, and pass you on the right by driving on the sidewalk?
More "real" advice: Read LOTS of other people's code.
Need to use a library? Then first read the documentation, then read the source code, so you actually understand what it can do, how it does it, that it's not magic, what its limitations are, how to use it, and if you actually need it.
I've been working on learning and reading the D3 data visualization library for several years, bit by bit. It's a wonderful library, there's a whole lot to it, the code is brilliant and expertly written, and I've learned a LOT about JavaScript programming in general by reading different parts of it again and again.
Mike Bostock: 10 Years of Open-Source Visualization: Did I learn anything from D3.js? Let’s see…
https://observablehq.com/@mbostock/10-years-of-open-source-v...
>In honor of D3 1.0’s tin anniversary, I thought I’d reflect on lessons learned. This isn’t intended to be too comprehensive or serious — just a handful of observations as I look ahead to the next ten years. But I hope a nugget or two will interest you, too.
HN discussion:
That's the opposite of thread OP's advice. If you need to use a library and you're impatient, find the closest example to what you want to do and then hack away at it until it does what you want.
>But read articles every once in a while on best practices so you aren't learning the "wrong" way to do things.
>The big drawback is that there are a lot of Google results that are outdated, novice, or flat-out wrong.
>My general advice: consult official docs whenever possible
After you read the official docs, and decide you actually want to use a library for something that's not trivial, one-off, or throw-away, it will benefit you to actually read the source code itself, which is by definition not out-of-date and incomplete, like so many of the articles about the library you can find by googling and reading stack overflow.
In my book, hacking away at using a library until it does what you want involves reading the source code in the developer tools by setting breakpoints and browsing the call stack, function definitions, local variables, and data structures, while the code is alive and running.
Once you've done that, it's a lot more interesting and easier to then read the entire source code on github front to back, to learn the library well, because you will have a lot more context about how it's actually used and fits together, its dynamic runtime behavior, and the shape and texture of its objects and data structures.
And the most important advice, in my opinion, is to expect to write a LOT of garbage code that you replace almost immediately. It’s not like pouring concrete. You’re not wasting your time or code. It’s a learning process and once you’ve written it, you’ve absorbed all the good and bad lessons from it.
I struggled a lot with paralysis where I refused to even begin a project until I could see the “right way” to get to the finish line. But now I just do a tiny little bit of design (for toys and personal projects) and then dive in.
There’s no better way to deeply understand why a certain concept is important than doing it wrong and suffering the consequences.
For someone who knows the J's basics , I mean
But my recommendation is Firebase or Supabase. These tools were basically designed for this type of webapp. I know a team of junior devs who created a production-app in a few weeks with Firebase. Firebase handles authentication, the database REST endpoint, and various other common webapp functionality, so that stuff is seriously achievable in hours. In Supabase "signup", "login", "login with provider", "send reset email" are all single JS functions.
It would take 5 or 10 minutes (npm install taking up the majority of that time)
Other languages have some of that sprawl, but none quite to the same level, and none with the same pace of change.
If you learn like me, my advice would be to have a list of potential candidate projects to learn from and move on to the next one when the tool and dependency hell proves too much.
The third project I went with went much better, though it was still difficult to learn things (even if they are working) as every project seems to choose different build/deploy tools.
So maybe you're right. Perhaps everything is terrible everywhere.
I used to keep a paper copy of “JavaScript pocket reference” on me, and pull it out on the train, or just sitting around at night, to help get the concepts.
Go ogling it leads to being told to use os package managers, which do the wrong thing
So nothing will replace the experience of pain when learning.
I looked around a bit and found the perfect book for me: Modern JavaScript for the Impatient by Cay S Horstmann. A terrific way to learn JavaScript.
I especially liked how the author came up with 5 golden rules to follow right up front, such as "avoid automatic type conversion". JavaScript has so many crufty historical flaws, and by following these rules, he doesn't have to explain all the weird historical stuff. That cut out a lot of laborious explanation of things you shouldn't do anyway.
The examples were very well chosen. They focused on the important stuff, yet still explained the key gotcha's inherent in the language. Every paragraph seemed to have an important point.
It is a shame this is only the 85th most popular JavaScript book (as of now). It deserves to be better known. It is a classic, and perhaps the best computer book I've read since "The Go Programming Language".
Highly recommended.`. Will add this to my read-list after I complete WatchAndCode
Async is easy as well. I really don't understand the hate, what am I missing? Maybe I'm too dumb for other programming languages. I did try various languages from Java, Elixir, Haskell, Rust, Go, Ruby, Python and JS is simply the best in productivity, expressiveness, ease of use and performance balance.
As long as you don't code in a clusterfuck way, it is so easy to write JS and compose JS functions. Just use functions everywhere, no need class. JS is very readable.
Like, seriously, Python has Python2 vs Python3 package and build/deployment problem. Haskell is difficult and the tooling is abysmal. Rust is difficult and too much choices to just write this and that. Ruby has no tpe system and slower than JS. Python is also slower, no good async, and its type system is not expressive as TS. Go's type system isn't expressive enough. Java type system is too much and JVM is complicated. Scala is complicated.
JS/TS is:
- simple/easy to use
- pays the bills (you can go anywhere and find jobs as JS/TS dev in almost every company in the world)
- everywhere, like from IoT to robotics to game development to server to frontend to regular scripts
- easy programming language to do Leetcode style interview as well
- if you wanna do Option/Maybe style error handling like Haskell/Rust/Go you can do that with TS, just wrap try catch and return the error with neverthrow library. This makes TS programming bliss!!! I freaking love it
If you don't want to care about setting up NodeJS + TS, now you have Deno, who's pretty much out of the box everything just works.
JS/TS is such a super boring language it feels like cheating your way out of software engineering. It is a language made for dumb people like me, maybe that's why it has no appeal for hardcore programmers.
I owe to JS/TS on changing my life and giving me a good living.
Like, seriously I don't understand the hate...
Now I’m a full time JS/TS developer and I love the language. It’s a dream to use. The syntax is concise and logical, the ecosystem is vibrant, and the barrier to entry is low. I wish there was more JS in the scientific, CV, and ML spaces — Python is still superior here, imo — but otherwise JS is my go to. It’s no wonder we see the rise of Electron apps - the developer experience is just so much better.
Now it's a pretty nice ecosystem, but it used to be pretty bad. Not everyone's biases have caught up yet.
My problems with JS/TS:
Simple to start, but hard to program robustly and defensively. Due to the lack of typing, a lot of the codebases I’ve seen end up with extensive input validation code, which often uses fancy tricks that are hard to parse (unless you already know them). Typescript helps with this, but it is not the same as a proper type system because it is optional. Usually I run into runtime problems due to type errors with library code which doesn’t have types (or has the wrong ones).
The core language is filled with weird edge cases in coercion. jsfuck.com and https://www.destroyallsoftware.com/talks/wat are examples. This doesn’t affect my day-to-day code, but it’s equivalent to C undefined behaviour for me. A bunch of hidden rules that I don’t really want to extensively learn and understand, but which will bite me when writing anything moderately complex. ‘===‘ is good, but I think it’s really easy to miss the extra equals, especially if you write code in other languages a lot.
Lack of standard library (in Nodejs). For quick things, I find Python a lot better. The scant JS standard library has been widely criticised. This is a contributing factor to the absolute explosion in the dependency graph whenever you start pulling in a lot of the common dependencies. IMO, Go and Rust both do a better job despite having comparably easy package mangers.
Although some JS code is easy to read, I’ve seen lots of examples of overuse of functional indirection. Maybe it’s something I will start recognising the patterns once I’ve come across them more, I end up ragequitting JS codebases much more often than other languages. Despite its flaws, Go in a good editor is an absolute joy to understand new codebases.
I’ve found a combination of Python, Go and Rust to be the ideal combination. Each has its flaws, but for any specific use case, I can pick one I’d rather use than JS.
A few of them are really hard to avoid, though, like the fact that JS has both "null" and "undefined", and these two values are sometimes treated as the same and sometimes treated as different.
Btw it sounds like you might like Deno. Have you given it a try?
Are you talking about point free programming here?
A good example of what I mean is here (fresh on my mind because I was looking at it yesterday): https://github.com/FortAwesome/Font-Awesome/blob/master/js-p...
Somewhere this file defines an exported function called `icon`, but it took me way too long to find where and even longer to see what it was actually doing.
This might not be idiomatic JS code, but I’ve definitely seen other popular packages have similar code (especially internally).
I use TS professionally, and it is my go-to choice for personal projects too.
Deno and vscode have brought an extra dimension of awesomeness - I personally never liked using npm (and therefore node) and try to avoid it.
An off-topic question: how do modern development practices using async code avoid race conditions and intermittent heisenbugs?
Async doesn't change any of this, and is mostly syntax sugar for callbacks. However, there are of course logical race conditions so when you use async you must be aware that the entire world can have changed after an await.
If you're actually serious about learning to program, then it's going to take more than a few minutes of your life to learn.
But if you can't stomach investing more than a few minutes in learning to program in JavaScript or any other programming language, then you should really find something else do to with your extremely limited time.
Teach Yourself Programming in Ten Years, by Peter Norvig:
https://norvig.com/21-days.html
The last time I posted a link to this important essay, impatient people who weren't very serious about investing any time in learning or reading simply and immediately responded to the title, but didn't bother to actually follow the link or read and respond to any of Peter Norvig's brilliant essay (and probably didn't even know who he was), so here is an excerpt.
>Researchers (Bloom (1985), Bryan & Harter (1899), Hayes (1989), Simmon & Chase (1973)) have shown it takes about ten years to develop expertise in any of a wide variety of areas, including chess playing, music composition, telegraph operation, painting, piano playing, swimming, tennis, and research in neuropsychology and topology. The key is deliberative practice: not just doing it again and again, but challenging yourself with a task that is just beyond your current ability, trying it, analyzing your performance while and after doing it, and correcting any mistakes. Then repeat. And repeat again. There appear to be no real shortcuts: even Mozart, who was a musical prodigy at age 4, took 13 more years before he began to produce world-class music. In another genre, the Beatles seemed to burst onto the scene with a string of #1 hits and an appearance on the Ed Sullivan show in 1964. But they had been playing small clubs in Liverpool and Hamburg since 1957, and while they had mass appeal early on, their first great critical success, Sgt. Peppers, was released in 1967.
This essay is a classic that's been discussed on HN numerous times:
https://news.ycombinator.com/item?id=27411276
https://news.ycombinator.com/item?id=20543495
https://news.ycombinator.com/item?id=16574248
The website OP mentions is for someone who already knows how to program well in one or more language and want to take a quick look at another language syntax.
Then they think they can learn programming languages by reading Twitter instead of writing code, and claim on their resumes they know languages they've only read a few blog posts about.
Those are the same people who complain that they hate Lisp by parroting tweets that it has "too many parenthesis", even though other languages have much more complex syntax, much less powerful and more limited and difficult to use macros and meta-programming facilities (like C macros and C++ templates), that force you to use an ugly mish-mash of even more inconsistent punctuation line noise like brackets, braces, escapes, quotes, backquotes, obscure operator precedence and ad-hoc parsing rules, and a myriad of other hard-to-learn punctuation that makes the code much less readable than Lisp, without realizing that there is actually a point to Lisp's clean simple parenthetical syntax.
There's also a long sad history of impatient people not wanting to bother learning JavaScript, but believing that they can simply learn JQuery or React or some other popular "silver bullet" library instead:
Can you get away with learning jQuery only instead of JavaScript?
https://www.quora.com/Can-you-get-away-with-learning-jQuery-...
Should I learn jQuery first or Javascript?
https://www.quora.com/Should-I-learn-jQuery-first-or-Javascr...
Is it necessary to learn JavaScript before learning jQuery? [duplicate]
https://stackoverflow.com/questions/3183545/is-it-necessary-...
Why You Should Learn jQuery Before JavaScript
https://learn.onemonth.com/why-you-should-learn-jquery-befor...
Why Beginners Should not Learn JavaScript through jQuery
https://www.codementor.io/javascript/tutorial/learn-jquery-j...
Do I need to know JavaScript in order to learn jQuery?
https://www.quora.com/Do-I-need-to-know-JavaScript-in-order-...
How is it possible to learn jQuery without first knowing JavaScript?
https://www.quora.com/How-is-it-possible-to-learn-jQuery-wit...
Can I learn React.js if I don’t know JavaScript?
https://oprearocks.medium.com/can-i-learn-react-js-if-i-dont...
Do we need to fully know JavaScript to study React?
https://www.quora.com/Do-we-need-to-fully-know-JavaScript-to...
Once you understand this aspect of the language it's an annoying (to me) idiosyncrasy but manageable. Before you understand it there's a lot of pouring over poorly written tutorials that gloss over it like it should be obvious.
[0] https://journal.stuffwithstuff.com/2015/02/01/what-color-is-...
So in my mind functions did not have colors. They where "first class functions" that you could pass into another function that later called it. Now however we do have normal functions (before ES6-7), as well as async/await promise returning functions, and *function yealding generator functions.
The situation is better now with promises but it was a pain in the ass just a few years ago.
It's idiosyncrasies aren't deal breakers but they're non-obvious. They also crop up once you're into medium complexity code. At the level of simple/trivial code machines and JavaScript engines are fast enough to paper over naively written code. But you get to a certain level of complexity and you get bit by some colored function issue or something.
It's annoying bringing something up where JavaScript is not the primary focus of the project. This is all anecdotal, there's plenty of people that might never have issues. But it was all stuff that tripped me up around 2009-10 having to write some JS after not having touched it since before you could make XHRs or manipulate the DOM directly.
On topic: This is quite a list so I just clicked a random link and voila:
> 7.1.1.3 Assertions
> An assertion describes what the result of a computation is expected to look like and throws an exception if those expectations aren’t correct. For example, the following assertion states that the result of the computation 7 plus 1 must be 8:
> ...
> assert.equal(7 + 1, 8);
> There is also assert.deepEqual() that compares objects deeply.
What? Am I going crazy? Have my years of wild hedonism finally caught up with me? I don't see jest mentioned but fired up my browser's console and sure enough, there is no "assert" in my window. What am I missing here?
I say all this because I fucking hated JavaScript with a passion. From the time of my initial foray into programming until my later years, I hated it. It was always a joke of a language that, honestly, caused me to develop such a bias that I nearly refused to use it, for a very long time.
Several months ago I decided to put my prejudices aside and began playing around with Nodejs and React. The main motivation was trying to learn more about front end development and guess what? I really enjoy JavaScript.
JavaScript is a very enjoyable language to play with. It has come such a long way despite, literally, all odds. The ecosystem is scattered. The build system is the most hacky monstrosity you’ve ever encountered. But, that’s one of the reasons I love it. It feels like the essence of what I feel when I imagine hacking.
And not only that, it uses a unique (at least to the paradigms I’m used to) execution model that is very performant.
These are just a lot of words for me to say I love JavaScript.
> Table of contents takes 15 minutes to read
Functions are const, data is const, and I rarely use classes. It removes a lot of overhead, avoids this questions, and makes everything consistent and so makes spotting similarities and differences easier.
I can do
const myFunc = () => 2;
const res = myFunc();
It helps with the mindset of treating functions as data that can be acted upon similar to how data can be.I don’t know that it eliminates that many questions, but it does eliminate one question, which is whether that variable will be reassigned. Arguably that doesn’t tell you very much.
Highly recommended.