Hacker News new | ask | show | jobs
by spraak 2483 days ago
Don't do gradual typing, is what I'm saying. Start a project with the compiler and linter tuned strict and you'll do well. But if you have to go gradually and you have a goal of typing an untyped codebase, then just introduce a rule at a time from a list of rules you'd like in the end. Each rule should be a single commit or single PR (or Epic, or whatever granularity required)

> Because sitting around and typing tens of thousands, maybe hundreds of thousands of lines of code is not super productive?

Your project either doesn't benefit from static types or you're not seeing the benefits. I agree it's annoying to convert a JS project to TS, but TS in the end has been a huge boon to our overall velocity (long term) considering bugs, refactoring, and service to service edges.

1 comments

> But if you have to go gradually and you have a goal of typing an untyped codebase, then just introduce a rule at a time from a list of rules you'd like in the end.

This was the plan. In a similar fashion to bringing a legacy code base under test we would commit to bringing this code base under type coverage. We started by adding explicit type signatures at the start and refining the types as we worked on the modules. What we ended up with is an archipelago of typed modules.

This has the consequence of forcing the developer to be aware of the coverage of the module they're working with. On our team I don't think there were enough people who had experience with strongly typed languages on board -- we're a JS shop. This meant we had to teach our teams how to think and design with types as we went along... and as deadlines approach and teams work towards their goals sometimes... that escape hatch is too tempting.

So your archipelago spends most of its time shifting. Some old, crufty modules never end up getting typed. New modules are well typed. And there are too many of the former to enable strict checking without overloading the developers.

It's not simply a technical problem but a social one too.

> Your project either doesn't benefit from static types or you're not seeing the benefits.

I believe types benefit the programmer and help us reason about programs. We've been seeing benefits there. It has helped some of the more junior developers learn how to write better code.

One boost has been that I started teaching a weekly class in Haskell that some of our developers opt into and that has had a positive effect. A more strict language has helped demonstrate how to structure programs and think in types. Which has helped them, they say, write better Javascript (even though I'd never recommend learning Haskell to "become a better programmer," you'll walk away frustrated).