News for hackers. Stuff that matters.
Re:TypeScript 3.4 by cryptica on Saturday March 30, 2019 @11:41AM (#19529947)
There has never been a worse time to be a software developer.

Practically all of the most popular tools encourage anti-patterns, add unnecessary complexity or solve superficial problems instead of focusing on critical problems that exist in today's software projects.

Some examples:

- TypeScript: Unfortunately, we cannot reduce a language's complexity by adding extra complexity on top. The complexity will keep rearing its ugly head no matter how much we try to hide it. The TypeScript project has had over 20K issues raised and 9K pull requests (that's not even mentioning the DefinitelyTyped repo)... To put it into perspective, the Linux project has only had about 380 PRs on GitHub. But how much value does TypeScript add? All evidence points to the fact that TypeScript does not have any positive effect on bug density. Its value is purely subjective and speculative. If humanity had invested a quarter of that time and energy towards coming up with and documenting proper JavaScript design patterns and architectures, TypeScript would have been completely redundant to begin with.

- NestJS: Makes heavy use of decorators; these aim to allow developers to handle cross-cutting concerns within their code. Unfortunately, cross-cutting concerns are an anti-pattern because they imply a violation of the principle of separation of concerns between components. It takes a bit of thinking and discipline to come up with components which have clear and distinct concerns/responsibilities, but this is not a problem that can simply be ignored by injecting decorators all over your code.

- InversifyJS: Dependency injection is a failed concept. It's been proven over and over. Angular 1 provided us with plenty of evidence for why we should avoid dependency injection (e.g. it's impossible to find stuff and you end up with a pseudo-global scope for everything which is as bad as simply using global variables). Again, dependency management is not a solution which can be automated away; it requires developers to make careful design decisions.

- Code coverage tools like Istanbul and others add very little value to projects. 100% coverage is not a useful goal to have, in fact it's counterproductive. When it comes to test coverage, quality of that coverage is WAY more important than quantity (this cannot be over-emphasized). Did you test all the right inputs? Do the tests focus on the most important code paths (and those which are more complex and therefore more likely to fail)? I'd rather have 10% quality coverage of the right parts of the code than 100% poor quality coverage. Also, you need to take into account that the more unit test coverage you have, the harder it is to make changes to your code.

- Linting tools such as ESLint/TSLint: These tools can be very nice if used correctly and not treated as a silver bullet for all programming problems. We should never forget that linters can only detect superficial problems. If your code passes all the most strict linting rules, it still says almost nothing about your project's code quality. I'd MUCH rather have code that fails ALL linting rules possible but has good architecture and good separation of concerns between components; at least the linting is easy to fix. Linting does not prevent architectural mistakes AT ALL; it only prevents superficial mistakes which are usually easy to identify anyway (if you have half-decent testing).

I hope that over the next decade, the masses of new developers will develop their critical thinking skills and that they will be able to see value beyond the hype which is always being shoved into their faces by various misguided organizations.

It's particularly difficult for me to see what has happened to software development because 10 years ago, I used to roll my eyes when I read comments like this from older and more experienced developers. New developers are often attracted to complexity like moths to a flame, but eventually we all learn that complexity is a silent killer - It's the ultimate enemy. Complexity is always trying to quietly sneak its way into your code (and I do mean ALWAYS; no matter how good your code is at any given point) and you must identify and stop every single attempt. It takes most developers at least a decade or two of coding to really appreciate this.

For me, starting a TypeScript project is like accepting unnecessary complexity from the beginning of the project. It's a bad start, a slippery slope.

