News for hackers. Stuff that matters.
Re:Yarn's Future – v2 and beyond by yaseer on Thursday January 24, 2019 @11:40AM (#18990229)
The JS ecosystem has its flaws, but one has to appreciate the speed at which momentum shifts, making clear winners obvious.

The move towards TypeScript 'winning' has been fast, and to everyone's benefit.

Re:Yarn's Future – v2 and beyond by wanted2 on Thursday January 24, 2019 @01:52PM (#18991695)
> , and to everyone's benefit.

Why? I've worked on large codebases in Coffeescript, ES6 and Typescript. Whatever this whole community sings and believes, but Coffeescript still wins for me. ES6 is still trying to catch up but will probably never reach the beauty and ease of Coffeescript. Both are transpilers, only ES6 with Babel is a total horror to manage (just upgraded a large codebase to Babel 7..).

Typescript takes about 2x the time to write if you want to create all your typings properly. I hear you say; only in the beginning, later it will speed up the development process. I've never seen that in reality! I've actually never seen a proper codebase in Typescript. Show me a Typescript codebase not using the type 'any'! In a decent system language you can't get away with that, it's just a fake sense of security.

A good codebase should not be dependant at all by Typescript or whatever hype comes next. Writing a good codebase is IMHO a craft and should not depend on the language or a bunch of tooling. If Typescript is way to go, what about Python, Ruby, abandon it, deprecated? Are those inferior languages compared to Typescript? Typescript is just another hype, very smart play by Microsoft btw.

Re:Yarn's Future – v2 and beyond by ng12 on Thursday January 24, 2019 @02:10PM (#18991873)
> Typescript takes about 2x the time to write if you want to create all your typings properly.

Not true at all. You balance all of this stuff inside your head anyways: this object has this shape, this function takes these arguments, etc. The only overhead is actually writing them down -- which in itself arguably speeds up development because then your IDE knows about them too.

I pushed back migrating from Coffeescript to TypeScript and I consider it one of the only times I was really wrong about a front-end technology.

Re:Yarn's Future – v2 and beyond by eleclady on Thursday January 24, 2019 @02:11PM (#18991888)
> I've actually never seen a proper codebase in Typescript.

That's the problem then. I have, and have clearly seen in the real world why it's superior. ES6/Coffeescript can obviously be done correctly, but chaos tends to ensue as the flexibility is abused. Over time it makes debugging/understanding difficult. TypeScript makes changing/navigating large codebases a breeze. In other words, it's much easier to do correctly than ES6/Coffeescript.

Re:Yarn's Future – v2 and beyond by yaseer on Thursday January 24, 2019 @02:05PM (#18991842)
There are multiple benefits from having TypeScript a clear winner.

1. One standard typed version of JS (As appose to flow and TypeScript) is a better use of open-source developer time. It also reduces decision fatigue when architecturing new JS projects. 2. TypeScript tooling is fantastic. Using VSCode or Webstorm spoils you. 3. TypeScript is a testing ground for experimental language features. It can shape the direction of future versions of JS. 4. Finally, the language is clearly well liked, in addition to being popular. We can debate the pros and cons of its quirks, but overall, the stats say developer satisfaction is high. https://hub.packtpub.com/4-key-findings-from-the-state-of-ja...

Re:Yarn's Future – v2 and beyond by preommr on Thursday January 24, 2019 @05:54PM (#18993889)
> ES6 is still trying to catch up but will probably never reach the beauty and ease of Coffeescript. Both are transpilers, only ES6 with Babel is a total horror to manage (just upgraded a large codebase to Babel 7..).

...

> Both are transpilers

You don't have to transpile es6 if you don't want older browser support.

Re:Yarn's Future – v2 and beyond by kjaer on Thursday January 24, 2019 @02:28PM (#18992035)
> Show me a Typescript codebase not using the type 'any'! In a decent system language you can't get away with that, it's just a fake sense of security.

I don't know the comparison to system languages is fair though, because the use-case for JS is quite different from system languages.

Javascript (and by extension, Typescript) is commonly used to interface between the user and the network, both of which often are outside the bounds of the type system. Add to that any code that interfaces with plain JS, such as external libraries or legacy code. When dealing with those, it's natural to use statically untyped values and type ascriptions based on reasonable assumptions.

