News for hackers. Stuff that matters.
Re:Yarn's Future – v2 and beyond by ianwalter on Thursday January 24, 2019 @12:02PM (#18990466)
Maybe it's a benefit when moving from Flow, but personally, I would rather have JS projects spend that time adding more tests than converting to static typing.

Edit: changed strong to static.

Re:Yarn's Future – v2 and beyond by mason55 on Thursday January 24, 2019 @12:25PM (#18990711)
The two are completely unrelated. When I was writing vanilla JS it felt like half my tests were just focused on ensuring that everything remained the type it was supposed to be. Not in a static type sense but in a duck type sense at least - does this object still have field X? Can I still call function Y on this object? Is this variable still defined?

All those kinds of tests can be eliminated with static typing. It's true that a lot of those types of errors would get picked up in functional tests, but at least from my perspective it's not great practice to rely on a functional test to catch that kind of change. If your functional test changes it's easy to lose coverage of your basic unit tests that were only happening implicitly.

Re:Yarn's Future – v2 and beyond by ianwalter on Thursday January 24, 2019 @12:28PM (#18990761)
Funny how you say the two are completely unrelated and then go on to show how they are related with your personal experience.
Re:Yarn's Future – v2 and beyond by eyelidlessness on Thursday January 24, 2019 @02:10PM (#18991882)
While you're technically correct, this misses the value of static type checking vs type checking in tests. Tests must be written manually, must check every code path and must be updated whenever the underlying implementation changes, in order to achieve the results of static type checking. But types are declarative and will be checked automatically for every code path called.
Re:Yarn's Future – v2 and beyond by amikazmi on Thursday January 24, 2019 @02:40PM (#18992156)
1. If you dob't have tests covering code, sure type checks are better than nothing. but if you do, why do you also need type checks?

2. If the tests must be updated whenever the underlying implementation changes it might be testing too much- it's better to test behaviour, not implementation.

Re:Yarn's Future – v2 and beyond by eyelidlessness on Thursday January 24, 2019 @02:56PM (#18992312)
I was addressing the above comments about tests that specifically check types. My position is that declarative types and a type checker are better because each code path is checked automatically without writing additional tests, and because the type checker automatically adapts without changing or writing new tests when the implementation changes. Testing behavior is another thing entirely.
Re:Yarn's Future – v2 and beyond by ianwalter on Thursday January 24, 2019 @03:33PM (#18992630)
I'm not missing the value we just have a different idea of what that value is, but anyway, this is a different, more specific topic than the one I originally brought up and one that I don't feel like engaging in.
Re:Yarn's Future – v2 and beyond by eyelidlessness on Thursday January 24, 2019 @03:56PM (#18992863)
I think it exactly addresses your original topic, but you're in no way obligated to engage it further. Have a nice day!
Re:Yarn's Future – v2 and beyond by jakelazaroff on Thursday January 24, 2019 @12:13PM (#18990594)
Static types are a form of test!
Re:Yarn's Future – v2 and beyond by lucisferre on Thursday January 24, 2019 @12:22PM (#18990669)
They are a compile time contract at best, they are nothing like a test.
Re:Yarn's Future – v2 and beyond by coldtea on Thursday January 24, 2019 @12:54PM (#18991036)
Test and compile time contracts both check invariants.

Abstractly speaking, there's no big conceptual chasm that separates a test in a test suite from a test the compiler makes.

Re:Yarn's Future – v2 and beyond by mort96 on Thursday January 24, 2019 @12:27PM (#18990745)
A lot of tests end up testing things which would've been caught by the type system. Static and strong typing doesn't make tests in general unnecessary, but it does mean you don't need quite so many trivial tests.
Re:Yarn's Future – v2 and beyond by Sammi on Thursday January 24, 2019 @12:36PM (#18990842)
Half the tests I write for Javascript code are type tests. Typescript does that much better.
Re:Yarn's Future – v2 and beyond by azangru on Thursday January 24, 2019 @12:29PM (#18990772)
They are checking the shape of inputs and outputs, making it unnecessary to test that a function returns a value of a particular type or that this value has particular fields. They make sure you don't make stupid mistakes, leaving it up to you to test really valuable bits of logic.
Re:Yarn's Future – v2 and beyond by starefossen on Thursday January 24, 2019 @02:03PM (#18991820)
Static types most definitely do not replace the need for tests!
Re:Yarn's Future – v2 and beyond by jakelazaroff on Thursday January 24, 2019 @02:26PM (#18992024)
Agreed! They replace the need for specific kinds of unit tests, e.g. making sure your functions accept and return the correct shapes. You still need to test the actual logic, and should be doing some sort of integration test on the application as a whole.

In retrospect, my original response was too terse. Static typing and testing serve the same purpose, which is to make sure your application runs according to some measure of correctness. We shouldn't be setting up one-or-the-other dichotomies — we can have both!

Re:Yarn's Future – v2 and beyond by ianwalter on Thursday January 24, 2019 @03:43PM (#18992729)
But it misses the point I was originally making. I was not suggesting they are mutually exclusive.
Re:Yarn's Future – v2 and beyond by jakelazaroff on Thursday January 24, 2019 @05:27PM (#18993681)
My interpretation of your point was that unit tests are more valuable than static types, and I don't think that's necessarily true. They're both forms of testing, and it's important to recognize their strengths and weaknesses.

Static types won't help with your application logic, but they will (for example) ensure your function inputs and outputs are the correct types, help document your code and ensure consumers call your code correctly. Unit tests can only do the first one, and it's more verbose and brittle.

Re:Yarn's Future – v2 and beyond by asnrk on Thursday January 24, 2019 @02:22PM (#18991992)
Your statement and the one you're responding to are wholly compatible.
Re:Yarn's Future – v2 and beyond by enraged_camel on Thursday January 24, 2019 @12:28PM (#18990760)
They aren’t, and it’s detrimental to think of them that way.
Re:Yarn's Future – v2 and beyond by aylmao on Thursday January 24, 2019 @01:55PM (#18991723)
Why do you think so? I think they're better than equivalent tests, and in fact help bring about better testing.

A lot of unit tests will revolve around checking types. If you don't have to runtime-check this, you can focus unit tests on semantics and integrations assuming the underlying data structures are correct.

Re:Yarn's Future – v2 and beyond by fingerlocks on Thursday January 24, 2019 @01:37PM (#18991515)
Just a nitpick, but Typescript adds static typing, not strong typing. The types are still weak because implicit type conversions still exist:

  const x = "one two" + 3;
Re:Yarn's Future – v2 and beyond by mevile on Thursday January 24, 2019 @01:45PM (#18991607)
I think you can make either your typescript or tslint config error out on this at compile time. I think this is configurable.
Re:Yarn's Future – v2 and beyond by janpot on Thursday January 24, 2019 @12:11PM (#18990572)
sounds like their primary goal is 'attract more contributions' rather than 'strengthen the type system'.