News for hackers. Stuff that matters.
Re:Announcing TypeScript 2.1 by zdragnar on Wednesday December 07, 2016 @12:40PM (#13124392)
It's interesting to me that all of the initial reactions I've seen to this announcement have been around the introduction of async and object spread, which are available with babel, but the typescript specific features such as mapped types are completely ignored.

I don't really have any particular meaning behind that observation, only that it tickled my funny bone a little bit.

Re:Announcing TypeScript 2.1 by DanRosenwasser on Wednesday December 07, 2016 @12:51PM (#13124493)
TypeScript PM here - the reason for that is that when we implement a feature in TypeScript, we take lengths to ensure that it is typed appropriately and that its performance characteristics are reasonable.

That means that when using object rest/spread, we didn't want to just ship an experience where type type is effectively `any`, leading users to be frustrated if they make an error.

With async/await, we had to rewrite our emit pipeline, which meant that we needed to keep parity in both output as well as time to emit. The investment has shown, and TypeScript is still extremely fast.

We're always willing to think about different approaches, but those are some of the rationales here.

Re:Announcing TypeScript 2.1 by zdragnar on Wednesday December 07, 2016 @04:28PM (#13126373)
Did you mean to reply to my comment? If so, to help clarify, I wasn't critiquing the long delay of those features; I merely was amused that they've gotten so much more attention than the far more novel features that were also released.
Re:Announcing TypeScript 2.1 by vyrotek on Wednesday December 07, 2016 @02:22PM (#13125350)
As a long-time .NET dev... Thank You for Async/Await in TypeScript.
Re:Announcing TypeScript 2.1 by mattmanser on Wednesday December 07, 2016 @08:00PM (#13127618)
async/await in C# is pretty nasty and usually overused and overhyped for nothing but downside. It screws debugging, it screws call stacks, it dictates you to write bad code and it's just plain complicated. It infects your code up and down the stack and every new method MS now releases seems to be .SomethingAsync().

I likened it today to having a garden hose in a Victorian sewer but then declaring the sewer is the bottle neck, async/await to the rescue!

Most people use it in totally inappropriate scenarios, for no good reason but adding a load of complexity to your code and debugging.

But your sewer is now even bigger! Look at how you can throw that hose around!

I was working on a code base where the old developers had started going async/await for 'performance reasons'. Cue me ripping it all out, actually fixing the performance problems and downsizing the client from a P1 to a S1 in azure with 3x the load and vastly better page load speeds.

It's almost always a premature optimisation. My opinion is don't ever use it unless you actually know what the specific bottleneck is that async/await will fix and you actually need it.

async/await in javascript is actually useful.

Re:Announcing TypeScript 2.1 by taspeotis on Wednesday December 07, 2016 @08:23PM (#13127712)
I think it is unfair to compare async/await on top of poorly performing code with async/await generally. Fast synchronous code being faster than slow asynchronous code is kind of tautological.

async/await keeps your UI thread unblocked. Or, more generally, it keeps your threads unblocked. I have an ETL process that benefits from async/await greatly: I can stream more data in/out of the database with fewer threads.

That's not unique to the task-based asynchronous pattern, but it's far fewer lines of code to write than BeginExecuteReader/EndExecuteReader etc. so my appetite for doing it is much higher. And I believe asynchronous streaming (à la DbDataReader.ReadAsync) has no non-TAP equivalent.

Two steps forward, one step back. (You're right about debugging.)

Re:Announcing TypeScript 2.1 by mattmanser on Thursday December 08, 2016 @04:52AM (#13129390)
Why is it tautological? There is no performance gain for most people using async/await, at all. That's simply not how it works. You have to be in a specific scenario, high load on the server's resources, not the DB, to see any benefit.

And while keeping the UI thread unlocked is great, how many people are using this in C# web code instead?

Where the entire web pipeline is already set up to naturally multi-thread by itself.

Re:Announcing TypeScript 2.1 by lllr_finger on Thursday December 08, 2016 @09:32AM (#13130456)
I'm curious what experience led to this opinion because I can't disagree more.

Most any .NET site doing volume should be using TPL, because the framework is incredibly efficient at managing threads and preventing the pipeline from getting clogged. I've worked on dozens of APIs and sites that need to deal with hundreds and thousands of concurrent requests. Handling those in a synchronous fashion or hand-rolling state management is horrible and I'd never want to go back to it.

The only downside I agree with is the debugging, but that gets better with every C#/.NET/VS release, and you really shouldn't have a ton of complexity buried in your await block. If it hurts, there's a good chance you're violating SOLID.

Re:Announcing TypeScript 2.1 by mattmanser on Thursday December 08, 2016 @12:17PM (#13131978)
You have to be in a specific scenario, high load on the server's resources, not the DB, to see any benefit.

You're in the specific scenario!

If you're getting 1000s of concurrent requests, running at, say, 20ms each, that'd be 4.3 billion requests a day.

What percentage of C# devs have that kind of load?

Re:Announcing TypeScript 2.1 by taspeotis on Thursday December 08, 2016 @05:16AM (#13129461)
> There is no performance gain for most people using async/await, at all. That's simply not how it works. You have to be in a specific scenario, high load on the server's resources, not the DB, to see any benefit.

If you have two asynchronous things to do, and they are unrelated, start them both and then await Task.WhenAll(file1Download, file2Download). Look at the wall clock - it's up to twice as fast. Look ma, no threads or synchronization primitives!

> And while keeping the UI thread unlocked is great, how many people are using this in C# web code instead? Where the entire web pipeline is already set up to naturally multi-thread by itself.

Blocking operations ... block. Now your thread is doing nothing while your database churns/disk writes/network packet streams. As I understand it, using async/await with the SynchronizationContext in ASP.NET will yield the thread to another request. You get more requests per thread, which mitigates the problems with thread-per-request as described here [1]. Instead it's a combination of thread-based and event-driven models.

[1] http://berb.github.io/diploma-thesis/original/042_serverarch...

Re:Announcing TypeScript 2.1 by mattmanser on Thursday December 08, 2016 @12:08PM (#13131885)
Not a lot of things need to access two files at once. You and I both know virtually all await/asyncs are doing a singular one thing like DB or emailing or a single file access.

So why bring it up?

And as for your condescending "Blocking operations ... block", talk about missing my entire point.

IIS is the victorian sewer, your code is the hose. IIS has many threads available to it, that's my entire point. You don't need async/await to free up those threads, it's got a ton of them ready to go.

Most programmers are not going to hit the thread limit, and when they do they can upgrade hardware while they figure out the tiny few high-impact async/awaits that would actually mitigate the problem.

It's pointless pre-optimization. We all talk about how evil it is, so why is it suddenly not evil with async/await?

Re:Announcing TypeScript 2.1 by taspeotis on Thursday December 08, 2016 @05:12PM (#13134785)
I make plenty use of async requests to get files (images) and make web service calls at the same time. It's a Xamarin mobile application. Mobile apps are sometimes constrained by latency, so having a few requests in flight at once speeds things up.

Performance is not just fewer CPU cycles.

> IIS has many threads available to it, that's my entire point

My web services run on a VM with four cores. That's what I get given, and there's another twenty websites on it. The less overhead my code has the better. Just because it's not 100K TPS doesn't mean there aren't benefits.

Re:Announcing TypeScript 2.1 by egeozcan on Thursday December 08, 2016 @03:29AM (#13129124)
I heard from a colleague that in VS2017, the debugging is much better for async stacks. Did anyone here try it?
Re:Announcing TypeScript 2.1 by petilon on Wednesday December 07, 2016 @10:06PM (#13128124)
I agree mostly. One of the biggest issues with async/await in C# is that if not used carefully you can get deadlocks. If you get even one such deadlock, the cost of debugging it can wipe out all your hardware savings. For that reason most people should not use async/await in C#.

Since there is no deadlock issue in JavaScript async/await should result in code that is easier to write as well as maintain.

Re:Announcing TypeScript 2.1 by jc79 on Wednesday December 07, 2016 @03:01PM (#13125699)
Well, to me at least the mapped types are the main advantage of this release. Very frequently you start building a record incrementally (so, you can't assign it to an interface where all fields are mandatory), but then at a given stage you will validate that record and copy it to another variable which has the type with all the fields mandatory. Previously you had to define two copies, one with mandatory fields, another with all optional... kind of a bummer, and easy to update one and to forget the other!

Also, this greatly improves the type security of variables which work as keys to objects, without repetition of those keys on the interface and on the string literal.

So yeah, I'm thrilled with these changes

Re:Announcing TypeScript 2.1 by dandare on Thursday December 08, 2016 @01:58AM (#13128866)
I do not understand this concept fully and I wish I could read a more detailed explanation of how this works along with plenty of example code.
Re:Announcing TypeScript 2.1 by nozzlegear on Wednesday December 07, 2016 @12:47PM (#13124467)
For me, I'm excited because this announcement means I can finally remove Babel from my compile process and just rely on TypeScript to do all of the magic for me.
Re:Announcing TypeScript 2.1 by k__ on Wednesday December 07, 2016 @01:48PM (#13125038)
"the typescript specific features such as mapped types are completely ignored"

Oh, for me it's just because I'm to dumb to grasp them ;)

Joke aside, I knew the other features from JavaScript already. I used them for half a year now and know what they give me. The rest is something I probably will apreciate when the time comes and I need it.

Re:Announcing TypeScript 2.1 by Guillaume86 on Wednesday December 07, 2016 @12:58PM (#13124559)
Not surprising at all, parity with babel language support and ease to switch to typescript easily is very useful. Some features like the spread are not possible without the new features btw.
Re:Announcing TypeScript 2.1 by manojlds on Wednesday December 07, 2016 @12:56PM (#13124530)
From my experience - missing these features was a bit of an irritation. But now, with what Typescript already offers, and the small missed stuff like spread, it is even more great.
Re:Announcing TypeScript 2.1 by Longwelwind on Wednesday December 07, 2016 @01:21PM (#13124790)
Maybe it is me, but I feel like mapped types and keyof are terrible features, and using them would be a sign of a bad design/architecture.

In general, I don't think using a string that represents a static symbol (such as the name of a var, an attribute or a class) is a good idea.

I try to keep a simple stack (Typescript + NPM at the moment), and I prefer to wait for Typescript to have the feature I want, than to install a new dependency (Babel, for example) to my project.

Re:Announcing TypeScript 2.1 by klodolph on Wednesday December 07, 2016 @01:42PM (#13124993)
I think there are two main kinds of developers who use TypeScript. Some developers come from traditional statically-typed languages, like C#/Java/C++/etc, and expect the language to conform to their idea of "good design". For these developers, "mapped types" are "not good design". Other developers come from JavaScript, Python, Ruby, or other duck-typed languages and think, "I know that this object is just a dictionary underneath it all, and I want a type system that lets me write code with that foundation." These developers want additional safety but they see traditional type systems as handcuffs.

These are two very different styles of programming, and TypeScript does a fairly good job of serving both groups--it would have to, in order to be as successful as it is. There are a ton of useful JavaScript libraries out there which couldn't easily be rewritten to conform to some Java-style type system, and there are a ton of skilled Java/C#/C++ engineers out there who don't want their name on a bunch of cowboy code.

I don't think this cultural division is going to go away any time soon, so it's in our best interest to believe that people in the "other camp" (whichever camp that is) are skilled and conscientious developers. I'm sure you've heard the arguments by dynamic language lovers who talk about how restrictive/slow/painful it is to write in a static type system, and I'm sure you're as tired of that argument as I am.

Re:Announcing TypeScript 2.1 by stcredzero on Wednesday December 07, 2016 @02:16PM (#13125294)
I'm sure you've heard the arguments by dynamic language lovers who talk about how restrictive/slow/painful it is to write in a static type system, and I'm sure you're as tired of that argument as I am.

At this point in time, it's a bit of a false dichotomy. It just amounts to a programming tool based on a form of meta-data. Of course people are going to have different ideas about the cost-benefit of that tooling. Of course, people are going to have differing opinions on how much of that tooling is worthwhile. Most of the problems with online discussions about this kind of tooling, come from people forgetting that it's just a discussion about tooling.

Re:Announcing TypeScript 2.1 by klodolph on Wednesday December 07, 2016 @03:08PM (#13125745)
I don't think this is a false dichotomy. There's definitely a spectrum between static and dynamic type systems, and plenty of people who identify with either camp. Calling it "tooling" changes the name of the problem, there are still people who will complain when they think the tooling is going in the wrong direction, and those complaints have merits because so many of us will be forced to write code in a style we don't like.
Re:Announcing TypeScript 2.1 by stcredzero on Wednesday December 07, 2016 @04:16PM (#13126288)
There's definitely a spectrum between static and dynamic type systems

The key word is spectrum.

and plenty of people who identify with either camp.

What does it mean when people take something that's actually a spectrum, then divide that into two opposing camps? Does this sort of activity generally get public discourse closer to the truth, or farther away from it? It usually does the latter, in my experience. Hopefully, someone has set that knob to a position that works pretty well, and things work out.

those complaints have merits because so many of us will be forced to write code in a style we don't like.

Just who gets to write code in exactly the style that they like? From what I've seen, people generally make compromises, or they found the "perfect" job, or they are the one running the project, or they are going rogue and doing their own thing and introducing inconsistencies into a project's codebase.

Re:Announcing TypeScript 2.1 by klodolph on Wednesday December 07, 2016 @05:40PM (#13126941)
Honestly, I feel like I am on the receiving end of some moralizing here—when someone tells me that my language "brings public discourse farther away from the truth" I wonder how I could have offended them so deeply.

The difference between a dichotomy and a spectrum is itself a false dichotomy. Ask any biologist what a species is, and they might stammer out some kind of weaselly definition full of hedges, and that same biologist might turn around and publish a dichotomous key which tells you how to identify a particular species according to an easy set of rules. The same goes for politics, human sexuality, and yes, type systems.

So I'm not going to hedge myself when I say that people "identify with either camp". They do. Neither is it a contradiction when I say that there's a spectrum. And when I say that there are two main kinds of people—I hope that my reader understands that I'm not a robot, and that I don't actually think that type systems are some kind of strict dichotomy.

> Just who gets to write code in exactly the style that they like?

I could point out that, again, like/dislike is a spectrum and not only a dichotomy. See above discussion.

Re:Announcing TypeScript 2.1 by stcredzero on Thursday December 08, 2016 @01:19PM (#13132622)
Honestly, I feel like I am on the receiving end of some moralizing here—when someone tells me that my language "brings public discourse farther away from the truth" I wonder how I could have offended them so deeply.

Please re-read. I never said your programming language "brings public discourse farther away from the truth." Otherwise, please provide a quote. What I said is that some discussion about language "brings public discourse farther away from the truth."

I just re-read, and perhaps you are talking about human language. Also, no, I'm not offended. I'm just making an observation about how talking about things in a certain way can shape thought in non-beneficial ways.

Ask any biologist what a species is, and they might stammer out some kind of weaselly definition full of hedges, and that same biologist might turn around and publish a dichotomous key which tells you how to identify a particular species according to an easy set of rules. The same goes for politics, human sexuality, and yes, type systems.

When I encounter political discussions online, I sometimes have a person pattern-match something I've said, then declare all of my political beliefs for me. In those situations, false dichotomy -- or rather unawareness of the spectrum -- has distorted someone's thinking away from the truth.

I suspect this happens to Golang a lot. Basically, the Go language designers seem to be heavily into the Pareto Principle. So they are very willing to have a quite barebones level of tooling, and leave a lot of features out. This is especially true for their type system. They seem (to me) to have succeeded in getting most of the benefits of a type system while minimizing the disadvantages, while having much of the "feel" of a dynamic language, while also avoiding most of the downsides. It's a kind of pragmatic minimalism I've only encountered before in dynamic languages like Clojure, Lua, and Smalltalk.

Re:Announcing TypeScript 2.1 by ng12 on Wednesday December 07, 2016 @02:13PM (#13125268)
Simple example: keyof allows you to safely describe objects which only partially fit an interface.

  interface Values {
    foo: string,
    // etc...
  }

  let keys: keyOf Values

  function initialize(defaults: {[key: keys]: string}) {...}
Now the defaults object can only contain valid keys from Values.
Re:Announcing TypeScript 2.1 by daxfohl on Wednesday December 07, 2016 @02:05PM (#13125196)
I assume you mean lookup types rather than mapped types; the latter has nothing to do with strings.

In general, in application-facing code I think you're absolutely correct: using strings as lookups is a hack that should be discouraged. (Though sometimes it's convenient when dealing with other JS libraries).

However the feature brings some strong metaprogramming abilities that wouldn't be possible otherwise. For instance I'd have to imagine that mapped types were implemented by using those features, and the ability to define types as variants of other types (beyond ordinary generics) is something very powerful.

I'm primarily an F# user and have been begging for something like this there. The ability to define variations on record types (without and id/timestamp for inserts, with those fields otherwise; hashed/raw password fields for your various user records; etc) in a typesafe manner without a ton of repetition is a game changer.

Re:Announcing TypeScript 2.1 by Etzos on Wednesday December 07, 2016 @01:26PM (#13124830)
> In general, I don't think using a string that represents a static symbol (such as the name of a var, an attribute or a class) is a good idea.

Why? (Genuine curiosity here, not trying to be hostile or anything like that)