r/javascript • • Nov 01 '19

AskJS [AskJS] Does anyone still use plain Javascript (as opposed to Typescript) for any serious project? Why? What are the benefits (for you, anyway)?

4 Upvotes

76 comments sorted by

51

u/RyanMatonis Nov 01 '19

I feel attacked.

6

u/rholguing Nov 01 '19

Me too! I started to like JS because of typescript ironically

-7

u/jiri-urbandroid Nov 01 '19

Not intended! What I can't wrap my head around is that plain JS objects are extremely vulnerable - I never know what properties a certain object will have in runtime. Maybe I'm brainwashed from using strongly typed languages but whenever I have to use JS or even <any> type I am really scared to do so. When there are no constraints on object properties, in a larger project there has to be a ton of e.g. typo errors, no?

8

u/RyanMatonis Nov 01 '19

Yea there’s definitely a ton of issues with, for example, APIs wanting strings and getting Numbers. I grew up on Perl though so the clusterfuck is sort of my style.

13

u/darrenturn90 Nov 01 '19

I guess it’s just about discipline? In practice I found type errors few and far between - and tools like intellisense really help with working out names of keys in objects etc. Personally I think that static typing is a crutch you can learn to rely on at the expense of understanding an api or a project because you don’t need to. Of course that has its advantages - but (and at least in my experience) the overheads of typing everything don’t seem to outweigh their real (not perceived) benefits

0

u/pascalkiller Nov 01 '19

I agree! I write alot of code in strong typed languages, and thus won't even think about doing type-unsafe stuff in JS.

9

u/IxianNavigator Nov 01 '19

I guess it's more being "brainwashed", as you say. I almost exclusively use JS for 6 years. With the occasional Ruby, Python, Go, Java and Kotlin here and there. With the strongly typed ones I felt myself being too restricted and held down, almost to the extent that I felt I can't really do anything. I'm sure that the feeling would go away commensurate with time spent. But for the time being I feel with JS at home, with me being able to just make up things as I go, no need to carve every type, property, parameter into stone.

Long before JS I programmed with C, C++ and more with Java. And I didn't feel restricted with them. So I'm sure that it's just a matter of what you are used to.

Typos? No not really. Simply running the code eliminates these. Also it's not like there is no IDE supported checking at all. There is jshint or eslint to check syntax and basic code integrity things like this. Typos, unused variables, bad idioms etc. can be spotted and avoided right as you type.

22

u/darrenturn90 Nov 01 '19

The removal of bloat and the risk of over engineering any typescript project . I find typescript lends itself well to object oriented class based code to some degree - but i found it far less beneficial in the functional world.

At least to the degree I’ve seen it used in production. I’ve seen 60 file projects with services and providers and factories and interfaces where it should have been about 3 or 4 files in total.

I should add that it’s not typescript that causes this / maybe training and expectations people have after moving from oo to js

-6

u/jiri-urbandroid Nov 01 '19

Right - so functional is where JS would shine? My question comes from the oo perspective so that's most probably why I'm confused about this. Thanks!

5

u/alternatiivnekonto Nov 01 '19 edited Nov 01 '19

It doesn't matter whether you're writing functional or OO, TS does not impose any design limitations. You can write purely functional stuff and the benefit you still get is you know the types of your inputs and outputs. That's the whole point of TS.

I know, have seen and sometimes also contributed to a complex over-engineered TS code base but that's a failing on the devs' part, not the library.

4

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

TS does not impose any design limitations

Well, it does, sort of. The typing provided by TS works much better for more "traditional" code than for functional code. Finding the right types for the levels of indirection you may get from various functional constructs and composition can be quite painful.

I know I not that infrequently myself spent much more time on types than on the actual code. You can use less specific or correct type constructs to save a bit, but then you don't get the full benefit. Or you go all out and need a lot of advanced type constructs like conditional types, multiple type signatures per function, stuff like that. Then types become so complex you may actually have more problems with that "type code" than with the real one.

What IMO is not sufficiently ingrained in people's minds that there is only a "virtual" connection between the typings and the JS code: JS could not care less, so any types you write may or may not actually accurately reflect what the JS code does or should do. And for code like truly functional code it is up to you as the developer to make sure that connection is solid - and it gets really hard at times, and a lot of "cheating" is done (like using "any", maybe just for generic params, and "as Type" assertions - hopefully correct).

