News for hackers. Stuff that matters.
Re:Strong typing, a hill I'm willing to die on by halfmatthalfcat on Wednesday October 04, 2023 @09:28AM (#37764813)
I've worked with my fair share of vanilla JS devs who refuse to acknowledge the benefit of more statically typed variants of the language. Most of them bemoan the upfront cost of typing everything without realizing the benefits of it. I absolutely think less of them as developers.
Re:Strong typing, a hill I'm willing to die on by giraffe_lady on Wednesday October 04, 2023 @09:51AM (#37765169)
Not liking typescript is not the same thing as denying that types are valuable.

TS has a very complex type system in exchange for relatively weak guarantees about correctness. That's a tradeoff you can choose to take or leave depending on the problem at hand, and holding that position is not the same as believing types have no value.

Unless you're talking about elm or rescript or something then sure sure. But usually when people say things like this they mean typescript.

Re:Strong typing, a hill I'm willing to die on by smallerfish on Wednesday October 04, 2023 @10:22AM (#37765642)
Typescript's typing system is great and (for me) makes frontend development tolerable. It's annoying that it's optional. tsconfig and the related ecosystem is a disaster.

I still have hopes that Kotlinjs can fix the distribution size and the tooling around binding to js libraries.

Re:Strong typing, a hill I'm willing to die on by rafaelmn on Wednesday October 04, 2023 @10:19AM (#37765595)
Typescript can be very complex - it can also be incredibly simple - it's up to you how far you want to take it.

Sure it can be an adventure to express something fully in it - but this is true for any type system I've seen.

And I haven't seen another type system that's integrated into a dynamic ecosystem as well (IMO python is 5 years behind in terms of type checking experience) and that lets you chose the level of type sophistication that makes sense.

Static typing, code analysis, automated testing, etc. are all great tools that become counterproductive past a certain point. Where that point is highly depends on what you're doing and typescript is one of the most flexible type systems at letting you make that choice. I'd say a lot of people are terrible at recognizing when they went too far with it for no practical gain.

My only problem with it is that they can't fix the shit JS semantics.

Re:Strong typing, a hill I'm willing to die on by giraffe_lady on Wednesday October 04, 2023 @10:31AM (#37765762)
I am professionally familiar with typescript and explicitly not making a concrete argument for or against it right now.

I'm just pointing out that having an opinion about typescript is not the same thing as having an opinion about types. Something I think people are (intentionally?) conflating in these comments.

Re:Strong typing, a hill I'm willing to die on by rmilejczz on Wednesday October 04, 2023 @10:44AM (#37765919)
I think it’s just a path a lot of developers have traveled, starting with JavaScript and moving to TypeScript. If you’ve gone through that pipeline than you probably feel very strongly about the benefits that TypeScript provides and it’s the fulcrum for your opinion on static vs dynamic typing

Too many web developers, basically, I don’t think the conflation is intentional

Re:Strong typing, a hill I'm willing to die on by PH95VuimJjqBqy on Wednesday October 04, 2023 @03:25PM (#37770304)
I think you have to give typescript a bit of a pass in terms of types. MS had unique constraints when designing it originally, so it's never going to meet the expectations of more hardcore "typists", but I think they've done a great job given the unique challenges. Not perfect for sure, but it's one of the few newer technologies where I think it's a clear win.
Re:Strong typing, a hill I'm willing to die on by junon on Wednesday October 04, 2023 @09:58AM (#37765282)
This is pretty much my take, too. I don't hate the idea of TS, but TS is so painful to work with, and it's owned by a company I really don't like, too.
Re:Strong typing, a hill I'm willing to die on by dmix on Wednesday October 04, 2023 @10:07AM (#37765406)
OP is saying it's provides weak guarantees which is a result of the fact they made it easy to adopt and implement among legacy untyped code. It's the opposite of painful to work with for typing systems, compared to something like Rust which has stronger guaruntees and more predictable patterns but hard requirements the full stack is type. The result in TS is plenty of "any"s everywhere and in legacy code some situations where it's mostly just a thing veneer of type safety.

But all of that makes plenty of sense because in the early days it was rare to work on a real life production JS project that was pure TS from day one in addition to having TS only libraries.

These days it's everywhere and the work has been done to move away from rampant anys in popular libraries. The tooling is also mature and it's rare to find major JS libraries not already packaged with types or a @types import. Turbo moving away from TS was the rare exception.

Re:Strong typing, a hill I'm willing to die on by arp242 on Wednesday October 04, 2023 @10:27AM (#37765713)
> The tooling is also mature these days

Well:

  % cat a.ts
  console.log('Hello, world!')

  % time tsc a.ts
  tsc a.ts  2.39s user 0.10s system 232% cpu 1.066 total