Taking that into account, I actually think Typescript's type system is fairly well-designed for the use-case. The problem isn't really with Typescript, it's just intrinsic to the use-case of JS.

Re:Yarn's Future – v2 and beyond by s_tec on Thursday January 24, 2019 @06:13PM (#18994016)
Exactly. Even strongly-typed languages have this problem. In C, it looks like `void *`, while in Java, it's `Object`. The `any` keyword is just the latest in a long line of escape hatches. Pretty much every language has one.
Re:Yarn's Future – v2 and beyond by dragonwriter on Thursday January 24, 2019 @06:16PM (#18994030)
> Even strongly-typed languages have this problem. In C

C is clearly statically typed, but among statically typed language it is quite weakly typed.

Re:Yarn's Future – v2 and beyond by linkmotif on Thursday January 24, 2019 @02:12PM (#18991901)
> Show me a Typescript codebase not using the type 'any'!

Show me a Java project without an unchecked cast... I’m not a CS person but my impression is that sometimes you need these types and they exist in the type system for a reason. No type system is conceptually “perfect” as in there are soundness/expressively tradeoffs. I don’t think using ‘any’ is always bad. Sometimes it’s even right?

Re:Yarn's Future – v2 and beyond by int_19h on Thursday January 24, 2019 @08:24PM (#18994719)
There are type systems that don't have anything like "any" - you find that in languages like OCaml or Haskell.

But in TS, the main reason for "any" is interop with JS.

Re:Yarn's Future – v2 and beyond by linkmotif on Thursday January 24, 2019 @08:45PM (#18994828)
Thanks. So in OCaml/Haskell you can write perfectly sound programs?
Re:Yarn's Future – v2 and beyond by chowells on Thursday January 24, 2019 @09:55PM (#18995153)
Haskell's type system still isn't sound. It just elimates that particular class of errors.

A lack of soundness is closely related to the Turing completeness, especially in languages based on HM. In an ideal world you would want a sound type system and not want Turing completeness, but the tooling doesn't exist to make those choices the most pragmatic right now.

Re:Yarn's Future – v2 and beyond by int_19h on Thursday January 24, 2019 @09:08PM (#18994951)
Well, I mean, you can write perfectly sound programs in Java as well, or in TS. It's rather a question of how hard/easy it is to do so. Technically, any language that has either direct memory manipulation or FFI has the potential to do unsound things about types, but it takes a lot more effort.
Re:Yarn's Future – v2 and beyond by Perseids on Thursday January 24, 2019 @03:14PM (#18992475)
> Writing a good codebase is IMHO a craft and should not depend on the language or a bunch of tooling.

Of course, relative to other code in that language you can write good code in any language and that is a useful and important skill. If you invest enough energy and craft, you can even write code that compares favorably to good code in any language - the Linux code base is a testament to that. Still, it is a fallacy to assume that all languages are created equal. Nowadays, next to nobody would argue that writing code in Assembler is a good idea. And even though it is now possible to write web apps with C (via webassembly) there is no movement by seasoned C programmers to conquer the web.

> If Typescript is way to go, what about Python, Ruby, abandon it, deprecated? Are those inferior languages compared to Typescript? Typescript is just another hype, very smart play by Microsoft btw.

While the truism "use the right tool for the job" is overrated, it applies here. Untyped, quick to write languages are excellent for small projects. When I'm writing Python as glue code, designing nicely typed interfaces is a distraction. Also, Python, Ruby and Javascript have base types with excellent usability. E.g. when you parse time sheet data, it is pleasant to return [(time.parse('9:00'), 'document project X'), (time.parse('10:15'), 'implement feature Y')]. But when projects grow every structure enforced by the language is a guarantee I cherish. You know, there is this special case in your time sheet parser where you return a (time.parse('23:59'), Null) element, instead of using the empty string, which made the code much more elegant. But months later, when you are refactoring the code calling the parser, you have totally forgotten this behavior and introduce a subtle bug. That's the time where I wish I had a robust type system.