The connection between TS types and the actually executed code is not one with solid connections between the two - it's more like two completely independent planes of sheets of ice, and it is your job to make sure the "type ice sheet" is mostly correct and matches the underlying actual code ice sheet.

I would not want to write the kind of code that we write without TS (long term projects, distributed teams, quite a few newbies, long-term maintenance, plenty of refactoring going on). However, the idealist hype around TS pisses me off. It's just a static code check tool completely independent of the actual JS - and you hope that 1) you got the types mostly right, 2) that TS mostly correctly identifies what's going on.

In the end it is software trying to understand other software - and that fact alone should give you pause before getting too excited. Since software is not that good at it TS, despite having some automatic detection by parsing the code, heavily relies on the developer to tell it what is going on. This in turn requires the developer to understand what their code does. That's quite a heavy burden for any reasonably complex code, never mind team-developed code over time.

That means one use case for TS is having some base code, e.g. libraries, frameworks, type-annotated by really good developers who also have the time to do a good job. Then you can be slightly more sure about getting better results (code) from developers with less experience and/or time using that base code. That may also be in time instead of in space - i.e. you yourself working on the same code later (refactoring), with less time to spent on relearning what you did originally.

Anyway, the writing of the type annotations is harder, sometimes even impossible to do accurately, for some truly functional constructs. You can still do it, but it requires more complex type annotations (now themselves more of a probable cause for mistakes) or less exact types.

 

I highly recommend any serious TS (or Flow) users regularly spend some time in the "issues" sections for TS (or Flow) on Github. There are lots of legitimate unsolved problems (meaning not a user error or just a bug).

1

u/[deleted] Nov 01 '19

Not true at all. With functional programming you are mapping types onto other types, and Typescript gives you arguably the biggest benefit.

10

u/[deleted] Nov 01 '19

[removed] — view removed comment

1

u/MajorasShoe Nov 01 '19

Going full OO is why I like typescript. Yeah, I like the type safety. But I also like the class features thy get added, possibly more.

17

u/[deleted] Nov 01 '19

I implemented typescript because I needed more work to do and can honestly say it has pretty much done nothing except add 20 sec to my compile time.

6

u/dooburt Nov 01 '19

20 seconds sounds optimistic!

36

u/griffonrl Nov 01 '19

Of course! Loads of projects still do.
TS adds its own problems. TS specific annoyances. Spending hours figuring how to satisfy a side case for the type checker. Dealing with type definitions that might or might not up to date or complete. Extra dependencies in your package.json to manage. It also comes with a non negligible cost in development time. Then there is the added verbosity in your code.
And just personally find the type system friendly for C# and Java refugees but nothing as elegant as what languages like OCaml or Haskell offer: wish for H&M notation.

8

u/SizzorBeing Nov 01 '19

You had me at of course.

Do people still use plain JavaScript, sheesh. Relax kids, things don’t change as fast as you all seem to think.

9

u/tombardier Nov 01 '19

The thing with dynamically typed languages adding type annotations and things, is that to take advantage of the types, you need to annotate stuff to the point it starts to be as verbose as Java. The Haskell and Ocaml/F# world give you the benefits of strong typing, but largely use inference to get rid of all the really verbose type annotations. Type annotations are rarely used, and are just a hint to the compiler in a lot of cases.

3

u/bikeshaving Nov 01 '19

> Spending hours figuring how to satisfy a side case for the type checker.

Literally no one is stopping you from using `any` except (probably) a misguided, cargo-culted linter rule. When typescript gets in the way just use `any` and move on with your life.

16

u/neo_dev15 Nov 01 '19

Because legacy projects pay a hell more than typescript.

And because if you worked in this industry for 10 years... anything becomes cumbersome.

Typescript doesnt solve the issue between monitor and chair.

If you dont have code review for typescript its just javascript with extra rules and extra limitations.

I will say it again, there are tons of ongoing projects looking for react/angular developers because the devs left for greener pasture and now are stuck with it.

Instead of developing a mock and then use whatever framework fits.

-3

u/[deleted] Nov 01 '19

Typescript doesnt solve the issue between monitor and chair.

