News for hackers. Stuff that matters.
Re:How we failed, then succeeded, at migrating to TypeScript by AriaMinaei on Sunday October 13, 2019 @02:13PM (#21241834)
I was looking at some of my old repos today. Enjoyed the nostalgia. Lots of CoffeeScript there. I had to switch to ES and then TypeScript because CoffeeScript was abandoned at the time and I was stretched over other projects to be able to help maintain it.

Reading my old code, I was surprised by how clean it looks. How easy it is to digest. There is a certain sense of calm when your brain doesn't have to process all the visual clutter of a C-style syntax. I miss that.

I wish I didn't have to choose between CoffeeScript and TypeScript.

TypeScript first and foremost is about type safety and tooling. Its architecture is largely syntax-agnostic. It operates on the AST, so the parser and code generator can be swapped for a different syntax.

CoffeeScript is all about syntax and does not (and should not) concern itself with most of the semantics.

They could theoretically be used together if TypeScript simply allowed custom parsers/generators/formatters to be plugged in.

This would work with ESLint and other JS tooling as well. I did a POC on that a few years ago [0].

[0] https://github.com/gkz/LiveScript/issues/821#issuecomment-18...

Re:How we failed, then succeeded, at migrating to TypeScript by sa46 on Sunday October 13, 2019 @03:06PM (#21242211)
> How easy it is to digest

I’ve not had this experience. I’ve found the ambiguity in coffeescript a maddening adventure in syntax confusion.

- function call syntax doesn’t need parens except if a 0 parameter method

- commas are largely optional both in arrays and function parameters. How do you parse: [f, f(), f a b c]

- implicit returns are a terrible idea.

- the @ syntax refers to either a ‘static’ method or an instance variable depending on the context.

- I have to do a double take for the object literal syntax every time

Re:How we failed, then succeeded, at migrating to TypeScript by AriaMinaei on Sunday October 13, 2019 @03:27PM (#21242362)
Don't want to invalidate your experience. For me though, I rarely struggled with ambiguity.

> function call syntax doesn’t need parens except if a 0 parameter method

Function call syntax doesn't require parens so to make multi-line calls punctuation-free. Especially if some args are objects.

> commas are largely optional both in arrays and function parameters. How do you parse: [f, f(), f a b c]

Well commas are not optional.

> implicit returns are a terrible idea

They're especially elegant in writing declarative code. It takes some getting used to though.

> the @ syntax refers to either a ‘static’ method or an instance variable depending on the context.

Agreed.

These are all tradeoffs though. For me, they struck the right balance between ambiguity (very little) and expressiveness.

LiveScript in comparison was much more sugary (which I preferred): https://livescript.net/

Re:How we failed, then succeeded, at migrating to TypeScript by k__ on Sunday October 13, 2019 @06:10PM (#21243498)
Haha, yes. LiveScript should have won. It were awesome times.

Well, guess it's Reason for me now :D

Re:How we failed, then succeeded, at migrating to TypeScript by dagw on Sunday October 13, 2019 @05:48PM (#21243342)
My experience was that I always found my CoffeeScript really easy to read since I was always internally consistent with which opinional bits I used and which bits I ignored.

Reading other people's CoffeeScript on the other hand...

Re:How we failed, then succeeded, at migrating to TypeScript by Jare on Sunday October 13, 2019 @05:14PM (#21243088)
I was very excited about CS when I learned about it, and in my initial tests found it really pleasant to write. However, before committing to using it more, I went and read some other projects written in it. At that point I decided that the reading experience was confusing, and the lack of "visible" syntax elements to guide me drove me nuts.
Re:How we failed, then succeeded, at migrating to TypeScript by EdwardDiego on Monday October 14, 2019 @12:49AM (#21245330)
Don't forget fat arrow vs. thin arrow. If you're not writing Coffeescript 24/7 you start to forget which is which.
Re:How we failed, then succeeded, at migrating to TypeScript by switz on Sunday October 13, 2019 @02:53PM (#21242116)
You just gave me an idea.. because we've shared a similar experience.

I really miss the elegance of Coffeescript. ES6 is great, Typescript is great, but sometimes I feel like I have to visually parse a lot of static cruft to read the essence of the program.

What if one's editor had a toggle hotkey to hide typescript typings. Maybe you could turn it off to visually parse the program real quick, before turning it back on to edit it.

Hmm...

Re:How we failed, then succeeded, at migrating to TypeScript by AriaMinaei on Sunday October 13, 2019 @02:57PM (#21242151)
You're getting in the realm of "projectional editing." It's a fascinating idea: https://news.ycombinator.com/item?id=15534555
Re:How we failed, then succeeded, at migrating to TypeScript by minxomat on Sunday October 13, 2019 @03:16PM (#21242280)
Yep. You can take MPS today and implement an AST projection that looks like whatever you want. No parsing involved, impossible to even write syntactically invalid code (since it is not code you're writing, but an AST projection).
Re:How we failed, then succeeded, at migrating to TypeScript by switz on Sunday October 13, 2019 @04:31PM (#21242767)
I love reading about stuff like this, thanks for sharing. Developer UX still has a lot of room to grow.
Re:How we failed, then succeeded, at migrating to TypeScript by gherkinnn on Sunday October 13, 2019 @03:35PM (#21242404)
Interesting. I sometimes wish to only see the types and get rid of the rest.
Re:How we failed, then succeeded, at migrating to TypeScript by droidist2 on Monday October 14, 2019 @06:18AM (#21246637)
What about instead maintaining the type definitions in a separate file, and then having the editor add in the type hinting?
Re:How we failed, then succeeded, at migrating to TypeScript by Waterluvian on Sunday October 13, 2019 @07:02PM (#21243851)
TypeScript is so syntax heavy. But my perspective is that there are costs incurred at time of development and maintenance in return for stability at runtime. And I think the latter is far more important if you're writing production code.

When it comes to experimentation, I love Javascript and Python because of how fast they are to write when you're not thinking hard about types.

Then it's just discipline to know how to promote experiments to production code. TypeScript is beautiful because you can just turn it on and add them in. Same with Python type hints.

Re:How we failed, then succeeded, at migrating to TypeScript by zachrose on Sunday October 13, 2019 @03:14PM (#21242271)
If you want the quiet syntax of CoffeeScript and even better type safety than TypeScript, you might be interested in Elm.

https://guide.elm-lang.org/

Re:How we failed, then succeeded, at migrating to TypeScript by AriaMinaei on Sunday October 13, 2019 @03:29PM (#21242373)
I love Elm. Never got to use it in production though. Can't afford to get even further from the metal :)
Re:How we failed, then succeeded, at migrating to TypeScript by The_rationalist on Sunday October 13, 2019 @05:46PM (#21243329)
Elm is not compatible with js library or at least it's not seamless.
Re:How we failed, then succeeded, at migrating to TypeScript by zachrose on Monday October 14, 2019 @10:18PM (#21255011)
Yeah well, sometimes js library isn’t compatible with js library either
Re:How we failed, then succeeded, at migrating to TypeScript by k__ on Sunday October 13, 2019 @06:22PM (#21243572)
CS is what happens when you let Ruby devs write JS.

TS is what happens when you let .net devs write JS.

Let's see how that turns out in the long run.

Re:How we failed, then succeeded, at migrating to TypeScript by h_r on Sunday October 13, 2019 @11:12PM (#21244976)
The most depressing thing for me as someone who loves F# is how `.net` is nearly synonymous with C# in most people's minds
Re:How we failed, then succeeded, at migrating to TypeScript by k__ on Monday October 14, 2019 @08:13AM (#21247413)
I have the feeling Reason has more in common with F# than TypeScript, haha.
Re:How we failed, then succeeded, at migrating to TypeScript by pointerpointer on Sunday October 13, 2019 @07:23PM (#21243973)
> Reading my old code, I was surprised by how clean it looks. How easy it is to digest. There is a certain sense of calm when your brain doesn't have to process all the visual clutter of a C-style syntax. I miss that.

Indeed, Coffeescript is one of the finest languages I wrote in. Consider that 95% of the time we are reading code, what is the win of TS with a linter? The TS codebases I've worked on really hurt my eyes and brain, and that for some stupid website where type safety hardly makes any difference at all. And all those average web developers I've worked with bragging about type safety while the code they are producing is full of wrong constructs, bad naming, dependent on heavy tooling, etc..