TypeScript is great in this regard, as you can ignore all types if you wish and gradually add them later, when the complexity of the code base calls for it. Or you start with complete type coverage from the start if that floats your boat. Or you never introduce types and just consume JavaScript. Because of that, TypeScript is especially valuable for libraries: It gives the consumers of the libraries all choices. And it's also the reason the success of TypeScript is celebrated that much: Each new TypeScript enhanced library increases the effectiveness of the tool (and reduces the amount of `any` crutches).

Re:Yarn's Future – v2 and beyond by bluepnume on Thursday January 24, 2019 @10:19PM (#18995259)
> Show me a Typescript codebase not using the type 'any'!

https://github.com/krakenjs/zoid

Admittedly Flow, not TypeScript -- but 99% the same thing syntax-wise. And yes -- it was difficult to set up and get working comprehensively, but now it's there, it's fairly easy to maintain, and it's invaluable when refactoring, accepting PRs, or adding new features.

Most people using `any` should really be using `mixed` (flow) or `unknown` (ts) which at least force you to check before you use some property of those types.

Re:Yarn's Future – v2 and beyond by ex3ndr on Thursday January 24, 2019 @02:01PM (#18991800)
We are doing backend and frontend in Typescript and have very limited 'any' usage. Mostly for some hacky library for some small isolated need.

I can the same way cast value to an Object in Java of NSObject in Swift.

Re:Yarn's Future – v2 and beyond by ggregoire on Thursday January 24, 2019 @03:15PM (#18992485)
Do you have any experience with static typed languages? All the benefits brought by static typing become obvious & make sense when you actually get to use it.

Also, I'm sorry but you make some weird comparisons. ES6, Coffeescript, TypeScript and Python/Ruby are 4 completely different things. Not sure why you are trying to compare them and choose a winner.

Re:Yarn's Future – v2 and beyond by Waterluvian on Thursday January 24, 2019 @04:33PM (#18993219)
I agree with your sentiment but I find the location of it almost ironic. One thing I hate is when I go into a language and it's full of, "oh don't use the built-in, use this thing over here...".

If we want a clear winner to everyone's benefit, wouldn't we want Yarn to go away and for npm to gain whatever it's missing that makes Yarn relevant?

To be fair, I haven't touched Yarn in years. I switched to it, loved it, and then npm got the package-lock and some performance fixes and I suddenly didn't understand why I'd want to use Yarn.

I'm conflicted because on one hand I strongly believe that we're all better off using the same tools so we can help each other more easily. But that suggests that alternatives shouldn't exist, which stymies innovation.

Re:Yarn's Future – v2 and beyond by s_tec on Thursday January 24, 2019 @06:30PM (#18994110)
I get what you are saying, but the two cases are different. Typescript is a whole different language from Flow, so they can't interoperate. Every package that migrates to Typescript deprives the Flow ecosystem of compatibility and mindshare, so a win for one is always a loss for the other. Nobody wants to be a loser, so this will eventually resolve itself into a single dominant choice.

NPM and Yarn don't have this problem, since they are pretty much drop-in replacements for each other. As long as `yarn install` and `npm install` both get the job done equally well, picking one becomes a personal choice. Every project that adopts a standard package.json is a win for both NPM and Yarn. There doesn't need to be a loser in this case, and diversity is good.

Re:Yarn's Future – v2 and beyond by Waterluvian on Friday January 25, 2019 @06:45AM (#18997207)
That's a really good point. Thanks for sharing. Drop in alternatives can be healthy and not that harmful. It's not like we are locked into two separate camps.
Re:Yarn's Future – v2 and beyond by bouncing on Thursday January 24, 2019 @12:05PM (#18990501)
Do people typically prefer TypeScript over ES6?
Re:Yarn's Future – v2 and beyond by ggregoire on Thursday January 24, 2019 @12:34PM (#18990822)
It's a strange question. Writing in TypeScript is almost identical to writing in ES6. TypeScript is "just" ES6 with interfaces and static types.

Do people prefer typed JavaScript over JavaScript tho? I know that I prefer typed JavaScript, especially to write long-term web applications or Node.js server applications, but I don't think there is yet an unanimous shift towards typed JavaScript.

