News for hackers. Stuff that matters.
Re:JavaScript: The Modern Parts by tus88 on Saturday August 24, 2019 @03:07AM (#20785730)
What's the view that TypeScript is the modern Javascript?
Re:JavaScript: The Modern Parts by Figs on Saturday August 24, 2019 @04:50AM (#20786047)
Given how fashion-driven the web industry seems to be, my guess is that some new hotness will steal the stage from it in the next few years. I seem to recall seeing tons of posts about CoffeeScript maybe around 6~7 years ago, but it doesn't seem to be very popular any more...

Maybe TypeScript will turn out to have more staying power, but my current guess is that something will happen that makes another technology -- probably WebAssembly -- very popular in the next few years and that will kill off a lot of the hype around TypeScript. Then that will itself mostly get killed off by some other technology about 3~5 years after it hits peak popularity, and so on...

I could be completely wrong though, of course! Predicting the future is hard. This is just my guess based on handwavey recollection of the last decade and a half of web trends.

Re:JavaScript: The Modern Parts by quickthrower2 on Saturday August 24, 2019 @06:51AM (#20786445)
Typescript solves the biggest issue I have with using JS which is a lack of a static type system. It however does it in a very pragmatic way, giving the closest experience to Vanilla JS you could hope for. You are not learning a new language like you would be with Elm or Reason etc.

It has a powerful type inference system that puts C# to shame in places, and in some places I prefer TS to C#.

I don't feel like Typescript is 'hyped'. It is popular because it's damn good. As a programming language alone it could be seen as not too special, but when you see what it's trying to do, get JS developers to use types and not run a mile, then it does a brilliant job.

Re:JavaScript: The Modern Parts by siempreb on Saturday August 24, 2019 @08:46AM (#20786824)
> Typescript solves the biggest issue I have with using JS which is a lack of a static type system.

Hmm, the biggest problem with JS is types? Are you sure? I rarely had issues with types in JS. With JS I just used my trusty dynamic type checker at specific places in the codebase, and testing coverage of course even more importantly.

But with TS, the codebases I see on a daily base are mostly a terrible mess of wrong ideas, wrong libraries, wrong constructs, wrong design principles, tooling hell, etc, etc.. Which is IMHO the real issue with JS/TS. For some reason TS proponents seem to live in a world where 'TS solves everything'.

For me TS is just writing 20% more code and regularly needing to use the 'any' keyword to avoid spending hours on getting a basic line of code working. Everything I write non-professionally is not TS, I cannot think of 1 single reason to give myself that burden.

The best thing TS has given me is even more jobs. With Agile front-end developers spend at least 1 day a week in the meeting room, now with TS they spend 20% of their time left to hassling with types. It's hilarious. Especially all those managers that have no clue what's going on, why front-end development gets slower and slower.

Re:JavaScript: The Modern Parts by mariopal on Saturday August 24, 2019 @11:33AM (#20787705)
The biggest problem the parent comment have with JS is not types, as you say, but __a lack of a static type system__.

They are things as different as that you can actually have type problems only in a really typed system (as a static type system). Javascript has a very weak type system, and that's the problem. I think you do not understand that static typing serves to solve other problems in the code, not to solve type problems ... it would be like saying that an hypothetical language needs functions to solve function problems ... and then you say that you never had problems with functions in that hypothetical language (ex: assembler, with very primitives "functions", where you have to save data in register before jumping to code in another memory address).

Re:JavaScript: The Modern Parts by Zelphyr on Saturday August 24, 2019 @12:45PM (#20788161)
Having a static type system is great but it’s just another tool in the toolbox. I’ve been writing Javascript for 23 years without types and didn’t miss them. They’re great when I have them in other languages but not a deal killer in languages that I don’t.

But so many TypeScript fans act as if having types is the be-all and end-all.

And, unless I’m mistaken and something has changed recently, I often wonder how many of the TypeScript proponents don’t realize that they’re mostly only getting compile time type checking since the compiler strips away the types after TypeScript gets compiled down to Javascript.

Don’t get me wrong; TypeScript is great. But I don’t see it as the savior that others make it out to be.

Re:JavaScript: The Modern Parts by rgoulter on Saturday August 24, 2019 @01:02PM (#20788288)
"I often wonder how many of the TypeScript proponents don’t realize that they’re mostly only getting compile time type checking"

Surely the biggest benefit from static typing is for static-analysis tooling. (e.g. strong compile-time checks).

Re:JavaScript: The Modern Parts by Zelphyr on Saturday August 24, 2019 @01:48PM (#20788549)
I don’t disagree but the way people speak about static typing is as if it’s present during the life of the application.
Re:JavaScript: The Modern Parts by quickthrower2 on Sunday August 25, 2019 @06:32PM (#20796044)
Different languages have different types of behaviour under the "static typing" umbrella.

Typescript has chosen to interop nicely with JS, and they took the tradeoff that if you are passed an object (e.g. from an Ajax request) and you assert that it's a Duck, TS will assume that is correct during static typing. Of course this might be wrong at runtime, you may get returned {'foo':1} instead of {'foo':'bar'} and your object.foo.length now returns undefined.

Static typing in general (in other languages) does persist into the lifetime of the application. By persist, I mean the guarantees persist, even if the types are thrown away. Haskell for example throws away the types at runtime (you can't reflect on them) but because it's so strict, you can be sure that X: String->String does indeed return a string. This you cannot be 100% sure of in Typescript.

So why is Typescript useful? Well if you write an entire app in TS (which I am doing now) then all the code you write ... which is the new non-battle-tested code ... is now type checked against itself. Also well written libraries using TS will be well type checked against. People doing stuff like casting to <any> etc. could break things for you. But in general you get Pareto's rule applied and because most of your code is type checked (and it only isn't when getting stuff from the server or using a dodgy library that has exported an incorrect .d.ts or something), then you get almost 100% of the benefit.

Basically am I getting errors due to incorrect types at runtime in Haskell? Never. Am I getting them in Typescript? Not yet but it's possible, maybe 0.1% chance?

Re:JavaScript: The Modern Parts by rgoulter on Saturday August 24, 2019 @12:56PM (#20788230)
While it's fair to say that a static type system adds friction which isn't suitable for some development mindsets, I think it's worth expanding on problems people run into with types.

Bad types at runtime: with a static type system you make the effort to be sure the code does what it says. With plain ol' JS you can get that confidence from tests. -- different trade-offs made each way.

But another benefit to static types is knowing the structure of the data you're dealing with and how to manipulate it, while you're developing/maintaining the code. -- sure: naming, unit tests, documentation etc. can help, but I find not having the static types handy makes things tricky when there's enough indirection/complexity.

As with the stuff about runtime errors, tastes vary, of course.

Re:JavaScript: The Modern Parts by quickthrower2 on Sunday August 25, 2019 @07:46AM (#20792425)
Tell me more as I want to grok the dynamic typists viewpoint as I’m sure I’ll learn something. So are you doing type check assertions at runtime and throwing errors? Or are we talking about something else?

What I like most about static typing is tooling support for refactoring and how much easier it can be to change a name or significantly change internal apis and jig stuff around with confidence.

Re:JavaScript: The Modern Parts by ggregoire on Saturday August 24, 2019 @12:54PM (#20788221)
CoffeeScript never solved any issues tho. It was just syntactic sugar.
Re:JavaScript: The Modern Parts by pixelmonkey on Saturday August 24, 2019 @09:34AM (#20787041)
I'm the original author of this post. I'd say that it's very unlikely that TypeScript will supplant JavaScript. To quote Crockford in 2008:

"Because JavaScript is the language of the web browser, and because the web browser has become the dominant application delivery system, and because JavaScript isn't too bad, JavaScript has become the World's Most Popular Programming Language. Its popularity is growing. It is now being embedded in other applications and contexts. JavaScript has become important. It is better to be lucky than smart."

TypeScript is a very smart language, but then, so are Dart, CoffeeScript, ClojureScript. I suspect that if code durability is what matters to you, JS (and the ES evolutions thereof) will have the real staying power. Plus, not everyone is sold on the value of static types, but everyone is sold on the value of JavaScript.

Re:JavaScript: The Modern Parts by james_s_tayler on Saturday August 24, 2019 @10:04AM (#20787180)
I feel more sold on the ubiquity of JavaScript more than the value of it. I feel sold on the value of TypeScript.
Re:JavaScript: The Modern Parts by krapp on Saturday August 24, 2019 @09:50AM (#20787117)
The web (or specifically HTML) was originally intended to support multiple scripting languages (which is why the <script> tag had a type attribute, which is now deprecated in HTML5.) Unfortunately, things didn't work out that way.

I'm hoping that when WASM matures a bit more, and becomes as universally supported in browsers as a javascript runtime, JS just becomes the default language supported by it, not the only one possible. Maybe one day it'll be common to see Typescript run directly in the browser, who knows?

>but everyone is sold on the value of JavaScript.

Not everyone[0].

[0]https://news.ycombinator.com/item?id=11447851

Re:JavaScript: The Modern Parts by IggleSniggle on Saturday August 24, 2019 @03:47AM (#20785875)
TypeScript adoption has been swift and decisive. In 2019, the majority of js developers that take surveys use TypeScript.

Edit: Mea culpa. I got my numbers mixed up, or whatever source I thought I remembered just doesn’t exist. 46% in 2018 (state of js) says nothing about 2019, and is not a majority. That 46% is also backed up by a similar survey that npm ran. It’s worth adding though, I think, that js devs benefit from ts type inferencing and IDE support even if they aren’t using it directly

Re:JavaScript: The Modern Parts by trias on Saturday August 24, 2019 @06:51AM (#20786444)
> majority of js developers that take surveys

i like that qualification :)

most likely typescript is still a very small minority given how large the javascript world is

Re:JavaScript: The Modern Parts by growtofill on Saturday August 24, 2019 @03:59AM (#20785916)
Source on your claim? It was about 50% on last year’s State of JS: https://2018.stateofjs.com/javascript-flavors/overview/
Re:JavaScript: The Modern Parts by macando on Saturday August 24, 2019 @04:24AM (#20785988)
Have you read this article?

https://medium.com/javascript-scene/the-typescript-tax-132ff...

I use TypeScript. It's not all rosy.

Re:JavaScript: The Modern Parts by tengbretson on Saturday August 24, 2019 @06:26AM (#20786353)
There author of that article is speaking out of both sides of their mouth. How can they claim type safety has minimal value and simultaneously knock it for missing higher kinded types?
Re:JavaScript: The Modern Parts by RobertKerans on Saturday August 24, 2019 @04:57AM (#20786073)
I think a correction is needed here, it's "the majority of typescript developers that take surveys said they used typescript".

I'm being flippant, but Typescript is quite popular, that's it, most people who write JS write JS.

Re:JavaScript: The Modern Parts by IggleSniggle on Saturday August 24, 2019 @05:06AM (#20786103)
I agree. Correction added.
Re:JavaScript: The Modern Parts by leeoniya on Saturday August 24, 2019 @03:51AM (#20785895)
> In 2019, the majority of js developers that take surveys use TypeScript.

TS is quite popular, but this cannot possibly be representative of the general population of js devs, not even close.

it's more like ES6 >> JSX >> TS >> Flow.

Re:JavaScript: The Modern Parts by IggleSniggle on Saturday August 24, 2019 @05:03AM (#20786092)
46% was the survey number, so I definitely misremembered the facts. But your comparison here is inevitably necessary, since TS compiles to ES6/JSX, (as does Flow)
Re:JavaScript: The Modern Parts by leeoniya on Saturday August 24, 2019 @10:38AM (#20787352)
what was the survey sample size and how was the sample selected? (46% of 0.001% is still 0%).

my assessment isn't what things compile to but what they are authored in.

Re:JavaScript: The Modern Parts by IggleSniggle on Saturday August 24, 2019 @02:13PM (#20788711)
Good question. The state of js survey was self-selected, with 20.2k responses. The data is available if you’re interested. The npm survey, on the other hand, was sent to 800k registered npm users and received 33.4k responses, and also found 46% TypeScript usage. I imagine there is significant selection bias in a number of ways. And, while the state of js survey found 46% “have used ts and want to use it again”, the npm survey did not ask about preference. Still, a decent number of responses that I think is pretty interesting, regardless of your own preferences!
Re:JavaScript: The Modern Parts by mping on Saturday August 24, 2019 @04:03AM (#20785927)
I don't understand why jsx is in your comparison, although I agree with your assessment.

To be clear there are a gazillion Js projects that don't use react.

Re:JavaScript: The Modern Parts by leeoniya on Saturday August 24, 2019 @10:41AM (#20787368)
it's a bit anecdotal but React /JSX is still more common than TypeScript (if for no other reason than time on this earth). and both are dwarfed by ES5/6
Re:JavaScript: The Modern Parts by IggleSniggle on Saturday August 24, 2019 @02:15PM (#20788725)
We are writing our React components in TypeScript, so I’m not sure what React/JSX have to do with TypeScript adoption?
Re:JavaScript: The Modern Parts by blondin on Saturday August 24, 2019 @11:54AM (#20787847)
not sure Anders/microsoft wanted to replace javascript with typescript. the problem is this imo.

to use javascript -- or say python -- in an corporate/enterprise environment, you need to analyze your code base. static analysis is what worked well and still does but you need types. ofc having types has other major benefits but this is the big one for me at least.