Actually it does to an extent, I can write types that stop other devs from making certain mistakes.

4

u/neo_dev15 Nov 01 '19

I can change that type to any.

Tadaaaaaaaaaaa.

As i said. Proper Code reviews(like 1 person actually reads the stuff) or there is just stuff with rules.

There is code written in typescript where everything is var(current job). They just didnt care. The type is any almost anywhere.

If i have access to the source code i can freaking modify it.

People dont even use react how it should be use put redux over it as a "necessary" and go for it. When well shit hits the fan well they either bail or say :"cant be done" and here i am.

I worked on 5-7ish projects for other companies on react. (I work for an outsource "talent" company)

All of them had redux when it shouldn't. And i am not talking small companies here. I am talking big names with big money that well devs just took the "new shiny tool".

All of them had git, always merged code but it was always approved they had even tests.

And we are not even cheap and we get projects constantly. Or well more expensive than 2 devs thats for sure.

You protect your code with code reviews not language and frameworks.

8

u/[deleted] Nov 01 '19

You protect your code with code reviews not language and frameworks.

I'm sorry but this is so wrong. You protect your code with a whole bunch of things including a type system, unit tests, Integration tests, code review and QA. If you think code reviews alone are going to protect your code you are in for a shock.

A proper type system is one of these things and prevents a subset of issues. There's no magic bullet that solves all of your problems and there never will be, you need to understand what tools are used to solve what problems.

0

u/neo_dev15 Nov 01 '19

Then you should work in the real world.

Why should someone use int in typescript if they want any?

Who is going to make him? The language? The framework?

3

u/[deleted] Nov 01 '19

I do work in the real world, I have been for 12+ years now.

Why should someone use int in typescript if they want any?

I dunno, I've never had this problem. I work with competent programmers that know how type systems work. I've literally never run into this issue. Worst case most types are just inferred

Who is going to make him? The language? The framework?

Their own pride?

If this is an actual problem you have then you are working with people who are choosing to do things wrong. I guess you deal with them the same way you deal with people who can't follow a spec. You try and teach them to not be dumb and then fire them...

3

u/neo_dev15 Nov 01 '19

So you need ... code reviews or reviews.

Otherwise who knows who did what. Especially the team lead or manager. And you need a standard...

I dont know in what loopy land you live in where people suddenly work for pride and are fired.

In Europe you need a reason to fire someone and a good one at that. There is a lack of developers... so i dont know what industry you talk about.

For example it takes at least 3 miss-steps before you can fire someone in my country.

Not everywhwre is USA.

3

u/[deleted] Nov 01 '19

I mean I included code reviews in what's needed, but if you need code reviews to force people to write things the right way in the first place then there's a problem. Code reviews aren't design meetings, they are meant to catch mistakes.

1

u/Tittytickler Nov 01 '19

You can say the same thing about type checking.

1

u/[deleted] Nov 01 '19

Yes, that's why we have many processes to catch mistakes instead of pretending code review does everything...

→ More replies (0)

1

u/robotsympathizer Nov 01 '19

I'm anti typescript, but this particular problem can be solved by ESLint.

4

u/infinitelolipop Nov 01 '19

This is bigotry, shame on you OP

13

u/[deleted] Nov 01 '19

Because TS adds unneeded complexity. Not once have I had a typing related bug in any project I’ve worked on. So I’d counter, what are the benefits of adding TS and forcing developers to transition when plain old JS is more flexible, easier to work with, and works just fine.

3

u/Elession Nov 01 '19

Not once have I had a typing related bug in any project I’ve worked on

Really? You never made a typo or thought an API was returning something different? Linters can help but can't do magic.

what are the benefits of adding TS and forcing developers to transition when plain old JS is more flexible, easier to work with, and works just fine.

  • more flexible: not really a selling point, TS type system is very flexible so you can represent a good chunk of JS

  • easier to work with: no?

  • works just fine: it doesn't mean we cannot do better

The main advantage is maintenance. Can you jump into a 50kloc JS project and be able to follow some flows instantly? If you see placeOrder(user, cart), how do you know what are the fields/types of the arguments? Just go around the codebase until you find it? console.log? What is placeOrder returning?

