News for hackers. Stuff that matters.
Re:Polymer 2.4: Paving the way for 3.0 and TypeScript support by hazza1 on Monday January 29, 2018 @04:07PM (#16260616)
In my experience giving your JSON API type information is one of the most beneficial things you can do to your web codebase.
Re:Polymer 2.4: Paving the way for 3.0 and TypeScript support by jondubois on Monday January 29, 2018 @04:18PM (#16260688)
To some extent, but there is a difference between giving each object a type property (which is open to interpretation by the client app) vs forcing the client to adhere to rigid type definitions/constraints (which make it more difficult for the client to actually use the API). Developers who have used SOAP before will remember what that's like.
Re:Polymer 2.4: Paving the way for 3.0 and TypeScript support by hazza1 on Monday January 29, 2018 @04:25PM (#16260745)
Typescript is as rigid as you want it to be, you're free to loosen the types as your api demands. It really is nowhere near as heavyweight as SOAP.
Re:Polymer 2.4: Paving the way for 3.0 and TypeScript support by ascorbic on Monday January 29, 2018 @04:25PM (#16260742)
The client has to adhere to the shape of the JSON that the API is generating anyway. Defining those types just makes it easier to avoid mistakes. There's no reason that need to be any more rigid than the API would otherwise be.
Re:Polymer 2.4: Paving the way for 3.0 and TypeScript support by jondubois on Monday January 29, 2018 @04:27PM (#16260760)
But the schema can change over time with different API versions. So you need different schemas on the front end for different versions of the API? It just seems like a lot of hassle when ultimately all you need to do is get a string property from the API and put it in a textbox.
Re:Polymer 2.4: Paving the way for 3.0 and TypeScript support by skybrian on Monday January 29, 2018 @04:49PM (#16260934)
The simple thing would be to avoid making incompatible changes to the public API. If you keep the same schema and loosen the types a bit (accepting more kinds of requests) then there's no need to have more than one schema.

But you're describing a fairly complicated scenario where you have multiple public API's with different request types, internal data (hopefully canonicalized at the border) and response types.

How do you keep track of all that data conversion without types?

Re:Polymer 2.4: Paving the way for 3.0 and TypeScript support by ascorbic on Monday January 29, 2018 @04:51PM (#16260948)
If the schema is changing you'll need to document it and change the client code anyway. If you're able to auto-generate a schema then that's a hell of a lot easier.
Re:Polymer 2.4: Paving the way for 3.0 and TypeScript support by bitoneill on Monday January 29, 2018 @04:46PM (#16260903)
Microsoft addressed this and says Typescript is most beneficial to manage large code bases
Re:Polymer 2.4: Paving the way for 3.0 and TypeScript support by jondubois on Monday January 29, 2018 @04:52PM (#16260956)
I've worked with TypeScript on large code bases. I found that the compile step becomes really slow and it slows down the debug cycle.

On my last large project, I had to wait 10 to 15 seconds for the code to build every time I saved the file (and yes the compilation step was optimized to only include relevant code; a large number of dependencies don't help).

So every time I made a change to the code to check something, I had to wait... You can't use console.log() to quickly check stuff anymore; the compile overhead is so significant that you're forced to pull up the debugger and manually step through the relevant code every single time you want to check something (you want to get as much info as possible from each debug cycle because it's so slow).

When writing plain JavaScript, I only pull up the debugger when it's a particularly difficult bug (e.g. a race condition). For most bugs, I can get all the information I need with just a couple of calls to console.log() in my code. The debugger is just unwieldy.

Re:Polymer 2.4: Paving the way for 3.0 and TypeScript support by bitoneill on Monday January 29, 2018 @05:15PM (#16261128)
I used to be a c++ dev so a 15 sec compile time doesn't seem that bad. But what if you're compiler told you what was wrong faster than your console.log() could help you find it. I think is a trade off a lot of people want to make.
Re:Polymer 2.4: Paving the way for 3.0 and TypeScript support by jondubois on Friday February 02, 2018 @08:27AM (#16290327)
I agree, that makes sense for C/C++ because working with pointers and dynamic memory is a lot more complicated - Types make sense for C/C++ because the focus is execution speed and flexibility (not development productivity).

The case you describe very rarely happens to me with JavaScript; having fewer primitives to work with greatly reduces these kinds of issues... Sure it opens up the possibility that you'll do something stupid like trying to add an object with a string; but that's a pretty silly thing to do. If you name your variables properly then that never happens.

With C/C++, there are many primitives so you might get errors when you try to assign an int64 to an int8 (for example)... With JS, however, because there are fewer primitives so the odds of that happening are much much smaller.

Because there are so few primitives in JS, it's easy to remember how they all interact with each other. The only exception is the boolean truth table for '==' (which is a mess); that's why it's usually recommended to use '===' instead.

Re:Polymer 2.4: Paving the way for 3.0 and TypeScript support by ascorbic on Monday January 29, 2018 @04:19PM (#16260692)
This. It's also simple to generate JSON Schema from TypeScript types (and vice versa).