Re:Yarn's Future – v2 and beyond by bouncing on Thursday January 24, 2019 @01:28PM (#18991418)
> Do people prefer typed JavaScript over JavaScript tho?

I'd like dynamic typing but without the implicit and dubious type coercion. Like Python.

Re:Yarn's Future – v2 and beyond by chaostheory on Thursday January 24, 2019 @12:23PM (#18990689)
Coming from a background of being comfortable with Ruby, Python, and Java; I started with ES6 a few years ago and moved over to Typescript last year. While ES6 makes Javascript much nicer, Typescript makes it way better and easier to maintain especially with a decent IDE. I already had a lot of respect for Javascript developers previously, but when I started developing node apps with ES6 it grew even more. I can only imagine the discipline needed to maintain large Javascript apps before ES6 and Typescript
Re:Yarn's Future – v2 and beyond by WorldMaker on Thursday January 24, 2019 @12:23PM (#18990690)
There's not really a competition between ES6 and Typescript because they are generally on the same side. Typescript is mostly just ES6 (ES2015) + Types. (It also supports ES2016 + Types, ES2017 + Types, and ES2018 + Types, and generally as TC39 proposals make it to at least Stage 3 Typescript adds support for them.)
Re:Yarn's Future – v2 and beyond by cphoover on Thursday January 24, 2019 @04:06PM (#18992969)
I'm a fan of functional programming over OOP as such, I don't need all of the OOP constructs just give me some immutable primitives, first-class functions and let's get to work.

There's not much I can do with a class that can't be accomplished with a simple function.

I think I've evolved in my thinking over this in the last several years of experience.

Re:Yarn's Future – v2 and beyond by fold_left on Thursday January 24, 2019 @04:56PM (#18993432)
You can continue to code the way you've been enjoying, just with the option to type your inputs and outputs if you choose to. Writing classical OOP isn't imposed on you by TypeScript, nor do you miss out on anything by not writing classical OOP.
Re:Yarn's Future – v2 and beyond by Siilwyn on Thursday January 24, 2019 @05:04PM (#18993499)
Typescript doesn't support typings for functional concepts that libraries like Ramda & Sanctuary use though.
Re:Yarn's Future – v2 and beyond by fold_left on Thursday January 24, 2019 @05:37PM (#18993759)
That's also true. TS has more to do to improve working with functional JS.
Re:Yarn's Future – v2 and beyond by BMorearty on Thursday January 24, 2019 @12:12PM (#18990580)
From what I've seen, yes.

I'm a big fan of ES6 and I haven't been a fan of typed languages for a long time but I'm liking using TypeScript. So are my coworkers.