The main thing types gives you is an always up-to-date documentation that will also help you while you're developing not only with typechecking and refactoring but also with the autocomplete. Of course if people start putting any everywhere, it isn't very helpful. But there's a reason pretty much every single dynamic language has now some type annotations added to it: static analysis is extremely useful.

2

u/[deleted] Nov 01 '19

A debugger gives me everything you use types for and even better, gives me examples of those values. Paired with proper unit testing I can find all of that info extremely quickly.

That being said I have found TS useful for service development simply to maintain and easily understand contracts between my DB and my service layer. But in very few organizations is it viable to do this and then share those “models” across every layer.

Maybe if I was building a greenfield full stack application I’d start with TS and I’m sure I would love and hate it. But I just don’t see the need to use it in 99% of applications. You say better, many say overkill. I lean towards overkill and annoyance in many cases.

2

u/Elession Nov 01 '19

A debugger gives me everything you use types for and even better, gives me examples of those values. Paired with proper unit testing I can find all of that info extremely quickly.

Faster than "Go to definition"? Or do you mean you (and everyone else working on the codebase) run the code to see what happens in each branch? Do you remember the values you checked 6 months ago?

Maybe if I was building a greenfield full stack application I’d start with TS and I’m sure I would love and hate it. But I just don’t see the need to use it in 99% of applications. You say better, many say overkill. I lean towards overkill and annoyance in many cases.

Stuff like https://news.ycombinator.com/item?id=19131272 doesn't only apply to big companies. In my case it's easy to compare since I work with both TS and JS codebases and the TS ones are just 10x easier to work on and it's just incomparable in terms of productivity. The annoyance for me is when I have to work on JS :) I can see why people would think TS would slow them down and that is definitely going to be true at the beginning, especially if you are not used to types, but it makes for a much smoother ride in the end.

2

u/[deleted] Nov 01 '19

To each their own I suppose.

2

u/Jack9 Nov 02 '19

You never made a typo or thought an API was returning something different?

Inevitably, talking to these kinds of people in person they admit it happens all the time. When working in a team, the debugger only catches their issues ... most of the time. This is a troll.

3

u/[deleted] Nov 01 '19

Javascript is still being used in a lot of applications in the company I work for, Publicis Sapient, and we have a lot of different clients, however, I've actually been tasked with creating a class for converting these projects to Typescript incrementally. I would say that we consider it a major goal of converting to an almost-entirely TS house.

Now - I want to make this very clear. I LOVE plain Javascript. It makes the JS language flexible and approachable, and it and Python are the #1 languages I'd recommend for beginning devs, because of the lack of verbose typing necessary. When you look at TS code and JS code with a beginner's eyes, TS code is harder to read and understand at first glance (What's "IDataVisualizationItemObjectHeaderProps<Partial<IDiasporaGraphProps> & React.Ref<any>> mean anyway?").

But there comes a time when you're no longer writing code to learn how to code. And that means the code you write will need to pass through many hands. That is where Typescript shines compared to Javascript. While it might take longer for a novice developer to understand TS syntax, if you were to plop a novice developer straight into a Typescript project, even if they weren't familiar with typescript, the linting tools, development capability and relative flexibility allows for the developer to get "up to speed" faster. It also prevents them from introducing hard to debug errors by mishandling types or properties of types. In short - Typescript is more advanced, and requires more thought, but is a better tool overall for larger projects.

I completely agree that the way typing syntax is handled in TS is not what I would prefer. Too much comes from the C# background. I would prefer the way Rust handles it; "int mut foo = 3; int bar = 4;" vs "let foo: number = 3, const " bar: number = 4; but it's not that bad.

So to answer your question: Yes, we still use JS in real production, but we're phasing it out

9

u/-domi- Nov 01 '19

All my stuff is React, and i just find it redundant. Not that i have 100% test coverage, but between immutable state and testing, i haven't had a single issue happen in production which would have been prevented by TypeScript. Not one. It's simply not worth the time investment to transition over, and to learn to use it myself, for now. Maybe in the distant future when i'm not this far behind on all the feature requests, i could spend the time to consider it, but i literally don't see a single upside, as things are.

2

u/[deleted] Nov 01 '19

The only real problem is when you forget that a function returns a promise, so you forget to await it. That happens, and can be quite time consuming to debug. Apart from that I haven't seen any bugs in all of our plain JS projects that wouldn't have happened if we had used TS.

