Live data from Hacker News

I Was Wrong About TypeScript

triplet.fi

171–180 of 194 posts

Re: I Was Wrong About TypeScript

#171
post #40

Earlier quoted context omitted.

Did you know that Microsoft was part of the cabal against ES4, proposing a competing and very modest ES3.1 which became ES5?

MS was on both sides of it. Remember JS.NET? It was veey ES4'ish (for early definitions of ES4, anyway).

No, I didn't know about it...

Still, the hostility from the "against" side (which also included Yahoo and a pre-Chrome Google) was enough to derail the effort.

Re: I Was Wrong About TypeScript

#172
post #140
post #35

I just wish TS was based on CoffeeScript.

I'd love to know what you love about coffee? Is it the syntax? I am working on extending the Typescript parser to support coffee like syntax.

"Love" is a strong word. The syntax is nicer than JavaScript, and I prefer to use it when possible. Though granted JS is making strides and the difference isn't as great as it was 5 years ago.

You're part of a MS project doing this, or you're doing it on your own?

Re: I Was Wrong About TypeScript

#173

Earlier quoted context omitted.

You claimed that the lack of type checking at runtime is somehow detrimental to the notion. He pointed out that, fundamentally, all strongly typed languages run as weakly typed machine code at runtime, giving C as one obvious example. Thus, types in TS are at least as useful as types in C. The concrete advantage of TS is the same as the concrete advantage of any strongly typed language - types let you do static valid…

Yes, but what about mutating objects/primitives in a way that causes all validations to pass but still be passing the wrong data? It seems like using type checking as a reason to write fewer tests actually just creates nastier bugs in areas where your coverage is based on type validation. What am I missing about checking type mutation !== mutation being a problem? What is the advantage of strong types if your data st…

> Yes, but what about mutating objects/primitives in a way that causes all validations to pass but still be passing the wrong data? > What is the advantage of strong types if your data structures are immutable? Is there any? I'm genuinely trying to understand if TS is just for cases where uncontrolled mutation is the norm and test coverage is poor.

Can you give an example? I'm not following what you mean. Why would strong types be less useful if your data structures are immutable? OCaml mostly uses immutable data structures for example but its strong type system is fundamental to why it can be used to write such robust code.

Typescript has a stronger type system than JavaScript so Typescript can therefore capture more program properties statically compared to JavaScript whether you're using mutable data structures or not.

Re: I Was Wrong About TypeScript

#174
post #110

Earlier quoted context omitted.