Re:Yarn's Future – v2 and beyond by dak1 on Thursday January 24, 2019 @12:26PM (#18990732)
Since we all tend to live in bubbles to some extent, do we have any numbers to back this up (like, # of repos/commits in each language on GitHub, or questions on StackOverflow)?

I tend to view TypeScript similar to CoffeeScript — it brings to JavaScript some features from other languages that are convenient and preferred by a subset of frontend developers. It allows for experimentation in the language, and helps inform TC39 proposals.

In time, I suspect support will coalesce around a specific TC39 process proposal to add type support, it will graduate to stage 3 or 4, get integrated into browsers and Babel, and enthusiasm around TypeScript will wane.

Re:Yarn's Future – v2 and beyond by dangoor on Thursday January 24, 2019 @12:32PM (#18990793)
A flexible type system like that of TypeScript is pretty big and complex. It would take considerable time and effort to get that through TC39, I think. It could happen, but seems far off to me.

For data, 46% of npm's survey respondents used TypeScript: https://blog.npmjs.org/post/180868064080/this-year-in-javasc...

Re:Yarn's Future – v2 and beyond by mhd on Thursday January 24, 2019 @01:26PM (#18991400)
I'd prefer Eiffel or Oberon, but almost anything is better than ES6. I just wish there was some kind of standard library movement to coincide with it, but even MS seems okay with left-pad.
Re:Yarn's Future – v2 and beyond by chaostheory on Thursday January 24, 2019 @03:04PM (#18992386)
> I just wish there was some kind of standard library movement to coincide with it,

I keep hearing this complaint, and at the same time I'm wondering why it's a big problem. So you can't find 3rd party libraries that are good enough to fill in the void from the lack of a good standard library?

Re:Yarn's Future – v2 and beyond by mhd on Friday January 25, 2019 @12:55AM (#18995881)
Yes, pretty much. I don’t want to bikeshed elementary parts of the developer experience, never mind vetting all the teeny components or find replacements if dependency hell strikes, quality regresses or maintainers disappear.

Given all the constraints, it’s highly unlikely that you find something consistent.

Re:Yarn's Future – v2 and beyond by chaostheory on Friday January 25, 2019 @01:57PM (#19001144)
So you write your own standard library substitutes? Math, functional, etc...?
Re:Yarn's Future – v2 and beyond by iamjaredwalters on Thursday January 24, 2019 @01:34PM (#18991473)
ES5 is not better than ES6. So I prefer ES6 in that case.
Re:Yarn's Future – v2 and beyond by RobertKerans on Thursday January 24, 2019 @04:28PM (#18993168)
> even MS seems okay with left-pad

That's a strange choice of example to highlight the sparseness of the standard library.

Re:Yarn's Future – v2 and beyond by mhd on Friday January 25, 2019 @02:51AM (#18996278)
I thought it's a good illustration of how fractured and fragile the JS "library" situation is. It's a bit like the previous PHP standard library, combined with the worst of Perl's Tim Toady.
Re:Yarn's Future – v2 and beyond by RobertKerans on Friday January 25, 2019 @10:57AM (#18999037)
The reason I say it's a strange example is because of this: https://github.com/tc39/proposal-string-pad-start-end, which was added to the language two years ago (and seemingly very quickly [as tc39 proposals go], I assume due to left-pad)
Re:Yarn's Future – v2 and beyond by diminish on Thursday January 24, 2019 @02:10PM (#18991879)
Noone around me does. Typescript and JSX are the two ugliest tech to become fashionable recently. I suspect C#, or .NET developers find it familiar, and they've just joined the front end wagon.
Re:Yarn's Future – v2 and beyond by ng12 on Thursday January 24, 2019 @02:15PM (#18991927)
I've had the opposite experience. I don't know anyone not writing Typescript.
Re:Yarn's Future – v2 and beyond by irrational on Thursday January 24, 2019 @03:15PM (#18992477)
I don't know anyone using it either (and I work for IT in a Fortune 100 company). But there must be since I keep seeing people mention it.
Re:Yarn's Future – v2 and beyond by mort96 on Thursday January 24, 2019 @12:25PM (#18990710)
One huge thing we're giving up when moving from JS to TS is iteration speed though. The typescript compiler is not only an additional step, it's also ridiculously slow compared to other languages' compilers.
Re:Yarn's Future – v2 and beyond by jchw on Thursday January 24, 2019 @12:39PM (#18990880)
Disagree. The TypeScript compiler is quite fast even on large projects. Build systems that are unable to properly parallelize builds are common in the JS world these days so you are probably experiencing tsc much slower than it is.

That said, Babel now supports TypeScript so you should get nearly the same performance with TypeScript as you did with Flow or even just plain ES transpilation. That way you can do typechecking as a separate step like you would have done with Flow.

Re:Yarn's Future – v2 and beyond by mort96 on Thursday January 24, 2019 @12:59PM (#18991092)
I haven't really ever seriously used flow or babel transpilation. My experience with compiled languages is mostly gcc which has initialized and started compiling in microseconds, or just writing plain JS which doesn't need transpilation. "Nearly the same performance as Flow/ES in Babel" isn't the benchmark I use.
Re:Yarn's Future – v2 and beyond by jchw on Thursday January 24, 2019 @01:25PM (#18991385)
Apples to oranges. You can use TypeScript without ES* -> ES5/ES3 transpilation. The compilation process may not be as fast as not having one, but it will be similar in speed to running a few sed commands over your source code.

GCC startup time is going to be faster than Node.JS startup time, but that's irrelevant. We don't need to restart the compiler on each iteration. You can just use an auto reloader for that.

And since we're real developers writing real apps, hello world is not important to us. We want to organize our code into modules and bundle those to a single JS file that is minified in production. So we're going to process the source code one way or another.

C++ is a funny example to mention because it scales pretty poorly in the compilation time aspect, because it lacks modules. Compiler startup times are good... But it's not really that fun burning all 16 cores trying to compile Qt and still having it take forever. Compare to Go where compilation is so fast most people don't even talk about compilation speed.

All languages compile eventually anyways, even JS. It just compiles in the browser. If you really want a "zero compilation step" experience, you can just load the TypeScript compiler directly in the browser. It's been done in the past for demos.

Re:Yarn's Future – v2 and beyond by mort96 on Thursday January 24, 2019 @02:40PM (#18992154)
> We don't need to restart the compiler on each iteration. You can just use an auto reloader for that.

Interesting, I hadn't considered that. I've always just had a build script (usually in package.json), and run that when I change something (either with an inotifywait loop or manually). It does make sense that if you're instead keeping one long-running node.js process instead of spawning a new node.js instance every time, tsc's slow start-up won't matter as much. I'll have to keep that in mind next time I end up doing typescript work.

I have used Angular, using a long-running webpack process which does angular template and typescript compilation, and I found that to be excruciatingly slow even for small changes, but I'm willing to bet that has more to do with Angular than with Typescript.

> C++ is a funny example to mention because it scales pretty poorly in the compilation time aspect

C++'s compile times are horrible, I won't try to defend it - waiting another eight hours for Chromium to compile because you need a build with debug symbols is just horrible. However, most of my time actually working on relatively small C++ code bases is pretty good; compiling each individual file doesn't take very long, and you only recompile the files which have actually changed, and recompiling one C++ file and re-linking the project takes around 0.4 seconds (unless you're doing something stupid like linking in all of webrtc, which we admittedly do for a couple of projects at work). Compiling a typescript file which just contains `console.log("Hello World");` on the other hand takes a bit over a second. (I know compiling hello world isn't very relevant when your compiler is a long-running process instead of a one-shot thing, I'm just including it because that's what my experience with tsc has been until now.)

Do you happen to know of any good resources for how you would run the compiler multiple times from one node.js process? I imagine webpack maybe does it already, but I would be interested to import the compiler as a library or something, and do some testing to see how big of a difference it actually makes to not start a new javascript VM every time.

Re:Yarn's Future – v2 and beyond by jchw on Thursday January 24, 2019 @03:27PM (#18992574)
Webpack indeed can run TS in a loop, using hot reloading. If you want to do this yourself it's fairly trivial, the TS compiler API is at least documented somewhat:

https://github.com/Microsoft/TypeScript/wiki/Using-the-Compi...

And of course you can read the source code for Webpack's typescript support.

Sidenote: although it's less popular, I highly recommend looking into Parcel Bundler, it's much nicer to use and has no configuration required. You can, for example, point it at an HTML file with a script tag pointing to a TypeScript entrypoint that includes NPM modules and it will handle compiling, bundling, minifying transparently. And it's relatively quick.

Re:Yarn's Future – v2 and beyond by brlewis on Thursday January 24, 2019 @03:44PM (#18992735)
Re:Yarn's Future – v2 and beyond by foolfoolz on Thursday January 24, 2019 @12:41PM (#18990901)
classic fallacy of speed lost by dynamic code “i can’t hit save and refresh the page” vs compiled “i can’t make changes without breaking 5 things”
Re:Yarn's Future – v2 and beyond by mort96 on Thursday January 24, 2019 @12:56PM (#18991060)
Nah, my day job is writing C++ and most of my side projects are C. I have nothing against compiled languages, and if the compiler is fast enough, just having `make && ./whatever` in my shell history is almost indistinguishable from `node index.js`. It's just that it takes _over a second_ for tsc to compile hello world, and all javascript tooling feels similarly sluggish to me. I have similar issues with java; make starts compiling stuff in microseconds, while grade doesn't spawn a javac process in what feels like forever.

I probably shouldn't have lead with the "not only is it an extra step" thing.

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'.