3

u/Arumai12 Nov 01 '19

You can catch this with testing. And even if you miss a test you can add one later when you find the bug

0

u/[deleted] Nov 01 '19

Yes, definitely. I just try to think about scenarios where TS actually brings value since most of the arguments for TS isn't really objective. Looking back over the past 5 or so years, I'm thinking about what kind of JS bugs have been most common and been hardest to debug for me. This is the only one I can think of that wouldn't have happened if I'd use TS.

2

u/deinok7 Nov 01 '19

TS try to find issues related to types. So if you really write well typed JS code, you wont notice that TS is there ;)

1

u/Herm_af Nov 02 '19

Its the tooling more than anything. With VSCode its incredible

2

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

You mean you always know at all times which variables are nullable and which are not, even as you pass them between functions? Are you aware of how much easier it is to refactor code written using Typescript, or to onboard new engineers? Does every engineer know the exact type contract for every third party function they use?

Also, I think you'd be surprised what kind of bugs would be caught via Typescript. What bugs have you encountered that you think wouldn't have been caught with Typescript?

2

u/-domi- Nov 01 '19 edited Nov 01 '19

I've never once had to care. Literally, my life is riddled with very difficult to resolve issues involving scaling of stuff in HTML5 canvas, tracking down silly errors in reference values in databases, weird orders of operations causing undesired behavior, and UI troubles i'll never become good enough at addressing well, but never once can i recall having to care whether something was nullable, or it receiving the wrong type of data somehow. I'm well aware of TypeScript. If i ever feel like it's the correct tool for any job, i'll immediately resort to it. But as things are, i seriously don't see any upside to sinking the colossal time investment into converting everything over. And anything less than converting everything over is just diminishing the returns on the already marginal improvement which TypeScript integration would be.

It's just a super odd case of an application.

1

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

Wait, you've never used Typescript? Do you never pass around structured objects?

3

u/Tittytickler Nov 01 '19

I don't understand whats so crazy here? We've never used TypeScript where I work either. It's not like TypeScript saved web developement or something

2

u/[deleted] Nov 01 '19

[removed] — view removed comment

1

u/-domi- Nov 01 '19

Like i said, it's never happened to me, and when it starts happening, i'll definitely consider it.

5

u/tmckearney Nov 01 '19

I'm in the process of converting a large project (actually multiple applications) from plain JavaScript to Typescript and it has already found a multitude of bugs and shady practices like initializing a variable to the wrong type, or dereferencing an optional variable before testing for null, etc.

With large teams (we have about 60 devs), you don't typically have 60 rock stars, especially depending on hiring practices.

I believe TypeScript gives you the best chance to force Junior and/or less competent devs to write safer code.

Note: we already have mandatory code reviews and nearly 100% unit test code coverage. It's not enough

2

u/[deleted] Nov 01 '19

Forcing devs to write better code. You hit the nail on the head. Let me tell a story.

At my job we use React, and I got into a big debate with the other good react devs over whether or not we should enforce the use of CSS modules. Their argument against it was that we already use SCSS, and proper naming and scoping of SCSS renders CSS Modules redundant. My argument was that we can't trust devs to actually use SCSS correctly.

Case and point, I've seen some of our less effective frontend devs and some of our offshore contractors literally write a SCSS file with class names like .a-1, not scope it at all, and import it in a way that it will be applied globally.

Yes, code reviews are important, and I eviscerated that one, but enforcing standards that make it easier for less competent devs to not ruin the codebase is also super important.

3

u/ncgreco1440 Nov 01 '19

If it's at the point where you can't trust the employees to do the job they were hired to do, then you have a much larger problem with HR.

3

u/[deleted] Nov 01 '19

Spend some time working for big enterprises. You'll see.

2

u/[deleted] Nov 01 '19

It's nice for small project because you don't have a compilation step. You write js and it just runs. And most of the errors I have are not related to types and the browser offers very good debugging tools to find the errors. I understand how for projects with more than one person it's useful but when you're alone, you know how everything works and you don't need to add any fancy tech to your project if it does basic things

2

u/nxsynonym Nov 01 '19