2.4 seconds to compile a "hello, world" is orders of magnitudes slower than any other compiler or interpreter that I know of. It's a ridiculous start-up time.

esbuild is not an alternative as it doesn't check types.

What I want is "GET /foo.js" to "just" compile TS "on the fly" in dev; it's a simple "just works" kind of setup, but not possible with TS.

Or for a simple system, just "roll your own":

  for f in *.ts; tsc $f >|$f:r.js

  watch-files *.js --run tsc

  (for f in *.ts; tsc $f) | minify >production.js
Doesn't need to be shell, can be a simple JS script or whatever. You really shouldn't need millions of lines to call a compiler even in simple scenarios.

What exists now is an explosion of complexity to deal with all this and I guess these systems are "mature", kind of, but for a lot of systems it's massive overkill (and even for larger systems it's not particularly great IMO). Besides, it's really a bad fix for more fundamental problems.

Personally I wouldn't call TypeScript mature until compile times are roughly within the range of literally ever other compiler that has ever seen wide-spread adoption. It doesn't need to be fast: just not a huge outlier.

Re:Strong typing, a hill I'm willing to die on by zdragnar on Wednesday October 04, 2023 @10:53AM (#37766039)
You can still use tsc for type checking via editor language server and quality gates (with the noEmit flag) and get stupid fast compilation with swc or esbuild.

Explosion of complexity and "bad fix for fundamental problems" sounds a lot like you just have an axe to grind.

Many other popular languages have multiple build systems and tools to choose from as well; it isn't a particularly novel challenge.

Re:Strong typing, a hill I'm willing to die on by arp242 on Wednesday October 04, 2023 @11:29AM (#37766594)
Points out real-world practical problems

"You just have an axe to grind!"

Hmkay.

I just want things to compile, with errors, like literally everything else works. It's really not a huge ask. I don't want complex bespoke setups with multiple compilers and background processes and whatnot. The classic JS/TS response is "here is the happy path with all this tooling, but if you want something outside of that then there is something wrong with you".

Re:Strong typing, a hill I'm willing to die on by zdragnar on Wednesday October 04, 2023 @02:50PM (#37769841)
I mentioned using tsc with the noEmit flag for quality gating, which is the same workflow you would use.

`tsc --noEmit a.ts` (possibly flipping the position of the flag, I forget if it is sensitive).

That'll check the types without spending unnecessary time compiling with the slower tooling.

From there, esbuild or swc binaries compile the code as desired. They use the same tsconfig file that tsc does, so no need for any extra complexity. They build so fast that you'll not mind having a separate command, I promise.

You could even combine the two into a simple one-liner if you wanted.

Compared to, say, java where you have to fight over maven or Gradle or ant, plus endless config options in XML or groovy or whatever, typescript really isn't much to complain about.

Hell, trying to set up a clojure full stack project is a nightmare of conflicting opinions over tooling between lein and shadowjs or whatever.

Of the big languages, C# is about the only one with a "one true way", and of the smaller ones, they simply haven't yet developed a big enough base to grow contentious enough to have divergent solutions.

Re:Strong typing, a hill I'm willing to die on by dmix on Wednesday October 04, 2023 @04:05PM (#37770904)
Yep almost every (serious) TS dev only uses --noEmit for development by default because they use VSCode/IDEs as their typechecking engines and then have something like esbuild for delivering the content to the browser locally. I've never had performance issues with either step and I use both daily.

The raw output speeds aren't a very good 'practical real world example' as the OP described it.

If anything in dev ESLint (+ Copilot) is the slow ones that I sometimes noticed, but there is already Rust driven replacements maturing in the pipeline as we speak.

Re:Strong typing, a hill I'm willing to die on by arp242 on Wednesday October 04, 2023 @04:42PM (#37771444)
The performance of "tsc --noEmit a.ts" is identical, and it makes no difference vs. just typing "tsc a.ts", and it doesn't really solve "compile on demand" (with type checks) in any case.

