JavaScript! Why?
Better composability
Faster development
Type Safety Bugs
I spend about 1% of my time dealing with types and type re...
For further actions, you may consider blocking this person and/or reporting abuse
While TypeScript fans are blasting him for it, it says something that Ryan Dahl (creator of Node.js and Deno) went from TS to JS for Deno's internals.
I have warned about every reason he gave for the switch for years, and then some.
*Edited out "fanboys," because there are plenty of valid reasons to consider TS and there were some well-reasoned arguments against his complaints; however, those were few compared to "Jeez, this guy" (again, creator of Node and Deno) "is an idiot! How doesn't he see that treating JS like C# is so much better!"
That's really interesting. Do you have links to any of that information? I would love to read what his reasons were.
startfunction.com/deno-will-stop-u...
Wow, thanks.
You're welcome. It was quite vindicating to learn that someone who has made my career so much better with his creations has some of the same concerns about TS that I do.
Most of my other beefs with TS stem from what it's doing to JS devs:
and giving a false sense of security in:
@param
s (you can even exploit tscheck in VS Code to check them as you write)Finally, on the hiring end, because:
Oh, and a comment about most annoying language replying to a post asking about hardest language - the commenter chose Java as most annoying for the same main reason I dislike Java, and yet another beef I have with TS:
Verbosity is really key.
Of course, if you follow the rainbow to the end, you'll notice the disclaimer at the top of the Design Doc that the Deno decision was discussed around.
Design Doc: Use JavaScript instead of TypeScript for internal Deno Code
tl;dr: Context is everything and know your use case. I'm still a TS newb, but I've already run into instances where TS removed burden by increasing transparency and simplifying apparent complexity in a manner similar to Artur's(@dotintegral) comment.
Yes, and still, not being a TS noob, I've run into the same issues for years.
FWIW the complexity issue is something many experienced JS devs likely complained about back in the early-mid part of the last decade when so many got caught up in the "object oriented JavaScript" craze (because it wasn't already? 🙃) that Kyle Simpson touched on in the first edition of You Don't Know JS, and the related "MVC EVERY CODEBASE PURELY FOR THE SAKE OF MVC 🙃" craze.
What a lot of us witnessed back then was a bunch of resulting code that was, somehow, even less readable and maintainable than it was in its previous spaghetti form (which we had probably already warned was spaghetti, but new hotness won out over common sense as the solution).
Right. Other than a clear model for componentization, it's hard to think of anything libraries offered that I wasn't already doing in one form or another. JSX/Hyper-HTML has also been quite revolutionary in it's own right, but on the other hand, that does come at a cost. I do like that the React community brought an awareness of classic CS concepts like immutability, side-effects, memoization, etc.
I could be very wrong here, but... I think the industry will dramatically shift back away from mega-frameworks and build-systems this decade, mostly due to new browser capabilities like Web Components and Modular JavaScript. I can't wait, it's going to be clean again for a while.
I actually don't have a problem with React - now Redux's obsession with pure functions to the point that you need either band-aidy (Thunk) or even more super-duper-boilerplatey (Saga) middleware just for async is a different story - in fact, it's my favorite library (actually React Native on mobile web and desktop, it's amazing what you can do with a single codebase without relying on a WebView these days).
I actually dug pretty deeply into HyperHTML (and other smaller libraries like Riot, and strictly relying on modern vanilla JS) before giving React a serious, unbiased chance, but I kept running into wheels that needed to be reinvented.
I haven't experienced many tradeoffs with JSX, especially now that there's hardly any reason for me to worry about repeating class/lifecycle methods (or using classes at all) ever again.
The thing that keeps me from web components is the same thing I ask any time I hear about use of just about any web framework/library: What's your mobile strategy? I don't like fragmenting teams to build what is often the same exact app in multiple codebases, if it's not absolutely necessary.
I feel the opposite. Recently I was working on a big project with advanced FP patterns. We composed and composed a huge amount of functions that were processing our monads. Sometimes, despite trying to keep everything simple, it's easy to get lost in big functions compositions. Especially when you enter a file for the first time and just want to make a small change, but you're unsure what's the structure at given point. Then comes TS and helps you with understanding quickly what's going on.
Though TS is not perfect and will not reduce run-time bugs (that's why we used monads) it can be helpful and improve your dev experience. The problem with TS is that you need to understand it's strong and weak parts to use it efficiently. It's the exact same thing as with JavaScript - it gives you a huge amount of tools, but it doesn't mean you should be using all of them. TS can bring you value, but you need to have a bit experience. Perhaps that is why a lot people are saying TS is crap. Because they haven't got to learn the good and bad parts and quit in the middle.
In TS, I don't really care about the types themselves. They are just a first step for what it brings. It helps you understand what are the structure of the objects and what are the arguments and return values of your functions. This is where it is most effective. For example, when working with pretty nested object - like the responses you get from hedless CMSes like Contentful - it's really easy to make a type-o or to refer to
object.name
insteadobject.title
This is where TS comes and makes your experience much more bearable.In addition to that, if configured properly (that is with strict mode on) it can warn you that when calling
object.something()
your object can be nullish. Though (as mentioned before) it does not completely eliminate run time errors, allows to reduce a bigger part of them.It can be tedious, it can be annoying, but also it can help you a lot.
Finally someone with a Typescript preference! :) good points. It would be surprising if Object Composition itself was responsible for getting people lost, are you certain it wasn't an organizational issue?
Well, when you have 50+ contentful models with references to other models then yeah... From the data modeling point, the model makes sense. So I would argue that no, it was not an organisational issue. And honestly, if I have big project that I need to work on, I don't really want to spend precious brain power to memorize all of the models. I let TS hint me with fields ;-)
Make sense. TS hinting is pretty great. Hinting tends to drive me nuts, but it is really useful in a larger/unfamiliar codebases. VS Code has some level of hinting for regular JavaScript. I find that I am still able to traverse the model to a satisfying degree (see image).
JS Hinting is great, but it can only go as far as to the code/objects that you explicitly define. There is no way (unless I missed something) for VS Code to predict the structure of data incoming from API. With TS, you can just state that you expect data of this structure and hinting will work correctly. Granted, there is still possibility that you made mistake in typing the response, or the response changes after some time, but the same problems would occur in normal JS.
Yeah, you make a good point. I hope I'm not coming across as saying other people are doing it wrong. What I'm trying to do give an opinion on why an alternative that's well worth the trade off.
FWIW, the second edition is in the works right now. It's now titled "You Don't Know JS Yet," and Simpson does promise to go into more detail and cover more than before (he's even going to cover ES6 classes with an honest effort on how-to vs personal opinion, despite personally being opposed to them).
I do remember those books teaching... closures, lexical scope, prototypes, the module pattern, and classes, but I think you're right, I don't remember them talking about using object composition in place of OOP.
Thanks Ankush. The books mentioned in the bottom of the post will teach you some of the internals that make these patterns possible, as well as showing you some of the patterns. Another place that has information on this are the ui.dev courses: ui.dev/javascript-inheritance-vs-c...
We've all heard the Kyle Simpson quote (usually parroted without understanding) that "ES6 classes are syntactic sugar."
I've long taken it further than that. ES6 classes are a CONCESSION on the part of the ECMAScript committee to (TypeScript and) developers coming from class-based OOP languages who couldn't be bothered to properly understand the what and why of a prototype-based (also OOP) language.
That's interesting. When I wanted to learn OOP back in 2007, I started learning JavaScript Prototypal Inheritance. I didn't understand a thing I was reading. I had to switch over to Java to learn OOP, which was much clearer. Then once JavaScript Prototypes began to make sense to me, I started to realize that I was not really learning OOP in the traditional sense; JavaScript's composition model was meant to be different, but people were not getting it.
Prototypes are awesome, and I used them for a long time before discovering cleaner alternatives. I was giving a presentation on Web Audio at the Wakanday Conference in Boston, in 2013, where Douglas Crockford, the inventor of JSON, introduced the audience to the power of JavaScript Closures. That was the end of OOP for me.
If I remember correctly, this is the video of Douglas Crockford's talk here: youtube.com/watch?v=gz7KL7ZirZc
I resonate with this. If it ain't broken, why bring in an entire language to fix it? TypeScript makes the problem of types in JavaScript bigger than it is. Also, thanks for the link to Eric Elliot's article; good reads all around.
Thanks. That makes sense. In my experience, it has been mainly junior engineers making a big deal about types. I get it. It's hard to understand the quirks without enough experience using JavaScript. But I don't think that makes typed languages easier. Perhaps it's a matter of taste for the most part, but I would guess if those junior engineers really learned modern JavaScript, they'd question whether they really wanted to pay the TypeScript tax. Building an identical project in both would be a great lesson in trade-offs.
I like your demo of compo-sable JavaScript objects but....
No upgrade in any language (including JavaScript) should be done with reading the breaking changes section.
No upgrade in any language (including JavaScript) should be done with reading the breaking changes section.
Both these arguments are User errors.
Yes, I do agree in principle. But it's not always that simple: github.com/Microsoft/TypeScript/is...
It's not that the language would break something, though it may, it's more that different parts of the ecosystem surrounding the language will shift at different rates. Some people will follow SemVer some people will not.
The number of modules and packages being installed in today's projects is astronomical. It's a lot of work to keep everything in sync. I would love to get real stastistics on time-cost of library incompatibilities for the Node.js universe.
Great stuff @Alistair! I wonder, are there some examples where we can take your Counter function and add some additional functions inside of it via a mixin
Here is one possibility... though I had to cheat by adding the
set count(value)
setter. There may be a better way, but even if there is, I would use the longer form of extensible composition as it's easier to manipulate after the fact because the scope is passed on through state. But this method does demonstrate a private variable within the lexical scope of Counter.Exactly what the doctor ordered! I love it, I feel this avoids the pitfalls and complexities of class-based inheritance
Here you go Adrian-Samuel, this is how to extend the counter with mixins, without having to update the original object...
This is superb! Alistair, really appreciate you taking the time and effort to demonstrate these very useful examples to me!
Care to expand on your methodology with some examples? Do you work with a team? Are you writing JS for web apps? sites? node?
Good call. Added something very simple to give the basic idea.