News for hackers. Stuff that matters.
Re:Why Angular 2 Switched to TypeScript by orgomon on Saturday July 23, 2016 @10:48PM (#12151988)
Where is the evidence that static typing results in a net benefit? There's some evidence that points in the opposite direction:

http://games.greggman.com/game/dynamic-typing-static-typing/

When a language imposes static types, it also imposes a development cost, possibly negating all the value it brings.

Typescript is a little in the middle in that static typing is optional, but then you also don't reap the supposed benefits wherever you don't use it. Any "tool-based" refactoring is now less reliable than a simple text search.

As for catching type errors, those are usually caught very early. If they aren't, that points to a lack of test coverage.

As for the "documenting" aspect: The article claims that by static typing, the documentation need not be consulted, which is rather irresponsible. If you use a function, you had better read the documentation. I know that's a bit much to ask from actual developers, but it's true.

Re:Why Angular 2 Switched to TypeScript by swift on Saturday July 23, 2016 @10:56PM (#12152013)
I notice in your comments that you express concern about the development cost imposed by static typing, but then you later on state that you expect type errors to be caught by tests.

Here's the thing: test coverage is crucial on any large project, and we (hopefully) all agree that they're worth it, but tests can be very hard to write and impose a huge development cost. Static typing helps reduce that cost by reducing the number of tests you need to write. Generally, the more powerful the type system, the more the number of tests you need to write is reduced.

It's been my experience that the development cost of static typing is infinitesimal compared to the savings of having to write and maintain fewer tests. YMMV.

Re:Why Angular 2 Switched to TypeScript by mcphage on Saturday July 23, 2016 @11:01PM (#12152033)
> Static typing helps reduce that cost by reducing the number of tests you need to write.

Those type annotations are the tests, they're just run by the compiler. And once you realize that, you can start to ask: are these the most valuable tests to write? If I have a fixed amount of time to write & maintain tests, would that time be better spent testing things more likely to be incorrect?

Re:Why Angular 2 Switched to TypeScript by lomnakkus on Saturday July 30, 2016 @09:44AM (#12192929)
> Those type annotations are the tests,

Disagree slightly. Type annotations are logical propositions and the compiler proves them for you.

That is to say: Tests can only prove the presence of bugs, not absence. Types prove the absence of (type-related) bugs. They essentially give you theoretically perfect test coverage (modulo bugs in the compiler).

Re:Why Angular 2 Switched to TypeScript by mcphage on Thursday August 04, 2016 @04:06PM (#12228079)
> They essentially give you theoretically perfect test coverage (modulo bugs in the compiler).

Theoretically perfect test coverage, for a particular class of bugs. But that class of bugs isn't the most prevalent class, nor are they the hardest class to fix. So it still is a question of, is that the best place to put development time? And beyond that—are all type annotations equally relevant, or are there some that are very valuable, and some that are less so, and so an optionally typed language would be ideal in that regard?

Re:Why Angular 2 Switched to TypeScript by lomnakkus on Friday August 05, 2016 @05:41PM (#12235913)
> Theoretically perfect test coverage, for a particular class of bugs. But that class of bugs isn't the most prevalent class [snip]

Well, except maybe is is? They're certainly extremely severe when they occur. (Especially if your language is weakly typed like C/C++.)

Without the proper research, who knows? (I'm only talking about my own experience, so YMMV. I'm not even sure a proper metric for a 'fair' comparison can be constructed, even in theory, so again YMMV.)

EDIT: Just curious as a point of interest: What statically typed languages do you have non-trivial experience in? This is not a gotcha, or a haha-look-a-the-noob type question. I find that the quality of the $ST_LANG has a huuuuuuuge impact on how people perceive the value of $ST_IN_GENERAL... if that makes sense.

Re:Why Angular 2 Switched to TypeScript by mcphage on Thursday August 11, 2016 @10:59AM (#12268718)
> Well, except maybe is is? They're certainly extremely severe when they occur. [...] Without the proper research, who knows?

Maybe is is? In general that hasn't been my experience (they happen, but not that often, and are usually easy to figure out).

I agree that research is needed to decide, but the research I've seen references doesn't seem to hold that up. But it's not something I've looked closely into; too much discussion about it ends up getting into holy war arguments, and I stay away.

> I'm only talking about my own experience, so YMMV.

Me as well :-)

> What statically typed languages do you have non-trivial experience in?

Java (which has a garbage type system) and Objective-C. I'm in the process of learning Swift and Scala, but I don't have much experience in either yet. More languages back when I was in college, but that was a while ago, and you don't really get non-trivial experience in college.

> I find that the quality of the $ST_LANG has a huuuuuuuge impact on how people perceive the value of $ST_IN_GENERAL...

I agree 100%. And it's not that I think ST is worthless—although Java's type system really tries its damnedest to make it worthless—but spending most of my time in Ruby, one of the wildest-west languages out there, I still don't find type errors cropping up very often, or being a major issue when they do. On occasion, sure, one can be hard to find. But they're really not a major source of error in my day-to-day life; and if ever a language were susceptible to them, it's Ruby.

Still, if the language used matters that much, then it's not just ST that's the solution, it's ST with a certain level of sophistication.

Re:Why Angular 2 Switched to TypeScript by tracker1 on Sunday July 24, 2016 @04:09PM (#12154630)
In the case of TS, they go out the window at runtime... anything outside of your project that comes in (json via rpc or rest) or outside-in calls/callbacks don't enforce the type safety.
Re:Why Angular 2 Switched to TypeScript by mcphage on Tuesday July 26, 2016 @11:02AM (#12166114)
Yeah, and that's frustrating because it also eliminates the performance gains that come when you can determine what exact function will be called, rather than having to determine it at runtime. I guess that's the consequence of TS being a superset of JS.
Re:Why Angular 2 Switched to TypeScript by orgomon on Saturday July 23, 2016 @11:10PM (#12152056)
Test coverage is crucial as code matures and is finalized, not necessarily when it is prototyped - which is exactly where a type system gets in the way.

I disagree with the idea that you need to write more tests because of dynamic typing, my claim is that the tests you have to write anyway also cover type errors. Just running your code yourself covers most type errors.

Re:Why Angular 2 Switched to TypeScript by pixie_ on Sunday July 24, 2016 @01:59AM (#12152381)
Typing doesn't get in the way of prototyping code. On the contrary it's essential. When you're starting out a new project the tendancy to refactor is very high. Everything is changing and in flux as you go from nothing to something. Having static typing makes refactoring quick, easy, and most of all safe. Developing new projects for myself in TypeScript vs JavaScript is exponentially faster.
Re:Why Angular 2 Switched to TypeScript by bubersson on Sunday July 24, 2016 @02:57PM (#12154313)
I have this only from experience, no hard numbers, but I've seen the types make more and more sense with more developers developing the same app. If it's just upto 2 devs I would consider writing it in plain JavaScript. Currently we have around 8 devs in frontend and having type checking via Closure saved us so many times. It's also nice to use the same struct definitions both on Go server and in JS (we have the structs defined by protobufs and we generate both Go files and Closure JS annotations from it). It also gives us nice autocompletion in the IDE.
Re:Why Angular 2 Switched to TypeScript by k__ on Sunday July 24, 2016 @10:41AM (#12153432)
If you know types from, Java, then you're in for a treat.

TypeScript is so much better to work with. Most of the time it feels like ES2015.

Re:Why Angular 2 Switched to TypeScript by PeCaN on Saturday July 23, 2016 @10:50PM (#12151994)
Maybe it's because I'm lazy and sloppy, but I'd rather the language catch type mistakes than having to write tests for that. Plus, domain modelling with types is nice in ML dialects.
Re:Why Angular 2 Switched to TypeScript by orgomon on Saturday July 23, 2016 @11:00PM (#12152023)
You're not writing tests to catch type errors. You write tests that actually use your code, where a type error will almost certainly be picked up.

Chances are however, your type error will already occur the first time you run your code.

Re:Why Angular 2 Switched to TypeScript by Cpoll on Saturday July 23, 2016 @11:09PM (#12152054)
The article itself throws some self-doubt with a link to http://danluu.com/empirical-pl/

It's also a bit of a pain that it's just a summary of a video, and there's no citation to any text anyway.

From what I can tell, the first bit of evidence is from a researcher's toy language.

The second was a scan of GitHub for issues that included type errors. There's no mention of actual methodology, but I'm imagining that means 3% of Python issues in GitHub have a copy-and-pasted stacktrace that contains a type error? This is clearly not a great indicator, since it won't count issues with less description, or any bugs related to, say, a bad type coercion.

On the other hand, you're right, I've not read any research that points to static typing being a net-gain. Every static-type advocate probably remembers being burned by a dynamic-type issue, but that doesn't mean the advantages might not outweigh disadvantages - experience and intuition don't cut it here.

Re:Why Angular 2 Switched to TypeScript by orgomon on Saturday July 23, 2016 @11:17PM (#12152078)
In the absence of evidence, what else do you have besides experience and intuition?

I'm not actually making a claim one way or the other, I'm rather questioning one argument in favor of static typing.

There are other arguments for static typing which I agree with, but which are too domain-specific.

Re:Why Angular 2 Switched to TypeScript by namelezz on Saturday July 23, 2016 @11:16PM (#12152072)
I remember TypeScript creator(forgot his name) mentioned that it's extremely difficult to do refactoring right in JS.

Edit: https://youtu.be/lT07c3OREL8?t=713

Re:Why Angular 2 Switched to TypeScript by zastrowm on Saturday July 23, 2016 @11:56PM (#12152159)
Anders Hejlsberg is who you're thinking of.

> He was the original author of Turbo Pascal and the chief architect of Delphi... the lead architect of C# and core developer on TypeScript.

(from wikipedia)

Re:Why Angular 2 Switched to TypeScript by protomyth on Saturday July 23, 2016 @11:40PM (#12152130)
I would find it interesting to know why refactoring tools are successful in Smalltalk but not JS.
Re:Why Angular 2 Switched to TypeScript by hota_mazi on Sunday July 24, 2016 @12:55AM (#12152267)
They're not successful in Smalltalk: the absence of type makes automatic refactorings unpredictable because the compiler simply can't guarantee you that it's not breaking anything.

Today's automatic refactoring IDE's are light years ahead what the Smalltalk Refactoring browser ever did.

Re:Why Angular 2 Switched to TypeScript by protomyth on Sunday July 24, 2016 @07:18AM (#12153029)
Saying they are not successful in Smalltalk doesn't jive with the history of refactoring browsers in Smalltalk. I doubt the widespread use of a tool in a language if it didn't work.
Re:Why Angular 2 Switched to TypeScript by crypto5 on Saturday July 23, 2016 @10:52PM (#12152001)
> it also imposes a development cost,

Very very small cost.

Re:Why Angular 2 Switched to TypeScript by dang on Saturday July 23, 2016 @11:25PM (#12152097)
> Very very small cost.

I've gone back and forth a few times in my career (currently preferring dynamic languages) and would say that the cost is considerable, even with type inference. The trouble is, we don't notice the costs of approaches we're habituated to or prefer, so it feels like they're much smaller than they are. And we don't account for the costs we don't notice, so our cost/benefit analyses (on both sides of the question) are skewed. We all unconsciously put a finger on the scale.

This doesn't stop everyone from making grand, confident claims about static vs. dynamic typing. Such studies as there are don't support these claims, but the studies are weak in so many ways that it's easy to dismiss the ones you don't like and stick to your previous opinion, so that's what we all do.

For these reasons, the debate is pure tribalism and cargo cult. We should stop pretending that our views have any objective support and just talk about them in terms of taste. That's unsatisfying to the technical mind, though, so none of us will!

Re:Why Angular 2 Switched to TypeScript by lomnakkus on Saturday July 30, 2016 @09:48AM (#12192944)
> This doesn't stop everyone from making grand, confident claims about static vs. dynamic typing. Such studies as there are don't support these claims, but the studies are weak in so many ways that it's easy to dismiss the ones you don't like and stick to your previous opinion, so that's what we all do.

> For these reasons, the debate is pure tribalism and cargo cult. We should stop pretending that our views have any objective support and just talk about them in terms of taste. That's unsatisfying to the technical mind, though, so none of us will!

Excellent points[1] and I think I'm mostly justified in saying that I personally have begun prefacing any discussion of these things by a disclaimer to the effect of "well, the evidence is very sparse and it's a woefully understudied area...". I think of it as a kind of 'professional maturity' these days. Or maybe it's just 'old man syndrome' :).

Of course it's not like actually doing these types of studies is easy or cheap, so... here we are, I guess :)

[1] Even though I disagree with your position on type checking. Static FOREVER, baby! :p

Re:Why Angular 2 Switched to TypeScript by crypto5 on Saturday July 23, 2016 @11:36PM (#12152122)
Where does considerable cost come from? There is a small overhead in number of characters in your program. I think that's it.
Re:Why Angular 2 Switched to TypeScript by domlebo70 on Sunday July 24, 2016 @09:56AM (#12153302)
What is the cost? I mean, you are already working through the types in your head when writing code in a dynamically typed language. It's not like you get to just forget what type things are when you program.
Re:Why Angular 2 Switched to TypeScript by dang on Sunday July 24, 2016 @02:03PM (#12154075)
Here's one of many examples: when you're defining types you have to think of names for them. That's a high-energy mental operation.
Re:Why Angular 2 Switched to TypeScript by domlebo70 on Monday July 25, 2016 @04:22AM (#12157223)
Interesting. Can you give me some more examples?
Re:Why Angular 2 Switched to TypeScript by dang on Monday July 25, 2016 @01:28PM (#12160137)
Another is that you get a slower interactive development cycle because you have more things to do before your code can run.

For example, some portion of your program may be half-baked because you haven't worked out its types yet, or maybe you've changed a type but haven't yet updated the rest of the program. If you want to play with your program interactively to find something out about the work in progress, now you can't, because your program isn't currently 'correct', i.e. it isn't self-consistent.

This adds drag to the development process. First, you have more work to do. Second, it breaks flow: you must switch your attention to something extraneous, breaking your concentration on what you were doing. Third, it gets you in the habit of satisfying the machine rather than thinking about the problem you're trying to solve.

Re:Why Angular 2 Switched to TypeScript by pixie_ on Sunday July 24, 2016 @02:01AM (#12152386)
Development cost? I've had huge development savings using typescript. The support for fast refactoring plus constant intellisense of any type errors has sped up my up my development significantly.
Re:Why Angular 2 Switched to TypeScript by rtpg on Saturday July 23, 2016 @11:01PM (#12152034)
Historically this cost was a lot higher though.

It's only fairly recently that mainstream languages had type inferencing. Before it could be quite costly (and affect code legibility too)

Re:Why Angular 2 Switched to TypeScript by adamnemecek on Saturday July 23, 2016 @10:53PM (#12152003)
Not this thing again :-/