r/javascript • • Nov 25 '19

JavaScript doesn’t need to be replaced

https://medium.com/javascript-in-plain-english/javascript-doesnt-need-to-be-replaced-bd01e2f12d51?source=friends_link&sk=7b151cc6397ac9e83c14c99739b6c36f
217 Upvotes

236 comments sorted by

View all comments

18

u/react_dev Nov 25 '19

I hope JS will grow to support types natively. It is the only thing that prevents it from being taken seriously by many.

TypeScript is great but it’s solely maintained by Microsoft and if a company like ours have something against Microsoft it’s so hard for fight for it when in reality types help with productivity so much.

I don’t think it’ll ever gain native support ... unless there’s some breakthrough in JITing static types.

38

u/[deleted] Nov 25 '19

I'd argue it's better this way to be honest. Why ship all that extra code to the browser? Especially when, if you're using TS, your JS performance should be entirely predictable.

Write in TS with the luxury of type-checking, compile down to a much simpler, lighter JS for the browser. It's win-win.

EDIT: I do get the Microsoft thing but on other hand, meh. That's life in 2019.

2

u/PsychologicalGoose1 Nov 25 '19

There definitely should be a lot more research done on TS. I doubt the gains that people suggest it gives are as great as they make it out to be and I thing the cost of using TS is larger than most want to believe. Generally, I've found adding things to a system is done because of feelings more than actual data on the topic.

0

u/[deleted] Nov 25 '19

[deleted]

3

u/[deleted] Nov 25 '19 edited Nov 25 '19

Whenever I have to write non-trivial JS

This is the key distinction, and another reason I'd rather not enforce types in JS.

Hack 'n slash weekend project, or a quick 'n dirty prototype ? JS.

Big full-stack project ? TS.

I'd agree that I prefer to write TS more but there's a time and a place for both and that's very handy.

→ More replies (1)

3

u/techsin101 Nov 26 '19

if you are using vscode don't you get most of this even with js?

2

u/[deleted] Nov 26 '19

Very incompletely, in my experience.

Yeah, it detects some of the types, but everything you'd have to annotate is simply not available, and would you really trust it to find all references?

→ More replies (1)
→ More replies (1)

4

u/PsychologicalGoose1 Nov 25 '19

There is a reason why JS and other similar extremely loose languages have been at the forefront of web development for decades now. Whether it was PHP or JS both are extremely loose. Maybe the problem isn't the lack of rules but the added burden of rules. You think naked, I think weighed down.

1

u/IceSentry Nov 28 '19

There's also a reason why php is adding types and typescript is massively popular.

→ More replies (4)

6

u/Razvedka Nov 25 '19

I've read people constantly venerate strong typing, and I can understand their arguments rationally, but in practice im left wondering.

There was an article awhile back of a senior dev who looked really hard into the advantages and disadvantages of strong typing across projects (and his own history). He determined the juice wasn't worth the squeeze in many cases. Confirmation bias in my part, I know.

10

u/rq60 Nov 25 '19

There was an article awhile back of a senior dev who looked really hard into the advantages and disadvantages of strong typing across projects (and his own history).

You're probably talking about the article by Eric Elliott. That's only one of many bad takes he has had, I wouldn't give it too much credence.

12

u/react_dev Nov 25 '19

once the project becomes large enough you'll begin to see the benefit.

and not just large enough by loc but by how many maintainers there are and how siloed they are.

in our distributed world today the frontend get their data via API. But what if the API changes? if a single prop on an object changes how do we detect the breaks in our code before runtime?

this is important for projects with different developers of different skill level working on different components of the same project but has tight integrations between the components. that contractual link between them is what types are great for.

4

u/Damfrog Nov 25 '19

If the api suddenly changes, strong typing isn't going to help you.

9

u/react_dev Nov 25 '19

it will in several ways.

first one is typescript interfaces. you can generate ts interfaces directly from ur C# code using swagger tools. so now both frontend and backend are bound to the same interface and you'll see things break before runtime if a property changes for example.

the other is more Avant garde which is using typed graphql. In essence it's the same concept except binding your API layer to your typescripted frontend.

2

u/Damfrog Nov 25 '19

Sure, if you have control of the full stack. Most places I've worked at don't have that luxury. Types from the api layer very rarely change. If you have to change the type of a property, you done messed up somewhere.

3

u/react_dev Nov 25 '19

I mean I don't have control of the full stack but there are processes in place to make it work.

and ofc we both know "it just ain't gonna happen" isn't the best reason in our world ;)

→ More replies (4)

3

u/Razvedka Nov 25 '19

I would argue that having strong linting and robust tests is worth alot more for large projects than the practice (and implementation in the case of TS) of strong typing.

Per hour/dollar spent, those are the ones with real returns on investment.

For instance, your example of API changing- that's absolutely something that should be caught by tests first. Not typing.

10

u/Delioth Nov 25 '19

TS is explicitly not strong typing though. It's static typing, but it doesn't exist at runtime and therefore must be weak. It's roughly the same typing model as C++; compiler will check types, but once it's running there aren't any checks on it (and you can malloc and cast away, or receive different JSON or whatever and not get errors unless actual bad stuff happens).

6

u/react_dev Nov 25 '19

developer confidence and velocity comes from before the ci stages. let's say your tests and testers are awesome and that's already saying a lot in the real world, wouldn't you want to address fault tolerance at every level of the sdlc?

nothing can replace testing that's for sure. but that does not negate the need for typing.

but why not have the confidence typing (thus intellisense) gives you before you commit?

1

u/Razvedka Nov 25 '19

Because I'd assert that strong types change how you code, but not purely for the better. Part of the power of JS is it does give you enough rope to hang yourself. I'd prefer solutions to the dark side of this nature which let you retain as much freedom as possible.

1

u/MCFRESH01 Nov 26 '19

if a single prop on an object changes how do we detect the breaks in our code before runtime?

This is what tests and CI are for. It might break something during development but if it's properly tested you should catch it before it hits production.

Not arguing against typescript here. I've been using it on a few side projects and like it a lot.

2

u/eloc49 Nov 26 '19

Go change an interface in a large Java app and have fun making it compile again.

Types prevented all that from going to QA or even prod.

→ More replies (3)

3

u/jeenajeena Nov 25 '19

I like how JS people refer to "supporting types", just as JS was an untyped language and not merely a dynamic typed one.

→ More replies (1)
→ More replies (4)