Hacker News new | past | comments | ask | show | jobs | submit login

That’s the beauty though, isn’t it. Most bugs are trivial. I appreciate typescript getting the trivial bugs right more often than I’d trust myself to do so.



Right? The argument that static/strict typing mostly catches trivial bugs isn't an argument against the value of that language, and yet people seem to think it is!


Let them fight windmills while we have a good time.


I have to disagree. Adding the types will increase the number of the characters/lines of code which with a 80-char formatter limit can make functions look almost gibberish at a glance. Do that on a whole codebase and it becomes a mess to look at.


The verbosity of TypeScript types can be attributed to poor choice of syntax and names that became obvious retrospectively.

Still even with TypeScript if types makes your functions ugly, then it shows the complexity of the code. Often it also suggests sensible refactoring that without types would not be apparent.


Typscript: "function area(left: number, top: number, right: number, bottom: number): number {"

Javascript: "function area(left, top, right, bottom)"

In an editor the typescript function would likely be split into five separate lines.

"function area(

left: number,

top: number,

right: number,

bottom: number)

: number {"

None of the functions are complex but the the typescript function with the formatter creates a lot of noise.


It's not noise, it's informative content.

It also means it's not going to explode when fed the wrong types, because that's not possible.


The only way it can not be noise is if you have no idea what your types are. That's a terrible way to code.

If I'm working on a function foo(bar, baz), I know exactly what bar and baz are before looking at a single line of it, I've been tracing the code through to that function, how could I not know what the data types are at that point?


It's normal not to be aware of the types when encountering code for the first time, or after a long absence.

Your described experience is the rare exception when working with third party vendors, on long lived projects, or with teams that are not trivially small.


So the benefits are only available once or twice, but the code is going to be verbose forever.

If I were to come up with environment where it is guaranteed to be a net positive it would be a company with lack of boundaries between teams and a lot of churn.

Essentially TS averages out engineers in your team. You're going to be slower, but more predictable. Your 10x engineers will become 5x, but 1x will become 2x.


> Essentially TS averages out engineers in your team. You're going to be slower, but more predictable. Your 10x engineers will become 5x, but 1x will become 2x.

It’s the other way around. For more experienced engineers TypeScript is a huge productivity multiplier: you can fly around a large code base with ease, making changes all over.

More experienced engineers also probably have some history with other statically types languages (perhaps Java, Swift or C++) so the concept of static typing is likely to be familiar to them.

For less experienced engineers, there are more drawbacks such as 1) additional language complexity and 2) possible unfamiliarity with static typing. Although TypeScript still a productivity boost because they are likely to have a higher error rate.


> TypeScript is a huge productivity multiplier

See, I've heard it multiple times. And yet nobody is able to provide evidence. Surely if effects are so huge it's should be easy to prove. We're commenting on the article that says TS is 10 years old. Where is the hard evidence?

When you ask about real examples of productivity boost, TS folks shift focus to bugs (why not talk about bugs in the first place?). When you ask about critical bugs, TS folks shift focus to IDE autocompletion. When you press for evidence, goal post is constantly being moved.

Whenever you see bold claims and no evidence other than personal stories for several years, you should immediately attribute it to placebo (or other biases).

> you can fly around a large code base with ease, making changes all over

Not really, unless you're talking about bloated codebases. Huge codebases are huge due to domain complexity, you can't be making changes all over without extensive testing. What does help is having a modular codebase with good boundaries. If you already have it, TS benefits are tiny. If you don't, you're better off spending time making it modular than switching to TypeScript.

> TypeScript still a productivity boost

And yet if you talk to popular library maintainers in Python/JS community, a lot of them say that types have slowed them down. Some of them still believe it was worth it, because it helps users of those libraries. But again, see how the goalpost is being moved?


The strong evidence in support of static typing for productivity and security is well known and a trivial Google search away.


Which you conveniently not linking because you know it's going to be controversial at best.

Get off the high horse, static vs dynamic has been a never ending debate since the dawn of time.

Just because you side with one religion doesn't automatically make it "well known". Learn to recognize your own biases.


Nah, I was on mobile and linking was cumbersome.

Here, enjoy the trivial search and read through links and their references:

https://www.google.com/search?q=Evidence+for+productivity+an...

TLDR: for productivity, there's basically no measurable impact detected in studies, positive or negative. For security and bugs, the impact is as expected: dynamic languages are as safe as strictly typed languages if they are paired with exhaustive test suites which enforce type safety. You can either write the type information alongside the application code, or write the test suite to enforce it.

Folks who think Dynamic Typing frees them of having to consider types are just fooling themselves; in this thread, even, the argument is that because they know what the types are then stating them is just unnecessary "noise". Which is all well and good, in the here and now, but provides no value when the code is foreign or forgotten; and with just a little additional syntax both the information is available to the programmer and the compiler can perform performance and security analysis with greater ease.


Do you really think I didn't google before?

> for productivity, there's basically no measurable impact detected in studies, positive or negative

As I said, controversial at best.

But you're not being completely honest here. Most research is either inconclusive, or says dynamic is more productive. It is nearly impossible to find research that says static typing is more productive.

Which is quite obvious today, Uncle Bob and Steve Yegge were talking about this since 2000s.

https://sites.google.com/site/steveyegge2/is-weak-typing-str...

https://www.artima.com/weblogs/viewpost.jsp?thread=4639

> with just a little additional syntax

Unfortunately a little additional syntax easily turns into this:

  f(): Array<Promise<ServerResponse.Response<Proto.Response>> | undefined> {...}
I didn't even get to the function body, and I already used multiple levels of my mental stack. Ugh.

And gradual typing is the worst. It is either a terrible idea, or at least a terrible implementation (looking TS/mypy). It combines the worst of two worlds.

The only viable benefit of gradual typing is making dependency hierarchy explicit.


The verbosity is not a meaningful performance impediment. It takes a trivial amount of time to write, and a trivial amount of time to read.

If the a team can distinguish between an average and excellent programmer's performance by the time it takes to read or write type information then I expect the skill and experience breadth within the team was already narrow.


The other people on/joining your team probably don’t know.


And I have to disagree in turn. Those additional characters and lines of code are documentation, and turn gibberish into not only human-readable clarity about the code you’re reading, but a machine-traversable dependency graph as well.


The problem is that they are forced documentation. You can't choose to skip it after you became familiar with it.


That sounds like a VSCode extension I could write on a Saturday morning but whatever.


Character input time is a vanishingly small concern for overall productivity. If it's a concern then you'll probably catch more bugs by slowing down to think.


Typing it is not the problem. It is reading at a glance that becomes much harder since lines oftentimes get split into multilines. I get less of an overview.


It's all still there, except with even more helpful information.

If there are so many parameters that it falls out of mental context then there's too many parameters.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: