310 points · by eropple · 9y ago · 161 comments
I'd say they've made JS development bearable, but great is really stretching it. We still don't have a type system, static analysis, multi-threading, first-class IDE support, or any of a myriad of other features that are standard in any modern programming language in 2017. I'm hopeful that projects like Blazor[0] and other efforts being made toward bringing real languages to the web via native WASM will put JS to rest once and for all.
Let me try to address these.
Regarding type system, lot of great languages don't have type systems either. But if there's lot of discussion on type systems, it would be because of Flow vs TypeScript.
As for static analysis, JS has seen evolution of JSHint, JSLint, JSCS, ESLint, and finally, Prettier. Flow is capable of performing type-checks with dynamic analysis.
I am not sure multi-threading is the hallmark of a modern language. Because Go, Elixir etc. are providing great concurrency without exposing threading API to the developer. JavaScript lets you do asynchronous tasks via callback, promises, generators, and latest - async/await. In the browser, you can use web-worker. But in most cases, you won't need it.
JS ecosystem has great code editors. I find VSCode to have good support out of the box, with breakpoint debugging. You can also use Atom, or Sublime Text, or Webstorm. If you're missing certain functionality, you can always add open-source plugins.
I'm with you on most of your points, but IDE support is still quite crude compared to (say) Java or Kotlin. Once you're fluent with these in a Jetbrains IDE it feels like you're directly manipulating an AST (or something near it) rather than 'editing text'. Javascript (even with Typescript in IDEA/Webstorm) isn't close to this yet.
That's simply not true for JS.
ATM Angular 4 w/Typescript in VS Code is in my top 5 favourite language/dev environment combinations.
It has working code completion and is fast. It lacks refactoring and doesn't help me with debugging though.
(Java with any of the three big IDEs occupies three spots but I haven't made up my mind about exact order except first place. Also these are my favourites - they are not necessarily everyone elses favourites.)
Overall, I think JavaScript has a very rich ecosystem because, if you do Web programming, you do not really have alternatives to JavaScript. So the community made the language support various programming styles, tools and libraries.
I do not believe WASM will help bringing more language to the Web than today because it is already possible to compile to JavaScript with good enough performances for most use cases.
Agree, but we have TypeScript, also static analysis is done for ES6 module dependency
> multi-threading
This is wrong. JS has service workers, and sharred array buffers.
Do you mean Web Workers? https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers...
Service Workers are not really threads as the runtime environment is still single threaded no matter what, you just have the ability to spawn a new process. On top of that browser support is sketchy at best, with no planned support for Safari or IE.
We pack = Webpack?
When we hear about frameworks and build tools we think http://m.imgur.com/gallery/2dykF3D
If you're going to be writing a lot of CSS, then using SASS might save you some time and improve readability. If you're writing a webapp, then a SPA or React app might be the best course. And if it's image heavy, then a tool to automatically compress images would likely make sense.
If this is too complicated to manage, then other tools like task runners or Webpack can help automate the process. Node packaging can be used to sync settings across all project owners.
Taken on their own, it seems like a lot of complexity. But if you're only adding tools when you need them, it's really not that bad.
I wrote my last site in Jekyll + SASS. No Webpack, no gulp, no React. I just didn't need them, so I avoided the complication.
I'm glad they're there if I decide I want them, though.
Some people would consider it a bad thing that eg. Backbone hasnt had a major version in years but it is still perfectly capable for many use cases and it performs well. Of course you have to have more experience and knowledge with JS and frontend development in general to get these results I think.
Of course, you may still want to tweak configuration, and then you have to "eject", which means that all configuration files are dumped in your directory for you to edit, and you basically don't use create_react_app anymore. You now have to get webpack and babel configuration right to make your changes, but you have a solid basis.
Nowadays, I try to never eject, and see create_react_app as a lib providing everything I need. It sometimes prevents me to try new staged js features, but on the other hand I often have new features on update that I didn't bother enough about to eject in previous version.
Such wrappers around build system are probably the way to go. I would love to see something like create_react_app but allowing to provide buildpacks, so we can find in the wild the perfect configuration for our taste.
They have an excellent, super-comprehensive README that covers practically everything you'd ever need to know about state-of-the-art Frontend JS tooling: https://github.com/facebookincubator/create-react-app/blob/m...
create-react-app itself is great for quick prototyping, but for non-trivial apps, chances are, eventually some esoteric production concern will force you to "eject". At that point, the sheer volume of configuration you'll be left with will be rather overwhelming if you've never dealt with the underlying technologies before, and modifying/extending it can become rather intimidating.
My recommendation is to start your first few projects with create-react-app, to get a feel for what a modern JS dev experience feels like, and then once you find the need to eject, instead of actually ejecting, copy your code over to a new project starting with just a bare minimum Webpack + Babel config, like the one in react-hot-loader-minimal-boilerplate (https://github.com/wkwiatek/react-hot-loader-minimal-boilerp...) and refer to the ejected configs of the create-react-app version of your app and the create-react-app README to port over pieces of tooling that you feel are sorely missing from your create-react-app days, one by one. This way, you'll be left with a much simpler and leaner tooling pipeline that you fully understand and one that you'll be able to extend and maintain much more easily.
I usually refer to the react-hot-loader-minimal-boilerplate config as a baseline simply because I consider es-next transpilation and hot-reloading essential parts of the modern Frontend dev experience. If you don't, you can totally start with something even more barebones.
I still have no clue about frontend web frameworks yet.
Live / Hot reloading might take some setup though.
One thing I am yet to see implemented, is tail-recursion. It's in the spec, but I am yet to find an environment that implements it. Please correct me if I'm wrong.
I too, am learning JS in 2017, and I can't wait to go back (to cljs). Or away, to anything else. I had done some basic stuff before, but for the last days I have been writing some code for a larger SPA.
Just as an example, today I needed to do the simple task of iterating over a dictionary. I expected it to go roughly like this:
dictionary.forEach(this.someMethod);
Instead, this is apparently what passes for sane in JS world, in 2017: for (var key in dictionary) {
if (dictionary.hasOwnProperty(key) {
this.someMethod(key, dictionary[key]);
}
} Object.entries(dict).forEach(fn)
Or _.entries(dict).forEach(fn)Of course, once you're writing typed JavaScript, you're no longer writing JavaScript.
Maybe you should consider that just because a language doesn't work like what you're used to, it doesn't mean it's a bad language. Because saying nowadays that javascript is not worth learning sounds pretty absurd. Sure, you can live without it. But that's probably the most useful language to know as a "second language", for all its various applications and because when you want to add scripting in your tool, you know javascript is a solid choice for its penetration rate.
sql = client.read()
res = remote_db.query(sql)
client.write(res),
still writing tons of boilerplates and spaghetti instead. We drown in happy ignorants, and they can't stop doing this to us, because they're happy with penetration rates, not technologies.The fact that the big web scripting monopoly influences other scripting and embedding markets is self-explanatory.
As for 'second' language, I'm pretty sure I'm not happy to do main work with a 'second' language, because it is second only after top 3-5 that I use on daily basis.
This was my first experience with modern JavaScript frameworks and TypeScript. I wanted to do it right, so worked closely with team members who were more versed in this stuff, and followed the various recommended best practices.
By the time all was said and done the PR for this thing had 27 files in it.
For a modal.
This seems ludicrous to me. The frustration, somewhat humorous, expresses by TFA is completely understandable, though. While I came to appreciate TS, I'm still skeptical about this JS framework stuff. They seem overly complicated to me. (While I have only read casually about React, it seems similar in this regard.)
I experienced the same thing when learning angular, flux and redux. It all screamed "overengineering" to me. But then I realized why it was that way, and why it had to be : you now have teams of like 50 js developers working on the same codebase. They have to have very strict and complex architecture, because their frontend codebase is just as big, if not more, than their backend codebase.
Those tools still lack alternatives for small to middle sized teams and products, IMO. React by itself is super cool to be quickly productive in that scope, but state management systems are not. For that reason, I made my own flux library, meant to keep things conceptually simple. The flux pattern by itself (data always propagating in a single direction) is not complicated, its implementations are. I would recommend that small teams working on small products take time to get the flux idea, then make their own implementation, it's worth it.
EDIT : to be more specific, here is a simple thing to do to make your own implementation:
1. build something (let's call it a store) with a `subscribe(func)` method allowing to be notified when data changed
2. add a public api to that store (`like store.addArticle(article_data)`)
3. in the `componentDidMount()` method of your root component, subscribe to store with a function that calls `setState()` on your component, then pass data as props to child components
4. when triggering an action, like clicking a button, call a method from the public api of your store
5. you now have a state manager ensuring data always flows in the same direction, and you can make your store implementation as simple or as complex as you want
Personally, I'd find it very hard to be motivated to work on a project like that. It sucks all the fun out of coding when things that should be simple aren't simple, it's draining for the whole team and it creates a lot of friction in adding new features.
So I guess that, to the question "How could the 27 file commit example comment not be a clear case of overengineering though?", the answer would be : "when there are 100 modals in your codebase and various devs work on various parts of those modals". Not saying that's a place I want to work either, obviously :)
In desktop world, we were using this sort of software architecture decades ago. It's only a combination of modular design, separating state from presentation, and an observer, and these are all well-established principles that have stood the test of time. Countless developers have written something like this at the start of countless new projects, and they probably did it in five minutes without a second thought.
The difference In modern JS world is that some people talk as if you need 197 dependencies, a whole build process and a team of 5 just to maintain it. You really don't, and the frameworks and build systems that push in that direction make my head hurt.
A good set of components for your library of choice should make a modal dialog that works and has flexibility e.g. https://bootstrap-vue.js.org/docs/components/modal/
That said, a modal dialog can be very hard to implement, depending upon needs (centering in viewport, mobile devices, stacking multiple modals, form modals with popup controls above them, preventing tab key allowing focus to go to form behind, plus many other hard issues!)
> By the time all was said and done the PR for this thing had 27 files in it.
Can you not just use a library for this and do it in a few lines...? I found Angular 2 verbose but I don't see how the above is common. I just did something similar in Vue today and it was about 4 lines to load the library and call it. You shouldn't be implementing modals yourself if you can avoid it.
Just starting fresh, what is a modal? It's a widget (we could use a div) which when activated is moved to the front of the z axis and steals focus. CSS can do that. Now all you need it do is keep attributes regarding the text of the modal and state representing whether it's activated (we can juse a regular JS object for both), and you've got a working modal.
Some of the frameworks are needlessly complex, which is frustrating, because it's hiding something very basic.
It's surely not one line of code!
https://stackoverflow.com/questions/25920941/how-do-i-overla...
Didn't say not to use a framework. Use it and some CSS and that's a basic task, not to mention there are other libraries which do it for you already.
Why?
UI is hard dude. UI on the web is especially hard because the technology has been growing progressively for over two decades.
I've seen devs complain about how coupled some small jQuery one-liner is and then replace it with some muli-hundred line monstrosity of a module that's buggy, incredibly hard to understand and impossible to actually reuse...then when you call them out on it, they just say "fuck you, we're writing ES6 now".
The code they replaced was simple, just worked and didn't have side-effects. And they're still using jQuery elsewhere in their project anyway...
Probably because it's one line in Vanilla.js:
confirm("Message")* With the vanilla solution, the user can check a box that says 'Prevent this page from creating additional dialogs' (which can break the site). With a non-vanilla solution, the user cannot check that box
* The vanilla solution can't be themed in tune with the rest of the site or webapp
* The only options you have are 'OK' and 'Cancel' - you may wish to have other buttons/labels for your modal. Never mind if you want three buttons, or a list or the like
It's been a solved (and re-solved) problem for decades.
- clients that range from tiny phone screens to full desktop screens
- incompatibility when it comes to what features clients support, and even how they support it
- a foundation not meant for UI's that is pretty much required to be abstracted away leakily (HTML, browsers)
- serious limitations in payload file size for the entire UI codebase
- much of the UI depending on asynchronous operations. The only 'UI' that I can think of that is similar is when I SSH into my server. All other user interfaces are mostly 'local'.
- backend systems that are not optimized for these kinds of things
I am a relatively 'young' programmer, so maybe I'm utterly wrong about thinking that, considering the above, we're in kind of uncharted territory. By all means correct me!
All that said, I do get the feeling 'we' in the javascript world reinvent the wheel more than necessary. But perhaps that's because none of the historical solutions are 'complete' enough to get enough mindshare in the way that, say, Ruby On Rails was, or jQuery.
Also, personally I'm becoming more convinced that until all this stabilized, many of use (or at least I personally) might benefit from just not aiming that high when it comes to UI. If I'm honest with myself, an 'old-fashioned' backend that produces HTML with perhaps a few dynamically loaded components (as just HTML fragments, even) is perfectly fine and I truly doubt it would have a negative impact.
(hey carsongross, this is where you bring up intercooler.js!)
However, this only covers a small part of front-end development with VDOM based approach, and a few ES6 constructs (destructuring, arrow functions, let-const).
The author misses out on mobile development, Node JS and NPM modules, server side, and Electron-based desktop apps.
It's a good thing to take the positive approach, and get introduced to some interesting, low-barrier-to-entry items. At the same time, it would be prudent to keep in mind what lies ahead.
They are likely to be fairly happy with their existing approaches to desktop and server development and want to learn to use javascript where it is currently unavoidable.
There are a lot of skeptics about modern JS frameworks, and I get it (my inclination in every programming environment I've ever worked in is to avoid frameworks, etc. until I know I need them), but boy is this a big, and awesome, change.
That's a lot of what this backlash against JS is. Some of the criticism is warranted, but a lot of it isn't, it comes from people who have never done anything other than sneer at the language, and for every issue JS has, you can find a matching issue in another language that either a) isn't a problem because there are idiomatic solutions or b) everyone in the choir knows it's dumb but they don't say it to outsiders, because why advertise your weaknesses?
JS today is very expressive (more expressive than Python simply due to good lambdas - not to pick on Python but it's a language that doesn't get the hate of a JS or Go), it's been fast for awhile, it's got a dozen new interesting frameworks, the tooling keeps getting better, etc. This can either scare you or represent opportunity.
We've got a 5k line JS app. It was written by people who weren't programmers, in a jQuery/d3 ball (it was still an impressive interface). Over the summer we've converted it to Mithril and modern JS, now it's half the size, our dev environment is setup with a simple npm install and npm start, we have reusable components that multiple people can grok and use, it only takes a 20 line webpack file to do this all, and before the summer started none of us had used the framework.
It's amazing what it has enabled us to do and how simple the whole stack is. I've been building desktop apps and small intranet web apps for a decade, they don't hold a candle to what's possible if you harness this stuff. People can complain all they want but this is what progress looks like. Someone might not think it's cool that you can write an interactive single page application in 50 lines of code that anyone in the world can access, but isn't that what we wanted?
It takes a day to grok this stuff, a week to build interesting stuff in it. It's worth the investment, you might actually learn to do things you couldn't before. That's fun.
I think a lot of the "sneering" is less about fear of "new" things and more about frustration that old ideas that they previously considered are now being presented as "new" by a generation of people who either did not see themselves or did not ask an oldster about the old ways.
The tell for me, is in what things get the most sneered at. Node and npm tend to get a lot of sneering, because they're essentially attempts at solving problems people had already solved before. People don't sneer as much at other things like React (except for its license and large number of dependencies, and the latter is really npm/language sneering).
The part where you say a lot of people are terrified of heir skillset becoming obsolete -- I'm not sure I see that in web developers. Everybody I talk to is happy that their knowledge is now obsolete of which array methods don't work in IE8, for example.
Possibly a lot of the backlash against JS comes from conversations that go like the "How it feels to learn JavaScript in 2016" essay rather than like the one posted here.
What I'm not so welcoming of is, for example, the Angular 1.x -> Angular 2, 4, whatever transition. I don't want to have to keep thrashing my projects due to incompatible upgrades.
And I'm tired of the hype cycles. Not so very long ago everyone and their dog was banging on about how React was the next big thing, and now a lot of them are running scared over the patents issue. It seems like almost overnight all I read about now is Vue.js, but I know that in another few months, or maybe a year, everyone will have moved on again.
Fundamentally there's just no incentive to invest, especially not if you have other things you also need to focus on in your work and life.
So yeah, they're programmers now, but they didn't start out that way and the app showed it. That's what JS and the browser allowed them to do.
Is nobody even slightly wondering how OOP has infiltrated modern JS development?
Old school Java web development has fully seeped into Javascript with JSX replacing JSP, OOP everywhere.. It looks exactly like the bells and whistles of early 2000 web development.
I would like you to give an example of this. We use the class-syntax, yes, but inheritance usually never goes beyond one level of parent-class-child-class relationship.
If anything, the JS community at large hates OOP the traditional way, and somewhat open to the prototypical pattern.
The ecosystem actually prefers functional constructs. At the very least, an attempt to write pure functions.
The process looks quite complicated where you have to figure out lots of "buts," "whys," and "gotchas," while keep telling yourself, "What the hell?" all the time.
[1]https://hackernoon.com/how-it-feels-to-learn-javascript-in-2...
Here here.
Even with an SPA - assuming you use a framework that doesn't force you through a build pipeline.
Even if the build setup is the most complex thing on the face of the earth, if you or team members get reported for undermining the team because you don't understand it, then those are not the team members or managers you want to work with or for.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
It's amazing how recently some things arrive and how late competitors skip some elements.
Nice to see that people who dropped JavaScript a while get to find that things are actually better today than they were.
Rollupjs also has "treeshaking", meaning your transpiled bundle only includes the functions that are referenced allowing you to organize your code into large modules or even use a monorepo.
But of course as JS spreads I am looking, reading and mostly just shaking my head. But man, Svelte makes sense. For the first time in about 15 years, a JS framework makes sense.
app.on("new_private_msg", updateMsgBadge);
app.on("new_chat_msg", updateMsgBadge);
function updateMsgBadge() {
this.badge.newMessages =
PRIVATE_MSG.reduce(msg => msg.unread)
+ CHAT_MSG.reduce(msg => msg.unread);
}
Parts of the app can be abstracted into micro-services. For example the signup can be it's own micro-service.
Or using the plugin pattern each widget can be independent/untangled. let planets;
let planetFilter = planet => true;
The planets variable is static in this example, but planetFilter changes. The "Voila, it works" link near the bottom of the essay leads to a live demo: https://brlewis.github.io/2017/planets.htmlWas there a particular aspect of state management you want to hear more about? I'm thinking of a follow-on post. Not sure whether the next one should be state or build system.
m('div, {style: `display: ${status ? 'block' : 'none'}`)
Mithril's diffing engine does the rest. If status changes it knows to rerender that section.I'm doing mobile projects at the moment, and it feels like going back 10 years.