r/programming • u/whackri • Apr 29 '21
Modern JavaScript Explained For Dinosaurs
https://medium.com/the-node-js-collection/modern-javascript-explained-for-dinosaurs-f695e9747b70106
u/IsleOfOne Apr 30 '21 edited Apr 30 '21
Funny how in just the last 4 years since this article was written, half of the technologies they mention in the subtitle are obsolete.
19
u/Pwntheon Apr 30 '21
Are they?
You can still get by very well using the tools mentioned. I did it in a project recently and everything is working very well.
Edit: The article mentions moment.js - but that's just an example of a package. I'm talking about the toolchain.
-6
May 01 '21
Pencil and paper are obsolete for taking notes in a meeting. You can still do it though.
10
u/WasteOfElectricity May 01 '21
How's that obsolete though...
-5
May 01 '21
So the very definition is that something is no longer produced or used. Obviously this was a very simple example, No one uses pencil and paper to take notes in a meeting anymore, just trying to give an example. Obsolete doesn't mean extinct, it doesn't mean it doesn't work. If something is obsolete it can still work just fine.
8
May 01 '21
[removed] — view removed comment
-4
May 01 '21
That doesnt change anything. It's still obsolete.
6
May 01 '21
[removed] — view removed comment
0
9
Apr 30 '21
Any recommendations on another article or learning material to learn about the latest?
53
Apr 30 '21
The article is pretty decent. It doesn't mention gulp and grunt outside of the image at the top of the article.
Node, npm, webpack and babel are all still widely used and are the defacto standard.
-1
62
u/antimeme Apr 30 '21
moment is obsolete.
I'd recommend date-fns
39
Apr 30 '21
I don't know why you're being downvoted. Moment has been deprecated
I'd recommend dayjs over date-fns though. It has a much nicer API IMO and it has a smaller bundle size.
dayjs() .startOf('month') .add(1, 'day') .set('year', 2018) .format('YYYY-MM-DD HH:mm:ss');28
u/antimeme Apr 30 '21
I have not used
dayjs, thanks...quote from ^that
momentproject-status:We now generally consider Moment to be a legacy project in maintenance mode. It is not dead, but it is indeed done.
10
u/WitchHunterNL Apr 30 '21
The only gripe I have with dayjs is that you have to enable every single feature. You can check if a date A is after date B and if date A is before date C, but calling the
isBetweenfunction is a feature you have to manually enable, making your code look like this:import utc from "dayjs/plugin/utc"; import isBetween from "dayjs/plugin/isBetween"; import timezone from "dayjs/plugin/timezone"; import customParseFormat from "dayjs/plugin/customParseFormat"; dayjs.extend(utc); dayjs.extend(isBetween); dayjs.extend(timezone); dayjs.extend(customParseFormat);8
u/SkyrimNewb Apr 30 '21
Gross
1
u/14u2c Apr 30 '21
Really? This seems nice to me. Add what you need then export the dayjs instance you setup. You can then add a single import to any file you wish to use it in.
1
6
5
u/CoffeeGreekYogurt Apr 30 '21 edited Apr 30 '21
I’d like to imagine that people reading this thread in four years will think “What?
momentis obsolete, everyone knows the defacto standard iswhat-time-is-it-right-now.com!”1
u/earthboundkid Apr 30 '21
I just use native dates. You don’t really need a library for much nowadays.
10
14
Apr 30 '21
Typically the more things you need to prop up your coding language.... Doesn't that mean there is a flaw with your coding language? (Before the nooooooo people get here notice I said flaw, I didn't say it was a bad language)
6
u/ZPanic0 Apr 30 '21
Flip it around to see the granularity. Are there any languages that do not require any sort of runtime or compilation?
6
u/social-media-is-bad Apr 30 '21
An interpreter or compiler is a single tool, throw in a package manager and most languages require two tools. This article ends with the use of four tools and that doesn't include the actual language interpreter (which is the js engine in the clients browser).
Each tool (on any software project) introduces fragility, maintenance, overhead, and potential security vulnerabilities.
1
u/StillNoNumb May 01 '21
A large tool requires more overhead than a small tool though. By having small tools like Webpack and Babel separately, this allows faster evolution, for example at any time I could replace Babel by TypeScript, or Webpack by Parcel, and the build step is considerably more modular.
There's definitely some reason in your argument though, but we can't just ignore the advantages this approach provides us with.
2
u/social-media-is-bad May 01 '21
What’s the Python equivalent to Babel? As far as I know, there is none because Babel solves a problem that other languages don’t have.
There are tools that will help with a one-time conversion of python2 code to python3. There aren’t any widely adopted tools to transpile python 3 backwards to 2 because that would be hacky and weird.
Babel solves a problem that other languages don’t have, but it does so by potentially introducing bugs and security problems, and definitely introducing config cruft to maintain.
Similar issue with webpack: I’ve never had to deal with the problem it solves in another language. I understand the utility of these tools inside the browser but the fact that they’re needed is a big red flag in and of itself.
1
u/StillNoNumb May 02 '21
The Python equivalent to Babel is install multiple versions of Python or even packaging the entire runtime with your app. A terrible solution.
Think of Webpack as the part of the interpreter which compiles
.pyinto.pyc.2
6
u/social-media-is-bad Apr 30 '21
I may be turning into a grumpy old person but this comment nails it. Constantly running into problems and adding stuff to workaround it is a code smell IMO, and modern javascript reeks.
I can maybe understand it for front-end web stuff exclusively, as there you're dealing with baked in deficits in the language/runtime. My instinct would be to live with it but make it as "dumb" as possible, and push important things like routing and business logic elsewhere. Instead people are building SPAs.
But for mobile or server applications why would you want to deal with this stuff? The only thing you get out of the tradeoff is the ability to use the Javascript language. Even if the language were amazing I don't think it would be worth it.
4
Apr 30 '21
Yeah why would you want to write code in a language that has support on every major platform?
0
u/social-media-is-bad May 01 '21 edited May 01 '21
Ever since I gained the ability to write .NET code on an ARM MacBook I’m not really worried about portability.
Seriously, inside the browser JavaScript is the only game in town and I’ll deal with it (as little as possible). Outside the browser, plenty of good languages/frameworks are available. But I’m also serious that maybe I’m just a grumpy old person that’s wrong about the kids these days.
70
u/k1lk1 Apr 30 '21
Lipstick on a pig. And just results in insanely bloated websites that perform badly, all the while webdevs pat themselves on the back every 6 months for reinventing DHTML for the 132nd time.
43
u/radol Apr 30 '21
What is your preferred approach to front end for complex systems which does not result in ton of js being used?
8
-9
u/AyrA_ch Apr 30 '21
That depends on your definition of "complex systems" but raw HTML and CSS gets you pretty far usability wise now.
45
u/blazarious Apr 30 '21
Modern frontends are often times applications. Can’t write applications with HTML and CSS only.
10
u/kuikuilla Apr 30 '21
Yet most of the time they're just CRUD frontends for various data sources.
7
u/blazarious Apr 30 '21
I like doing CRUD applications with React, though. While certainly not necessary, it makes for a better UX in my opinion. And you get an API for other frontends basically for free that way.
2
u/AyrA_ch Apr 30 '21
You can. It's what we did before everything just had to be made in JS. There was a time where things like youtube and ebay worked with JS turned off.
33
37
u/blazarious Apr 30 '21
I’ve been making web stuff since the dawn of the web and I’ve been laughing at JavaScript for decades. Nowadays it’s one of my favorite technologies.
And no, you cannot create modern user experience without JS.
I do agree, though, that not everything needs to be an application and a lot of websites get bloated for no good reason.
-7
Apr 30 '21
"modern user experience"
loads website
tries to click on widget
website layout changes suddenly but I already clicked on something I didn't want to
clicks Back, nothing happens
starts from step 1 again
Javascript/browsers are still laughable tech compared to VMs. Js is a toy script language running on a slow and bloated VM with one of the worst layout systems ever created. Doing anything with react feels very counter-intuitive and requires a lot of digging in documentation.
4
u/jl2352 Apr 30 '21
What you describe as a 'modern user experience', I would describe as a 'shitty user experience'. It has nothing to do with the tech stack. There were plenty of terrible websites in the past.
You can design and build good applications. In my experience bad applications aren't bad because they use React or Vue. They are bad because they didn't, and as a result scaled really badly. Either 1) they are still bespoke, trying to do really complex things, and fucking it up. Or 2), they are some bizarre monster that loads multiple technologies at once, and none of them work nicely together. Think of news websites that load React, Vue, and four copies of jQuery (yes these exist).
Websites that start out using a modern JS framework, tend to be pretty nice to use.
1
Apr 30 '21
The reality of things is that "modern frontend" is still complex and most will fuck it up - like this site. Most companies use react because it's cool and have no idea how to replicate proper behavior - that's why it should be hard to create bad design. I'd prefer layout presets and functionalities that can't be changed.
2
Apr 30 '21
[removed] — view removed comment
-3
6
u/twenty7forty2 Apr 30 '21
but as a developer it sucked. I recently went from tsx back to plain server side templates and it is a nightmare in comparison. tsx is fully typed, ide knows what's going on, compiles on the fly and tells you what you've broken vs templates are practically just plain text that slips bugs into production.
also adding js to websites used to be called progressive enhancement. so arguing it was better before it was enhanced is a bit stupid.
2
u/jl2352 Apr 30 '21
If you are building a website of documents; then yes. Do what you describe. That's what any front end developer would do. Even if they used React or Vue, it will essentially still be HTML documents. Powered by a bit of JS, rather than PHP or Ruby.
If you mean raw HTML & CSS as in just
page.htmlwith nothing else ... that doesn't scale. You will be copy / pasting HTML across pages. You change a navbar, and then need to manually copy it to every file. You will need something to give you code re-use. That doesn't need to be a front end framework.However very few websites are just a list of documents. Most need to do more than that. Maybe your suggestion is you could just use jQuery for that, and not bother with React nonsense. If that fits your needs; that is fine.
However once you start needing to do anything more complex it will get painful. That's what history has taught us. Something as simple as a Login form is just easier to build and maintain with a front end framework, and importantly easier to provide a better experience!
Since after all the user's experience is more important than how much you like the code.
1
u/Y_Less Apr 30 '21
That's what the server is for.
1
u/jl2352 Apr 30 '21
For which bit of my comment?
2
u/Y_Less Apr 30 '21
For reusing code without copying it in to every page.
1
u/jl2352 Apr 30 '21
When I wrote ...
If you mean raw HTML & CSS ...
I meant using only HTML & CSS. i.e.
.htmlfiles. That’s why I said you’d need something.-6
Apr 30 '21
[removed] — view removed comment
14
Apr 30 '21 edited Apr 30 '21
They just don't understand why the frontend has to be so slow and so anti-user.
22
u/voidvector Apr 30 '21 edited Apr 30 '21
insanely bloated websites
Considering VSCode has like 50% IDE market share and game developers are putting embedded Chromiums in games so they put together UIs faster, I am going to conclude that "bloated" runtime is not important to most downstream users.
No one is going to waste time doing memory management for UI work as they would need for in say high-freq trading.
9
u/BornOnFeb2nd Apr 30 '21
I think they meant more bloated transfer size than memory footprint....if you're on a slow/metered plan, downloading multi-megabyte images that get resized with CSS to a microscopic thumbnail gets old, fast.
-5
u/valtism Apr 30 '21
What a tired take coming from a lack of understanding of modern web app development.
4
u/Zer0ji Apr 30 '21
Dude, I tried using React to redo a POC front-end, and ended up with 600 MB of modules on my disk and a built app that was nearly 1 MB, for something all text with maybe 500 lines of code...
I since then switched to Preact but it's still big.
4
u/StillNoNumb May 01 '21
You might not wanna use React for that then. React is for complex, usually dynamic webapps with many pages and functionalities - there's more appropriate libraries for your purpose.
In programming, it's always about knowing what tool solves your problem best. I don't go around and complain about Python either because I tried making a kernel with it and failed.
0
u/Zer0ji May 01 '21
It's for a board game, React allows me to define a Card component and reuse it everywhere - it's not a multi-page app, but it's still a complex one
A python kernel would be fun :p
1
2
u/arcanemachined May 01 '21
Try Svelte. The dependencies for a hello world app are 19.5 MB, and it's basically just gussied-up HTML and Javascript. Dead simple and easy to use.
It's not as mature as React but it has a pretty enthusiastic community.
1
u/valtism May 02 '21
Well react compressed is like 36kb, so I'm sorry that you managed to up your production build by 974kb in 500 lines of code.
1
u/Zer0ji May 02 '21
Well I guess I screwed up my build pretty bad... Thanks for the heads-up, I'll look into compression better.
-11
u/salbris Apr 30 '21
No it doesn't... The only reason website weren't quite as bloated as now was because these packages didn't exist. Bad developers will always exist. Tools simply make it easy to do everything (good or bad).
25
u/sellyme Apr 30 '21
You just said "No it doesn't" and then proceeded to explain why it does.
A good tool would make it hard to do bad things, like building an exclusively text-based website that manages to lag on a high-end computer. The modern JS ecosystem is full of terrible tools.
-1
u/salbris Apr 30 '21
There are plenty tools for evaluating performance. Just like how in other programming languages you can write bad code and refuse to use tools and end up with a slow program. They only difference is ignorance. That's not JavaScripts fault.
20
u/automata_theory Apr 30 '21
This seems like a disaster
Back to desktopland where things make sense
33
u/creepy_doll Apr 30 '21
Didn’t you hear? Desktop apps are now also being developed with this shit
33
u/Pwntheon Apr 30 '21
Am i out of touch? No, it's children who are wrong.
11
u/creepy_doll Apr 30 '21
See my other response to the other guy making the exact same comment as you. I’ve used the whole js stack and it’s fine for web shit but I’d prefer not to have the overhead in desktop apps
0
u/automata_theory Apr 30 '21
I am a scared old child who likes to make sim toys. I dont wanna go pls dont make me
25
u/creepy_doll Apr 30 '21
I worked with this stack and I’ve worked with “old school” js as well as mfc based windows programming, server side programming and whatnot.
Without doubt the new style gives more immediate power. But it comes at the cost of security and control, because with the constantly changing environment users don’t ever have a deep understanding of the libs they’re using or their massive dependency trees.
The idea that this is just old people being grouchy is appealing I understand but there is some truth to it. There is no perfect language and anyone that believes theirs is the best is just a fundamentalist language warrior. I’ll use the tool suited to the task, I used this whole stack for front end dev. But I would really prefer my desktop apps to be free of the craft and wanton waste of resources connected to them. I look at slack and then I look at mirc, software separates by 20 years. And sure slack gives many extra gimmicks, but the core functionality is the same at the cost of massive resource usage for what is mostly just text
6
5
5
u/LukeLC Apr 30 '21
Ok, this is a great article. Definitely should be helpful for people getting started with modern JS.
The thing I find irritating, though, is that we already had something that could do all this much more elegantly called PHP. No need for command line to do frontend stuff, no need for building projects to bundle modules, just an interface between your server and your client that works transparently.
And the reality is, PHP still dominates the modern web. I would welcome JS as a replacement if it was updated to natively work on the server, but what we have right now is a bunch of workarounds that have become an accepted standard. The amount of dependency hazards this has introduced is unsustainable and will someday likely cause a large swath of websites to suddenly break. In my (probably unpopular) opinion, Node.js is the new Flash.
9
Apr 30 '21
[removed] — view removed comment
16
Apr 30 '21
Don't focus on JavaScript. Focus on NPM. Build something people want and then hide something sketchy in there.
11
Apr 30 '21
[removed] — view removed comment
3
Apr 30 '21
Oh. Well then it would be useful to have a tool that attempts to find sketchy, intentional, obfuscation in NPM packages.
29
u/Caraes_Naur Apr 30 '21
JS is a lousy language, with an ecosystem to match.
12
u/jtinz Apr 30 '21
But TypeScript is a surprisingly good language once you have enabled strict mode and learned to avoid some pitfalls it inherited from JavaScript. It also maps cleanly to JS.
I love to use the language, but things around it like the different module and bundling systems ruin the the experience.
3
u/1newworldorder Apr 30 '21
What language doesnt have its drawbacks?
37
u/meltingdiamond Apr 30 '21
For a start: any language that doesn't make everything a float.
It is a horrible pain in the ass when a float goes wrong for any of the many reasons it can go wrong.
13
u/BackmarkerLife Apr 30 '21
I'm working with a (new to me) inventory system that outputs inventory into JSON and has inventory of products numbers as floats. I emailed them, "Am I ever going to have 0.25 of a specific product?" "No," they said. "Then why is this sent over as 17.0 instead of 17?" "I... can't answer that"
Can't get it changed on that vendor's end (because they refuse) and it breaks another vendor's end for their API because that cannot handle floats either. Christ the world has gone batshit with JS. The main vendor has a huge inferiority complex and as gatekeepers.
3
u/spacejack2114 Apr 30 '21
17 would not be encoded as 17.0 in JSON unless you rolled your own JSON serializer to do that on purpose.
-1
u/MjrK Apr 30 '21
I'm not sure that yours is a good example of what OP is saying... JS doesn't have the concept of "int" or "float"... there is just a "Number".
Your vendor's choice to send the values that way is probably just an artifact of your particular API with them... it might not relate to how JS works.
2
u/xigoi Apr 30 '21
there is just a "Number"
…which is a float.
1
u/MjrK Apr 30 '21
Correct, but my point was that JSON u/Backmakerlife's question...
"Then why is this sent over as 17.0 instead of 17?"
... is a situation that isn't possible in JSON. Unless there's something else funky going on in the API and they are transferring a String instead of a Number.
So while on the surface it relates to using floats when int should be used; it doesn't appear to have any relevance to the lack of integers in JS.
Further JSON doesn't even have a data type for an "integer"; so asking the vendor to send integer instead of float makes no sense - it isn't possible to send an integer in JSON.
1
2
16
u/CanIComeToYourParty Apr 30 '21
Why does this whataboutism appear every time you criticize JS or PHP? Nobody is claiming that all other languages have zero drawbacks.
0
u/1newworldorder Apr 30 '21
Mostly because i just hate complaining. Yeah i wish we had something better than both of those solid examples...
So why isnt anything being done about it? Well as far as PHP thank facebook and wordpress for that. Thats never going away.
Why dont we make something better? Because collectively and practically speaking theyre good enough at what they do and no one has the resources to do anything about it. Call them polished turds i suppose.
Im all about change and progression. So lets do it man!
10
u/TimeWarden17 Apr 30 '21
Rust, the moral language
0
2
4
Apr 30 '21
[removed] — view removed comment
19
u/Caraes_Naur Apr 30 '21
That's part of the ecosystem: everything is rushed, poorly considered, and DRY is treated as holy sacrament.
What do you expect from a language that was developed by an intern in 10 days then prematurely hurled into production 25 years ago?
7
u/redderper Apr 30 '21
And JavaScript is nothing like it was 25 years ago. It has been greatly improved year after year. There's const, let, arrow functions, async/await and even Typescript that makes it much more maintainable, readable, and less error prone. Of course there are still people who use rushed and hacky code, but that's not JS's fault, that's on the user. Modern JS gives you all the tools you need to write clean code. You're comment makes perfect sense 10 years ago, but not anymore
-1
u/xigoi Apr 30 '21
There's still no enums, pattern matching or
switchexpressions, for example.2
u/redderper Apr 30 '21
You can use typescript for that if you need it. What do you mean with switch expression? Just the regular switch case statement because JS has that
2
u/xigoi Apr 30 '21
I mean something like this (made-up syntax):
const correctPhrasing = switch (numberOfApples) { case 0: "no apples", case 1: "1 apple", default: `${numberOfApples} apples`, }1
u/ClittoryHinton Apr 30 '21
What? JS has been doing switch statements and regex for awhile now. And TS gives you options for enums.
4
-3
Apr 30 '21
There's const, let, arrow functions...
Wow, welcome in... 1970?
3
u/redderper Apr 30 '21
So what? Explain to me why JS is bad then
3
Apr 30 '21 edited Apr 30 '21
It's a weakly-typed and poorly designed language with lots of stupid quirks. It misses a lot of useful features and only started to catch up with much older languages a few years ago. It introduced nothing of value and has more issues than benefits. It was pointless to create the language. Netscape could have utilized an already established scripting language instead.
3
u/redderper Apr 30 '21
It's a weakly-typed and poorly designed language with lots of stupid quirks. It misses a lot of useful features and only started to catch up with much older languages a few years ago.
Again these things are either not true anymore or solved by using typescript.
It introduced nothing of value and has more issues than benefits. It was pointless to create the language.
Uhh, saying JS has no value and is pointless is like saying the internet as we know it today has no value and is pointless. It's just an ignorant statement. Whether you like it or not, almost every website is built with JS including Reddit
-1
Apr 30 '21
Again these things are either not true anymore or solved by using typescript.
All of those things are still true for JS and TS only partially solves them because it still needs to interact with the JS-cesspool.
Uhh, saying JS has no value and is pointless is like saying the internet as we know it today has no value and is pointless.
No, it doesn't because JS != internet. Netscape could have used python instead. JS as a tech just made the client-side dynamic. We can still interact with websites without JS: commenting, upvoting etc would all work. JS is what makes the web slow because browser vendors were too lazy to create a proper API to control components. We can also interact with many online services without using js by using apps. Yes, apps - they still work and are much more efficient than websites.
It's just an ignorant statement.
No, you're just an angry JS fanboy and can't accept that JS was and is a pointless language. The language itself introduced nothing. The dynamic behavior it introduced is just the cherry on top of the internet's cake and doesn't actually need JS to function.
Whether you like it or not, almost every website is built with JS including Reddit
I don't like that and reddit sucks, especially the new design.
→ More replies (0)
62
u/sylvanelite Apr 30 '21
It's worth noting that since this was written, javascript modules now exist in the browser, so you can write models kinda like in the article, without using the command line tools.
But annoyingly, there's some quirks. They syntax isn't the same as in the article. For example:
can be replaced with something like:
And if doing it the "dinosaur" way, instead of having javascript files like:
you can do something like: