Earlier quoted context omitted.
> I learned a lot about JavaScript (and Node.js) by writing shell scripts in Node.js. Totally! This will give you lot of insights into low-level working of JS. Of course, some Node.js specifics too. Reading from STDIN, parsing strings into structured data etc.
For writing shell scripts in Node, there’s a helper library called zx created by Google. I find it a lifesaver for the common occasion when I’m tempted to write a bash script but also know it’s going to need some slightly more advanced features (as in parsing a JSON, or just arrays that are not totally bonkers in syntax).
Ask HN: Changing my mind about JavaScript
51–60 of 73 posts
Re: Ask HN: Changing my mind about JavaScript
#52I have been using JS for more than 20 years, and I do not like it. There are parts of it I find useful, but I avoid using it as much as I can in any project. The biggest reason for this being that the execution of JS code it down to the browser rendering the page where it’s deployed. As such it’s practically impossible to get any code to run consistently. This is of course only relevant in my day to day work as a web…
> the execution of JS code it down to the browser rendering the page where it’s deployed. As such it’s practically impossible to get any code to run consistently Can you elaborate on this part? I would say one of the strengths of JS is that you can get it to run consistently just about anywhere.
Every browser implements a version of ECMAScript (this is a specification declaring what features of the JS language will be available for the JS engine included with the browser).
This means that every browser on the planet, and every version of them, support different JS features.
For example, let and const are commonly used to define variables, but if someone happens to use an old browser version the use of these would cause an error, which in turn may cause all the rest of JS code to stop executing, resulting in (worst case scenario) your website being rendered useless to that particular person.
On top of that different browsers may use different engines. So even if they define the same ES version the code may still execute differently (this was for example a very big issue with Microsoft browsers in the past).
This may seem trivial, but new JS features emerge all the time. Granted, this was a much bigger problem before ~2015 something, but it’s by no means none existent today.
Thus, you cannot be sure the code you write locally will actually function the same everywhere, and you are unlikely to know how often failures even occur since it all happens client side.
Re: Ask HN: Changing my mind about JavaScript
#53I have used many languages in my nearly 40 years as a programmer (Scheme, C++, Java, Python, Haskell, OCaml, Rust, etc.) and still enjoy JavaScript: It’s decent as a language and there is so much you can do with it. Tips: • If you like static typing, you’ll want to use TypeScript. It’s more work to set up, but it catches many bugs, especially subtle ones where JavaScript’s semantics are not intuitive. • I learned a l…
> If you like static typing, you’ll want to use TypeScript. It’s more work to set up, but it catches many bugs, especially subtle ones where JavaScript’s semantics are not intuitive. It’s worth looking at JSDoc as an alternative to regular TypeScript. No compiler to set up, and you’re restricted in a good way - less likely to get over-engineered types.
Re: Ask HN: Changing my mind about JavaScript
#54Earlier quoted context omitted.
For writing shell scripts in Node, there’s a helper library called zx created by Google. I find it a lifesaver for the common occasion when I’m tempted to write a bash script but also know it’s going to need some slightly more advanced features (as in parsing a JSON, or just arrays that are not totally bonkers in syntax).
Yes, I was about to propose this. But then again, the author wants to learn the basics without grappling with abstractions. I think zx can be a bit quirky.
You need to understand async/wait, promises and tag functions to make sense of this basic zx example:
await $`ls -la`Re: Ask HN: Changing my mind about JavaScript
#55Earlier quoted context omitted.
> the execution of JS code it down to the browser rendering the page where it’s deployed. As such it’s practically impossible to get any code to run consistently Can you elaborate on this part? I would say one of the strengths of JS is that you can get it to run consistently just about anywhere.
Certainly! Now, I’m no expert and may get some things wrong here, if anyone else knows better I’d be happy to be corrected. Every browser implements a version of ECMAScript (this is a specification declaring what features of the JS language will be available for the JS engine included with the browser). This means that every browser on the planet, and every version of them, support different JS features. For example,…
Re: Ask HN: Changing my mind about JavaScript
#56> Do you have any tip for learning js at it's fundamentals? I would recommend: - https://eloquentjavascript.net/ - https://javascript.info/
I see there's a 2024 edition that I should probably order.
Update: Looks like the 2024 version is going to be released in Nov.
Re: Ask HN: Changing my mind about JavaScript
#57My (unpopular?) take is that JavaScript should suffice. Once I feel the need for TypeScript, I've done something wrong. For example, built my whole frontend with JavaScript or built my backend in JavaScript. JavaScript's use case for me is sprinkling it where needed in browser. Anything extra and it feels wrong tool for the job. Frankly, I believe whole existence of TypeScript is a mistake – we should've never used J…
How would you not build the whole frontend in JS though? Use another compile-to-JS language?
TL;DR: The web platform has evolved (and continues to evolve) so much that I don't see a need to use SPAs for the majority of web applications.
Re: Ask HN: Changing my mind about JavaScript
#58I would recommend using Typescript and a strict linter if possible. TS is essentially modern Javascript plus static typing (so by learning TS, you also learn JS as a side effect), and strict linting rules will reject outdated Javascript features and nudge you towards the 'good parts'. With those two things (a static type system layer, and strict linting) JS is actually a quite decent language nowawadays, especially i…
Re: Ask HN: Changing my mind about JavaScript
#59Earlier quoted context omitted.
How would you not build the whole frontend in JS though? Use another compile-to-JS language?
Render most of the frontend server-side and just use JavaScript for the dynamic bits only, I guess? I personally haven't done it like this since the advent of SPAs, but I'm guessing lots of things are still built like this.
Re: Ask HN: Changing my mind about JavaScript
#60I remember clearly the days of callback hell. You didn't change your mind about JavaScript, JavaScript changed it's mind about being a real language.
I will give it credit, I don't know of another programming language that has changed so drastically and so much for the better.