Re:TypeScript 3.4 by frankpf on Saturday March 30, 2019 @12:33PM (#19530274)
> But how much value does TypeScript add? All evidence points to the fact that TypeScript does not have any positive effect on bug density. Its value is purely subjective and speculative.

This is objectively false. There is plenty of evidence showing that modern type systems reduce bugs considerably.

In Airbnb, they found out that 38% (!) of bugs could have been prevented by using TypeScript[1].

Another scientific study discovered that TypeScript and Flow could prevent about 15% of bugs in committed code [2]. And these aren't even measuring reduction of bugs in non-committed code!

Stripe is also writing their own type checker for Ruby and engineers have reported an increase in productivity[3].

[1]: https://news.ycombinator.com/item?id=19131272

[2]: https://blog.acolyer.org/2017/09/19/to-type-or-not-to-type-q...

[3]: https://sorbet.run/talks/StrangeLoop2018/#/

Re:TypeScript 3.4 by asark on Saturday March 30, 2019 @01:05PM (#19530496)
Typescript also significantly reduces communication overhead and provides machine-verifiable documentation, making it way easier to figure out WTF is going on with unfamiliar or long-out-of-sight code. People who don't love TS compared with vanilla JS must work entirely differently from me—using it's the only time I've not hated writing JS. Tons of time-wasting poking about and background anxiety just gone. It's great, and costs almost nothing.
Re:TypeScript 3.4 by phamilton on Saturday March 30, 2019 @01:26PM (#19530609)
Typescript is a gamechanger with generated interfaces. We use it heavily with an RPC framework and pulling down the generated client and server packages have drastically minimized integration issues.

It just takes away the mental overhead of making something conform to a spec. It probably doesn't save us much on production bugs, but it makes development faster.

Re:TypeScript 3.4 by jondubois on Saturday March 30, 2019 @02:46PM (#19531041)
Generated interfaces are an anti-pattern. Types force tight coupling between clients and servers. What if a third-party project written in a different language wants to communicate with your server using their own client? Types will make it more difficult for them to integrate because:

1. If they're using a dynamically typed language, this gives them extra work to typecast everything back and forth whenever they need to communicate with your system.

2. Even if they use types, maybe their type system is not compatible with yours and they need to do a lot of tedious extra work to typecast everything.

Re:TypeScript 3.4 by asark on Saturday March 30, 2019 @03:18PM (#19531215)
Huh? Everything always has a type anyway. It's sometimes just harder to know what it is. Specifying doesn't make the types appear out of nowhere, it just documents them.
Re:TypeScript 3.4 by true_religion on Saturday March 30, 2019 @03:21PM (#19531233)
I wouldn't call that an antipattern.

I treat other systems like I do the database and enforce consistency at the API level.

I wouldn't ask for a database to be totally untyped (and thus silently coerce things into its internal types in reality), so I don't ask for the same in an API.

Though, I can understand some people have differing preferences---MongoDB is popular for example---but I wouldn't call it an anti-pattern no matter which choice one makes.

Re:TypeScript 3.4 by tom_ on Saturday March 30, 2019 @05:45PM (#19532078)
No, it makes it easier, because they have a specification to work from, and they can probably just use that spec to generate their own glue code, assuming any is necessary.

I have never found option 2 to apply in any meaningful fashion, though I'm sure others have done much more of this type of work than I have.

Re:TypeScript 3.4 by phamilton on Sunday March 31, 2019 @08:11AM (#19535186)
I've found it to be annoying in the other direction. A type system like protobuf isn't rich enough for the problem domain. We end up building a lot of additional validation into the servers and clients that could have been enforced by the service/types spec.
Re:TypeScript 3.4 by phamilton on Sunday March 31, 2019 @08:03AM (#19535176)
Which is why our rpc services accept json in addition to protobuf. Yay, problem solved.
Re:TypeScript 3.4 by zwerdlds on Saturday March 30, 2019 @03:14PM (#19531195)
what is the solution? runtime errors?
Re:TypeScript 3.4 by jondubois on Saturday March 30, 2019 @02:31PM (#19530942)
>> In Airbnb, they found out that 38% (!) of bugs could have been prevented by using TypeScript[1].

I don't buy these hypotheticals and also I don't believe in this kind of anecdotal evidence.

I think that the real root problem is that they didn't break down the code into logical components and didn't test them correctly - That was the real problem, not JavaScript.

When you look at reports of bug density across large samples of projects, it's clear that TypeScript does not solve any problems. See https://medium.com/javascript-scene/the-shocking-secret-abou...

Re:TypeScript 3.4 by frankpf on Saturday March 30, 2019 @02:51PM (#19531072)
> I don't buy these hypotheticals and also I don't believe in this kind of anecdotal evidence.

The only anecdotal evidence I've linked is Stripe's experience with Sorbet. The paper linked is an actual scientific analysis with great study design. I couldn't find the Airbnb slides or talk but an engineer involved claims the study was carefully designed[1].

> When you look at reports of bug density across large samples of projects, it's clear that TypeScript does not solve any problems. See https://medium.com/javascript-scene/the-shocking-secret-abou....

Go read the "study" referenced in that article. It's just blog post with a terrible methodology. It's basically

(number of issues with bug label) / (lines of code)

The author doesn't even normalize for LOC (larger codebases tend to have more bugs) or take into account project complexity.

[1]: https://twitter.com/swyx/status/1094857103863209985

EDIT: add disclaimer about airbnb talk

Re:TypeScript 3.4 by z3t4 on Saturday March 30, 2019 @04:30PM (#19531653)
I would love to read the Airbnb study. Do you have a reference ?

The other study you referred to sponsored by Microsoft is very vague on the methods used to conduct the experiment. So its not repeatable. You can't say something is scientifically true unless the results are repeatable.

Re:TypeScript 3.4 by keymone on Saturday March 30, 2019 @03:37PM (#19531320)
the problem with study like airbnb is that while tooling would have caught X% of bugs of type A, it in no way means those wouldn't just be replaced by bugs of type B.

bugs are (in part) function of code and tooling complexity, making some bugs harder to introduce doesn't reduce that complexity. risk compensation principle is another factor, and so on.

i haven't yet seen strong evidence that static typing really reduces bug density.

Re:TypeScript 3.4 by int_19h on Saturday March 30, 2019 @03:10PM (#19531165)
Eric Elliott has been making claims like these for years now. You can see the comments here taking apart the last round (which was more substantiated than the one you linked to).

https://news.ycombinator.com/item?id=18977700

Re:TypeScript 3.4 by tjenkinsqs on Saturday March 30, 2019 @11:52AM (#19530012)
You make some valid points on DI, linting, etc. but your first point on Typescript itself not providing value is pure FUD. Typescript catches a TON of bugs and the ones that are the most frequent https://rollbar.com/blog/top-10-javascript-errors/.

That we as an industry ship code (Javascript) to production that still has bugs that are so easy to catch at compile time does not reflect well on us, and your comment really does not help in this regard. What is your recommendation to ensure we catch more bugs at compile time rather than letting users find out that their application doesn't work?

Re:TypeScript 3.4 by z3t4 on Saturday March 30, 2019 @05:19PM (#19531926)
I think the most effective way to find a bug in a program is to demo it in-front of a crowd. Or let grandpa use the program. Jokes aside, I think the most effective way to catch bugs is to have many people read (and understand) the code, and also have many users hit the code paths, most bugs will reveal themselves given enough time. Well used/tested code is often referred to as "hardened".

You wanted to find the bugs before shipping it to users, and that is also what I used to pursue, but when you let a ton of users hit your code, they will find the issues way faster then you could. It's however important to log, and debug all errors, and have a channel for users to submit issues. Sure it will be annoying for the user when he/she stumbles on a bug, but you will regain the goodwill when you fix his/her issue. In most software, even today, users are used to wait months, and even years, or infinitely, to have a bug/issue fixed. So it's a lot of "WOW! Thanks" And very little "I will sue your ass". Bugs, if you do actually fix them, will have a net positive effect.

Re:TypeScript 3.4 by cryptica on Saturday March 30, 2019 @12:32PM (#19530268)
Quality test coverage. I'm a big fan of having integration tests which cover all the main scenarios which are relevant to your users.

For example, one of my open source projects has about 120 integration test cases in total; these are enough to cover about 10K lines of code (not counting third-party dependencies); if I break any documented feature of the project, it's essentially guaranteed that many test cases will fail - They will catch the smallest issue or inconsistency; even things which are not being explicitly tested.

Integrations tests are great at detecting symptoms. They don't always point exactly at what the problem is, but they are great at letting your know that there is a problem and then you can debug it.

Integration tests are the best way to identify and fix issues in very complex systems. For example, when it comes to medicine and the human body; a thermometer reading is an example of a well-designed integration test case; if your temperature is high, then the doctor knows straight away that you have a problem which needs to be addressed. The doctor will probably not know exactly what the problem is immediately, but nonetheless, that simple thermometer reading (assertion) can allow them to detect the symptom of an essentially infinite range of possible underlying issues. One test case is not enough to cover all possible health problems, but the enormous amount of internal coverage that this single test case provides is unfathomable. We ought to try to come up with such test cases in our code.

If you have good integration tests, it doesn't really matter what language you use because (in terms of identifying issues) everything else pales in comparison.

Also it's important to note that integration testing doesn't necessarily mean end-to-end testing. You can still mock certain external components or engines in order to get more stability in your tests and you can still get that same kind of leverage.

Re:TypeScript 3.4 by guscost on Saturday March 30, 2019 @02:42PM (#19531005)
How long does your integration test suite take to run? I have (many) typed interfaces and an editor running the language server. Typos, bad imports, etc are highlighted instantly and inline so they get fixed right away. Even better, autocomplete and refactoring tools know about these types, so typos and refactoring mistakes are vanishingly rare in the first place.

I agree that this does not replace integration tests or manual QA (dependencies can break and not every behavior can be checked). But as a lever for increasing productivity, a type system (even with the added complexity) is unbeatable.

Basically my point is that you aren’t actually catching errors at compile time, you’re catching them at build time. Your workflow might provide the same guarantees for the code that gets deployed to production, but writing that code is probably less enjoyable and you’re probably less productive than you could be.

Re:TypeScript 3.4 by true_religion on Saturday March 30, 2019 @01:20PM (#19530580)
You can not compare PR counts for Typescript to the Linux kernel.

The Linux kernel does not accept Github pull requests for development. If you try it, it will respond with this friendly message:

Linux kernel development happens on mailing lists, rather than on GitHub - this GitHub repository is a read-only mirror that isn't used for accepting contributions. So that your change can become part of Linux, please email it to us as a patch.

Re:TypeScript 3.4 by coolreader18 on Saturday March 30, 2019 @08:04PM (#19532798)
Yeah, do they really think that Linux has only ever had 300-something pull requests?
Re:TypeScript 3.4 by veidr on Saturday March 30, 2019 @01:15PM (#19530551)
> All evidence points to the fact that TypeScript does not have any positive effect on bug density. Its value is purely subjective and speculative.

That is one of the weirder statements I've come across on this website.

First of all, there are tons of analyses publicly available — from well-known companies like Lyft, Airbnb, etc. — that document reduction in software defects solely from TypeScript's compile-time checks. (Source: uh, Google "TypeScript".)

Second, it is virtually impossible to code for a day in TypeScript without it catching bugs. Granted, many of them would be bugs that you would have caught as soon as you ran your program, but TypeScript catches them while you type them so you never do run the program with that bug.

(That's the secret actual reason it's named Type Script.)

Re:TypeScript 3.4 by ncphillips on Saturday March 30, 2019 @02:30PM (#19530935)
> starting a Typescript project is like accepting unnecessary complexity from the beginning

Dynamic typing is what really hides complexity. The higher order component pattern in React is a prime example. What seems like a simple idea is revealed to be extremely complex once you try to implement it using Typescript. Writing the types is a great way to get feedback on how complex your abstractions really are.

Deciding to use Typescript is about making a commitment to reveal and deal with unnecessary complexity from the beginning.

Re:TypeScript 3.4 by veidelis on Saturday March 30, 2019 @05:49PM (#19532096)
Especially true for generic types
Re:TypeScript 3.4 by faitswulff on Saturday March 30, 2019 @11:42AM (#19529952)
> To put it into perspective, the Linux project has only had about 380 PRs on GitHub.

IIRC Linux does not use GitHub for project management or as a source of truth, only as a mirror.

Re:TypeScript 3.4 by thomasfedb on Saturday March 30, 2019 @11:51AM (#19529999)
This. Comparison with Linux is laughable, there have been orders of magnitude more patches to Linux than there are PRs on their GitHub.
Re:TypeScript 3.4 by vimslayer on Saturday March 30, 2019 @12:43PM (#19530349)
Yep, Linus has been quite vocal about his distaste for GitHub pull requests.

https://github.com/torvalds/linux/pull/17#issuecomment-56546...

Re:TypeScript 3.4 by thomasfedb on Saturday March 30, 2019 @01:22PM (#19530589)
Interesting how Linus's replies look ridiculous on the GitHub interface (at least on mobile) because he hard-wraps his paragraphs.

Particularly when half his gripe with GitHub is not hard-wrapping commit messages.

Re:TypeScript 3.4 by sebazzz on Saturday March 30, 2019 @12:11PM (#19530133)
Type safety has been proven to increase programmer productivity long-term, allows code to be partially self documenting and prevents bugs. I don't think that we need that discussion again.

But in general I agree with you. If you adopt a tool, any tool, any framework you need also think about the learning curve and overhead you impose on the next developer and yourself. This is especially true if something goes wrong, you run into issues and you need to troubleshoot it.

Re:TypeScript 3.4 by koolba on Saturday March 30, 2019 @12:13PM (#19530145)
> There has never been a worse time to be a software developer.

Quite the opposite! CPU and memory are cheap, FOSS is everywhere, and now more than ever its possible to create massive applications all on your own.

> Practically all of the most popular tools encourage anti-patterns, add unnecessary complexity or solve superficial problems instead of focusing on critical problems that exist in today's software projects.

> - TypeScript ...

TypeScript solves many problems with real world JavaScript applications at scale (code scale, not user scale!). Static type checks and interface validation are powerful tools. They lead to both more correct programs and faster development.

> - Code coverage tools like Istanbul and others add very little value to projects. 100% coverage is not a useful goal to have, in fact it's counterproductive. When it comes to test coverage, quality of that coverage is WAY more important than quantity (this cannot be over-emphasized). Did you test all the right inputs? Do the tests focus on the most important code paths (and those which are more complex and therefore more likely to fail)? I'd rather have 10% quality coverage of the right parts of the code than 100% poor quality coverage. Also, you need to take into account that the more unit test coverage you have, the harder it is to make changes to your code.

Depends on the type of code being checked. For a library meant to cover a huge number of permutations a coverage report can be useful. It's not a panacea for general application development. With static type checks a lot of the value of code coverage iseliminated as an entire class of errors is handled by the compiler (ex: "foobar" mispelled as "foobuz").

> - Linting tools such as ESLint/TSLint: These tools can be very nice if used correctly and not treated as a silver bullet for all programming problems. We should never forget that linters can only detect superficial problems.

That's literally the job of linting tools. To catch superficial problems as they're often a symptom of real problems. An unreferenced variable is either dead code (at best) or broken logic. Bad formatting and indentation could be purely cosmetic or a massive security issue (GOTO fail...). It's not going to tell you that your binary search is totally correct, but it will tell you if you forgot to reference the "high" variable entirely.

Re:TypeScript 3.4 by phamilton on Saturday March 30, 2019 @01:33PM (#19530646)
Tslint has in some cases evolved as a compiler extension. Things like "no-floating-promises" are huge and only really possible with sufficient type information.
Re:TypeScript 3.4 by skybrian on Saturday March 30, 2019 @11:48AM (#19529985)
Unfortunately, many popular projects get a lot more bug reports than the team can deal with. While this is annoying, it's mostly a measure of popularity, not quality. (Or at least, you need to adjust for popularity.)
Re:TypeScript 3.4 by elliotec on Saturday March 30, 2019 @01:10PM (#19530526)
> There has never been a worse time to be a software developer

> I used to roll my eyes when I read comments like this

Yeah, I rolled my eyes so hard at this comment, it hurt.

Re:TypeScript 3.4 by jen20 on Saturday March 30, 2019 @12:22PM (#19530209)
Specifically addressing the “reducing complexity by adding complexity on top” point: the complexity is there whether you like it or not. The choice is whether it should be explicit and thus (to some degree) verifiable, or implicit and waiting to bite at runtime. TypeScript is a very solid improvement over JavaScript for this reason.
Re:TypeScript 3.4 by nlawalker on Saturday March 30, 2019 @12:38PM (#19530312)
In your opinion, what are the critical problems that exist in today's software projects?
Re:TypeScript 3.4 by jondubois on Saturday March 30, 2019 @12:51PM (#19530410)
Unclear separation of concerns between components.

This is more of a problem for back end projects. Front end web development frameworks tend to enforce certain architectural constraints so there isn't much margin for error there but back ends and other complex projects are often terrible when it comes to assigning clear and distinct responsibilities across components.

Re:TypeScript 3.4 by melling on Saturday March 30, 2019 @12:02PM (#19530072)
Any thoughts on ReasonML, Scala.js, Purescript...

The functional attempts at Javascript

Re:TypeScript 3.4 by chessturk on Saturday March 30, 2019 @07:25PM (#19532625)
It only gets interesting to me when browsers (or for that matter node) get tail-call optimization.

Until then iteration makes way more sense than recursion in JS.

Re:TypeScript 3.4 by vimslayer on Sunday March 31, 2019 @01:48PM (#19536993)
I don't quite understand what that has to do with the parent commenter's language suggestions. Simple TCO is easy to implement in the compiler level. ReasonML, for example, is quite capable of optimizing the usual recursive fibonacci example into a while loop [1].

[1]: https://reasonml.github.io/en/try.html?rrjsx=true&reason=DYU...

Re:TypeScript 3.4 by billions on Saturday March 30, 2019 @10:51PM (#19533466)
100% agree. Simplicity. Big picture focus.

The buzzwords & flashy libraries add incremental value over ES6 with large organizational migration costs. For example 90% of Redux code is useless and a liability. But, devs think it’s cool and devs get what they want. Businesses will let devs tinker instead of loosing them. Hence complexity, inefficiencies and egos.

Build something useful in the simplest way possible.

P.S. When I write Typescript I NEVER get caught by the compiler because I KNOW what fucking type my variables are. There’s only a of handful natives becau se this aint C and my object instances are always well named.

Re:TypeScript 3.4 by equasar on Sunday March 31, 2019 @03:02PM (#19537548)
I bet the majority of programmers don't write perfect code like you. But hey, no one is forcing you to use Typescript or any other library that requires you to stop using vanilla JavaScript or makes something so over complicated for you.

It is just like the CLI vs GUI thing, people want choices.