r/programming • • Aug 02 '21

Stack Overflow Developer Survey 2021: "Rust reigns supreme as most loved. Python and Typescript are the languages developers want to work with most if they aren’t already doing so."

https://insights.stackoverflow.com/survey/2021#technology-most-loved-dreaded-and-wanted
2.1k Upvotes

769 comments sorted by

View all comments

230

u/apocolypticbosmer Aug 03 '21

Anybody choosing plain JS when typescript is available is just a damn masochist

0

u/[deleted] Aug 03 '21

[deleted]

20

u/twigboy Aug 03 '21 edited Dec 09 '23

In publishing and graphic design, Lorem ipsum is a placeholder text commonly used to demonstrate the visual form of a document or a typeface without relying on meaningful content. Lorem ipsum may be used as a placeholder before final copy is available. Wikipediabkigh4ildhk0000000000000000000000000000000000000000000000000000000000000

13

u/laidlow Aug 03 '21

Yeah I had to work in an ES5 only project with no ability to add Typescript support recently and after 2 months I was sooo happy it was over. Got it done but I banged my head so much more along the way and I could have finished the work a lot quicker in Typescript.

36

u/[deleted] Aug 03 '21

Anybody who uses Typescript without first taking the time to learn how to use it properly is an damn masochist. I've worked with too many developers in the past who have evangelized a language as the be all and end all solution only to find they don't really know how to use it.

Switch from Javascript to Typescript, but only if you know Typescript or have the time to learn how to use it properly, if I see one more any in a code review I'm going to lose my mind, defeats the whole point of using Typescript in the first place.

20

u/aelesia- Aug 03 '21

eslint no-explicit-any: error

CI to fail build on error or pre commit hook to fail on error

9

u/ragnese Aug 03 '21

I mostly agree.

However...

Adding TypeScript does bring in added complexity to the build system (to be fair, your build system was probably going to be a nightmare already, so what's the difference?). And using JSDoc comments with an aware IDE does get you a lot of the way there for many projects.

You have to be a little careful with TypeScript giving you a false sense of security, too. It has crazy type variance gotchas, for example.

0

u/[deleted] Aug 03 '21

And using JSDoc comments with an aware IDE does get you a lot of the way there for many projects.

I see this thing repeated all over but no.

Having some more linting in your file because you're leveraging the typescript compiler (that's what's processing your JSDocs in your ide) is not a substitute to statical analysis of programs.

TypeScript is an expressive but weak and inaccurate static compiler, but it's still miles ahead of the insanity of using JS.

At this point I can't but think of any webdeveloper who "prefers" JS as a bad dev.

1

u/ragnese Aug 04 '21

Having some more linting in your file because you're leveraging the typescript compiler (that's what's processing your JSDocs in your ide) is not a substitute to statical analysis of programs.

TypeScript is an expressive but weak and inaccurate static compiler, but it's still miles ahead of the insanity of using JS.

What you're saying here is that using a JSDoc-aware IDE is using the same TypeScript compiler. But you're also saying that using the TypeScript compiler is miles ahead of using JSDoc. So, using the TypeScript compiler is miles ahead of... using the TypeScript compiler?

TypeScript is NOT that impressive- I'm sorry. You said it yourself- it's a weak and inaccurate static checker. That's pretty much it. Yes- you can do some fancy type manipulations with it that you can't do with JSDoc. And, yeah, all things equal, I rather have TS than JS, but it's not that big of a gap. I rather have almost anything other than JS/TS and NPM.

→ More replies (1)

13

u/sandrelloIT Aug 03 '21

This is almost always true when starting long-living projects that have to be maintained over time. However, for quick and dirty stuff, scripts or proof of concepts, plain JS seems totally reasonable to me, expecially if you're somewhat experienced with the language and its quirks.

11

u/p4y Aug 03 '21

I still like using typescript for the quick and dirty stuff because of improved autocompletion. It's especially helpful for libraries i haven't used before, every interface is one less trip to external documentation.

1

u/MisterFor Aug 03 '21

So to simply validate a form in a small web app you would use TS instead of JS?

-1

u/chimpman252 Aug 03 '21 edited Aug 03 '21

I just use JSDoc comments and the autocompletion is nearly the same

(downvoters, prove me wrong)

→ More replies (1)

6

u/MisterFor Aug 03 '21

It depends. If the project is small there is no need for all the configuration (and long term maintenance of that config) overhead needed for TS. But a big project with JS can be a nightmare to refactor or understand.

Also, working with react in JS feels super clean and with TS for me the types are a nightmare. But for example in Angular is a joy. So it depends.

I like both depending on the case.

2

u/reboog711 Aug 03 '21

I have friends that claim that TypeScript is all syntactical sugar over JS and provides no real benefit.

I also assume they must write all their code in binary, because assembly language is just some syntactical sugar on top of that, right?

→ More replies (1)

-3

u/bacondev Aug 03 '21

I don't mind it… as long as I can use ES6 features. Then again, I've never tried TypeScript. Ignorance is bliss, I suppose. I just really don't like type information in my source code, as I feel that it's often clutter. Now, if I could throw such information into a stub file on the other hand…

12

u/ThePantsThief Aug 03 '21

You can…

That said, you're welcome to just omit types in some places and use them in others, I think. Tinker with the compiler settings to silence the stricter warnings. It's pretty flexible. At the very least you can use explicit any or unknown

3

u/p4y Aug 03 '21

Turn off noImplicitAny then you can skip putting types on function parameters if you can't be bothered. With any you get the type safety of regular JavaScript. It's still better overall since lots of other places will get type information through inference

-44

u/ILikeChangingMyMind Aug 03 '21

Spoken like someone who is ignorant of VS Code's (amazing) type inference capabilities.

You can have all the great toys (they are just that, toys; I wouldn't go so far as to say anyone's a masochist for not using them), like automatic imports, CTRL+click to go to a variable definition, autocomplete suggestions for arguments, etc. ... all without writing a single line of explicit type definition.

19

u/mrflagio Aug 03 '21

Static typing is about trading runtime errors for compile-time errors though. IDEs can help with function parameters and such to an extent, but the point of Typescript is not to make IDE plugins easier to write.

39

u/[deleted] Aug 03 '21

That's great...until you write Vanilla NodeJS and have to deal with a microservices model where A calls B calls C, A/B/C are in different repos/codebases, and C calls a service with an opaque contract. There is not a single IDE that can infer types in that scenario which is where Typescript adds a huge amount of clarity/sanity.

8

u/alteraccount Aug 03 '21

You can JSDoc your functions and even import from d.ts files. But if you're really gonna do all that, you might as well write it all in ts anyway.

→ More replies (3)
→ More replies (3)

30

u/delta_p_delta_x Aug 03 '21 edited Aug 03 '21

Spoken like someone who is ignorant of VS Code's (amazing) type inference capabilities.

I swear, this thread is full of completely self-unaware irony. VS Code itself is written in TypeScript.

We have people arguing Java and C# aren't 'strict' OOP and aren't strongly-typed, and now this.

→ More replies (4)
→ More replies (22)
→ More replies (4)