Angular blew a loooooot of my trust in Google, who in the past always put out the highest quality stuff. I built an entire app in the damn thing only to realize as it got bigger that it wouldn't scale. Sure you can use less HTML templates, but that's the whole point so that it's easier for designers to approach / fix. Sure I should have checked it out but the documentation didn't exactly highlight it (at the time any…

That's a little harsh. It was an MVVM framework along the same lines as backbone, ember 1.0, knockout, and pretty much every other framework of the day, plus a lot of extra functionality. It's not really google's fault that MVVM has limitations.

I don't think his criticism is too harsh.

Two of the main problems I had with angular - the template syntax and the way the digest cycle worked, both contributed to its scaling factor.

The template syntax meant you would always wonder what a parameter meant when passed to a directive. Essentially, all parameters passed to a directive were strings, but angular would parse some strings to mean "the property of a parent scope", and some more convoluted variations of that(check out https://docs.angularjs.org/api/ng/service/$compile#-scope-). Furthermore, using the recommended ng-controller directive created great spaghetti code, with template blobs where the current scope is almost impossible to track. Applying multiple directives to the same element sometimes required special parameter parsing, which further made the situation confusing. This confusion meant the more stuff you had, the more time you had to spend carefully memorizing it all so you knew what was going on.

The digest cycle fundamentally limits angular's scale. It was designed with some scale in mind at first - a digest cycle triggered at a specific scope would only run watchers under that scope, thus limiting the effect. I assume they hit the problem that there was no way to define explicitly "global" watchers, or to tell another scope to update itself. This issue apparently crept into the development of angular and local digests were pretty much abandoned in favor of using scope.$apply(), which triggers a digest cycle at the topmost scope. Local digests were not really talked about in the documentation, which was littered with examples of scope.$apply(), all of angular's provided directives used scope.$apply() and pretty much no one wrote any code limiting the amount of watchers triggered in an update. React specifically addressed this point with shouldComponentUpdate and the ecosystem built around it, which is one of its biggest performance benefits.

Further criticism would be the terminology confusion. Angular talked about directives, modules, controllers, filters, services, factories, providers, etc.

In essence, providers/factories/services were all just singletons instantiated in different ways(providers being the progenitor and factories/services being variations).

Filters were poorly named, as they were actually mapping functions or value formatters. Thus came the infamous "filter filter", which filtered elements in a collection, as opposed to say the "currency filter", which added currency markers to numbers. They were also incredibly inefficient, running on every digest cycle, even after the attempted fixes with "stateless filters"(http://www.bennadel.com/blog/2766-stateless-filters-don-t-ap...)

Controllers were essentially stunted directives, provided via the ng-controller directive. They were paraded as the way to start "simple" development, but led to a lot of bikeshedding about where to use controllers and where directives, the confusion around directives requiring controllers and the limitations around that, how to appropriately bind directive parameters to a controller's "scope"(not an actual scope but the controller function object itself), the bindToController function resolving that problem(introduced in 1.4?), etc, etc.

Modules were also a weird concept without much practical use. They do not provide a separate namespace(all your angular elements go into the same one), they don't leverage angular tooling to import your code(you have to import your code manually e.g. add script tags). Mostly they provided the config() and run() functions which would let you schedule code to be executed on-load.

I could go on and on about the confusion that angular's terminology caused, the microsyntax in its expressions and how interpolation worked, the scoping inheritance issues around directives and the subsequent overuse of isolate scope to avoid them, transclusion and how it affected scope inheritance(which led to articles like this one - http://angular-tips.com/blog/2014/03/transclusion-and-scopes...), the massive problems with there being no real directive lifecycle hooks you could use...it usually took a monumental effort to avoid all the traps and pitfalls of angular on any larger project.

That doesn't make angular necessarily a terrible framework, because it did enable some productivity when being fairly rigourous when using it. That rigour was developed by the community as it struggled to understand all the concepts thrown at you, but it certainly didn't come easy, and I'm not sure it became really widespread. This severely crippled "developer scale" for me, and the performance issues of watchers/filters worked against "performance scale".

Re: I Was Wrong About TypeScript

#176

> I have written tests in TypeScript, compiled to JavaScript, and then used Mocha, for example, to run tests. I would like to hear your thoughts on this. We use ts-node to run our mocha tests without ever compiling: https://github.com/TypeStrong/ts-node

ts-node has some issues with source maps unfortunately. When your project gets big enough you might want to move back to ts->js then running mocha.

Mind being a bit more specific with "has some issues"? Our project isn't exactly small, and we haven't bumped into a problem yet. I'd really like to know what to expect if something is about to jump out from behind a wall.

Re: I Was Wrong About TypeScript

#177

Does anyone have a good tutorial on migrating existing JS codebases to TS? Talking specifically Angular 1 if you have one, otherwise a general tutorial is fine. I'm interested in whether it is worth the effort migrating a pretty large frontend codebase.

I did this on my current project. Basically: - Set up your TypeScript config - Set up Typings (or some other type def manager) - Rename all ".js" files to ".ts" - Replace all "var x = require()" calls to "import x = require()" - Gradually refactor components (controllers, directives, services) to classes, or at least add type annotations to everything. Because TypeScript is a superset of JavaScript, you can work on a…

I'd add tslint to that once the basic migration is done. It can get a lot of issues in the code that are either bad stylistic options, or things that can produce errors in the future.

Re: I Was Wrong About TypeScript

#178

All the TypeScript fervor kind of passes me by because I simply don't want to structure my work around classes and 'ideal TypeScript' that I've seen looks a lot like Java or another class-oriented language.

Typescript is still extremely useful even if you are writing more functional code. There is no "ideal Typescript", TS is still ES underneath and just about all the ES paradigms including high functional code are still available in TS and benefit from typing information. (The possible exception being that TS is not entirely great at some of the more complex prototype-oriented paradigms, but even that has gotten significantly better in TS >= 1.8 with support for things like intersection types.)

Re: I Was Wrong About TypeScript

#179
post #70

Earlier quoted context omitted.

I think the biggest advantage is that typescript emits code that is good JavaScript. This means if I decide to stop using typescript, I can just use the generated JavaScript. It also means that there transpiled file is smaller. Using scala.js for a small project wouldn't make sense if you cared about file size at all. It could be worth it more as your project grows, but your then you are that much more commited. Ther…

I remember hearing the same argument in the early 80s for the benefit of C vs Assembly. And it actually was a good argument. A lot of people, myself included, learned "real programming" (ie assembly) by using C as training wheels. But a funny thing happened on the way to the forum - C became real programming and nobody remembered or learned assembly - myself included. Then the same thing happened ten years later with…

So it sounds like everything worked out.

Re: I Was Wrong About TypeScript

#180
post #164

Earlier quoted context omitted.

Hey, I work on the TypeScript team. I hope you'll reconsider, and maybe you can fill me in on the issues you ran into. Your .js files should typically be relative to each other, so unless you're using absolute paths (which you usually shouldn't!), this hasn't been a problem for other users. Is there something that I'm missing?

Hey Dan, thanks for responding. I think the key point you may be missing (or perhaps I missed a flag somewhere) is that I want relative requires but I don't want the intermediate js and sourcemap files cluttering up my project (and assuming I have an existing babel/webpack stack I'm happy with -- I just want the type checking). I want the ability to convert any existing js file within the project to ts without having…

Hey rhymohr, I think I see what you mean. If you're already using something like Babel & Webpack, it should just be a matter of using a TypeScript loader like ts-loader[1] or awesome-typescript-loader[2]. TypeScript should just fit into that build step.

Let me know how that ends up working out!

[1]: https://github.com/TypeStrong/ts-loader [2]: https://github.com/s-panferov/awesome-typescript-loader

Post reply on HN