For personal projects I prefer plain js. I'm 100% familiar with the code base, can find and destroy bugs quickly, and it's one less dependency / config / compile step needed.

Working on a frontend project that has 6 other devs touch it and a big code base however, ts makes everything a little bit smoother. Takes a lot of the guess work out and does catch a lot of would-be run time errors.

3

u/[deleted] Nov 01 '19

I love them both. Yes, it's easier to write code fast in JavaScript, but the code is more stable in TypeScript. It's great to be able to look at a function and know what easy variable is supposed to be, what the return type is supposed to be, just at a glance. I subscribe to the philosophy that it's better to have to spend more effort when writing code to save effort when reading and modifying code.

3

u/Reashu Nov 01 '19

I find that the toolchain is still significantly easier to set up. I also find limited benefit with the frameworks I use, although support is improving.

1

u/natziel Nov 01 '19

We tend to use static typing (w/ Flow instead of TypeScript, which was regrettable) for our library code, but we don't really bother with it outside of that, since it's still weakly-typed and therefore doesn't buy you as much when you're working with dynamic data, like api calls, config files, external data stores, etc since their types can vary drastically during runtime anyway

1

u/[deleted] Nov 01 '19

I honestly just haven’t gotten around to using it, which is odd because I haaaate non statically typed languages.

Apprently vue 3 will have better support for it so I’ll pick it up then. I’ve heard veux doesn’t play nice with vuex

1

u/ryan_solid Nov 02 '19

TypeScript is getting good. But there is still a lot of places where types don't cover what you can do with the JavaScript language. JavaScript was made in a way that just didn't need to have those things in mind. I've done the move to TypeScripts but I still hit limitations every single day. It comes from years of thinking about problems a certain way. Do I feel the pure JavaScript solutions in many cases more elegant? Definitely. But does it really matter in the scheme of things if you are looking for the benefits that TypeScript brings?

TypeScript being based on JavaScript will always be a subset rather than a superset of JavaScript due to the fact it is more rigid. It is likely you will always be able to do less with it. But that is fine 95% of the time. I find when starting new projects with TypeScript you just start thinking of it as another language and approach things that way. Suddenly you don't hit those walls. So maybe that's the best way to think of it.

1

u/lifeeraser Nov 01 '19

For one project, just to keep myself aware of what JS features are supported by contemporary browsers and what still needs assistance from transpilers.

1

u/Owstream Nov 01 '19

Honestly, I wish JavaScript had a type system included. But React ecosystem is pretty usable without it and often doesn't worth the extra complexity layer, especially when using a decent linter instead.

1

u/robotsympathizer Nov 01 '19

Typescript is just what's currently trendy in front end development. Remember 10 years ago when everyone was switching from Java to Ruby and Python? There was a reason for that. In a few years when people are sick of dealing with bloated, over-engineered applications, they'll start looking for a new paradigm.

Typescript is probably useful for very large projects at enterprise-level companies, but for your average startup it's overkill. Most companies I know start using typescript due to hype moreso than the fact that they were having actual issues with type safety. In my experience, incorrect types represent a tiny percentage of bugs and Typescript tends to cause more headaches than it solves.

1

u/noseratio Nov 02 '19 edited Nov 06 '19

I side with Eric Elliot's The TypeScript Tax on this one. Coming from a heavy C++ and C# background, I've lately been involved with an Electron project which started as plain JS and just recently got converted to TS. At that time I felt ESLint had already been doing a great job on proactively catching errors. So far, I haven't noticed much improvements in typing errors catching, but I've personalty noticed a minor reduction in my code/run/debug cycle productivity. Pretty sure I'll adapt but that's my 2c as of now.

0

u/[deleted] Nov 01 '19

[deleted]

7

u/strangedreamer Nov 01 '19

This....I have used Typescript and I really like it. But JavaScript is like breathing at this point for me.

6

u/ancientRedDog Nov 01 '19

I use c# and javascript and don’t miss having strong types in js. I’ve use TS some and it seems useful. But also a bit of a vortex of time if you start to type everything.

2

u/[deleted] Nov 01 '19

-9

u/MikeMitterer Nov 01 '19

OMG You are one of these guys who thinks you're the best and all others are just idiots. Have you ever written at least one app with more than 10k LOC??? I guess not...