I looked in to this some time ago, because I couldn't believe it was this slow, and tsc just has a huge startup cost. Once it gets going it's alright (I think? Don't quote me) but to get started takes a long time. It's actually already improved because not too long ago it was more like 3 seconds (probably because of the parallelisation, which is kind of cheating IMO).

I don't know about Java as I never really used it, but complex build systems are not unique to TS of course, but what they are in TS is mandatory for any reasonable experience because it works around the fact the compiler is so damn slow. That's a huge difference you can get started without too much effort, and you can do "smart" things fairly easily as I mentioned in my earlier comment.

> they simply haven't yet developed a big enough base to grow contentious enough to have divergent solutions.

C, C++, Go, Rust, Python, Ruby, PHP don't have a "big enough base"? Ehhh

And my entire point is that TS LACKS "divergent solutions". Because it's so slow lots of solutions are simply not practical.

Re:Strong typing, a hill I'm willing to die on by jdeisenberg on Wednesday October 04, 2023 @10:58AM (#37766120)
You might want to look into ReScript (https://rescript-lang.org/). It has strong static typing with type inference, and it is very fast.
Re:Strong typing, a hill I'm willing to die on by arp242 on Wednesday October 04, 2023 @11:19AM (#37766445)
Yep, Rescript is nice, but also comparatively obscure. It's okay for personal projects; in company setting: maybe? It's certainly more complex.
Re:Strong typing, a hill I'm willing to die on by 2c2c2c on Wednesday October 04, 2023 @01:56PM (#37769085)
This take is common, but personally never understood it. The typing is optional. Use it for the easy stuff and enjoy the low hanging fruit
Re:Strong typing, a hill I'm willing to die on by junon on Wednesday October 04, 2023 @05:23PM (#37772000)
If the tooling is a pain to use, slow, and owned by a crappy corporation, and I'm not going to use the types anyway, then I have even less of a reason to use it...
Re:Strong typing, a hill I'm willing to die on by arp242 on Wednesday October 04, 2023 @10:09AM (#37765438)
Are these people who used types but didn't like it, or people who never really used it and refuse to even try it?

IMHO these are markedly different scenarios: the first is essentially just a difference of opinion, the second is a rather myopic attitude.

Re:Strong typing, a hill I'm willing to die on by lo_zamoyski on Wednesday October 04, 2023 @11:25AM (#37766521)
Have they considered languages with type inference?
Re:Strong typing, a hill I'm willing to die on by digging on Wednesday October 04, 2023 @11:53AM (#37767003)
> bemoan the upfront cost

This applies to much more than static typing as well. Anything built, can be built well or it can be built quickly.

Although I often have to make trade-offs for immediate gain at work, there is a big difference between the quality of my work over time vs the quality of other devs who default to immediate returns. I will say in their defense, they play a role in the team. But I wouldn't want to work on a team where avoiding upfront costs was the expectation rather than the exception.

Re:Strong typing, a hill I'm willing to die on by waffletower on Wednesday October 04, 2023 @12:12PM (#37767290)
And I definitely think less of you as you as a developer as you openly admit to dogmatic and myopic prejudice regarding the nuances of typing systems and the complexity of software development contexts.
Re:Strong typing, a hill I'm willing to die on by lijok on Wednesday October 04, 2023 @12:35PM (#37767687)
Interesting. Would you have had the same response if GP stated:

"I've worked with my fair share of vanilla JS devs who refuse to acknowledge the benefit of testing. Most of them bemoan the upfront cost of testing everything without realizing the benefits of it. I absolutely think less of them as developers."

Re:Strong typing, a hill I'm willing to die on by waffletower on Wednesday October 04, 2023 @01:58PM (#37769110)
Again another binary dichotomy that doesn't neatly fit reality. I imagine the number of developers that would unilaterally dismiss all testing practices is very small.
Re:Strong typing, a hill I'm willing to die on by halfmatthalfcat on Wednesday October 04, 2023 @04:19PM (#37771106)
I mean, I'm not going to say it to someone's face but I'll definitely be judging them. Most of those who have pushed back against typescript have done so for similarly dogmatic reasons or even straight ignorance (I dont want to learn something new), so I'm not sure who is really the winner or loser in this situation.
Re:Strong typing, a hill I'm willing to die on by leptons on Wednesday October 04, 2023 @01:20PM (#37768485)
I absolutely realize the benefits of it, and I also recognize it doesn't cure all. Everything has trade-offs. There were plenty of amazingly complex and large projects written in vanilla JS before typescript ever existed, and somehow they aren't falling apart and crippled. It really depends on the developers involved more than the language or the dogma.
Re:Strong typing, a hill I'm willing to die on by ecshafer on Wednesday October 04, 2023 @01:59PM (#37769122)
This sounds like its just Typescript evangelizing. But while I love types, Typescript kind of sucks and sucks the fun out of writing Javascript. If I am going to add a compilation step to get types, I would rather write Scala or F# and compile to JS, then you also get rid of all of the warts of JS that Typescript doesn't get rid of.
Re:Strong typing, a hill I'm willing to die on by IshKebab on Wednesday October 04, 2023 @06:18PM (#37772576)
I agree Typescript doesn't solve all the warts. But it does solve a lot.

The really issue with compile-to-Javascript languages is debugging. Have fun stepping through your incomprehensible generated code in dev tools.

(Except Dart which has really good Dev tools support; I guess they can poke the right people to make it work.)

Re:Strong typing, a hill I'm willing to die on by manicennui on Wednesday October 04, 2023 @02:16PM (#37769370)
The problems with JS go far beyond its dynamic typing.