News for hackers. Stuff that matters.
Re:The Great CoffeeScript to Typescript Migration of 2017 by dgoldstein0 on Friday May 15, 2020 @05:12PM (#23197482)
I recall when we first adopted Coffeescript, the engineers who did it touted that we had about 20% fewer lines of code as an example of coffeescript being better - a lot of which was probably just the removal of lines that only had curly-braces. In hindsight, this wasn't a good metric to judge the language on.

As a larger engineering organization, what we've definitely learned over time is that we need to prioritize readability (and maintainability) over writability - as our code is going to last a long time and the original engineer who wrote it, will likely move on to another project, team, or even company. And while maybe they train their replacement, after a second or third iteration of that, the knowledge can easily end up lost.

Coffeescript, as a language, definitely prioritizes terseness, often at the expense of readability. And we didn't have internal coding standards that pushed back on this.

But even if we had done a better job using coffeescript, we're still better off in typescript today, due to the stronger community and stronger set of available open source tools to work with the language.

Re:The Great CoffeeScript to Typescript Migration of 2017 by erikw on Friday May 15, 2020 @05:24PM (#23197627)
I see readability as a key advantage of TS. Once you are able to comfortably read type signatures, it is trivial to see what a function is supposed to do, or what a library is supposed to provide. When things don't work as expected, then it's just a matter of hopping into the debugger to inspect data inflight to find where the typings aren't matching up with reality.
Re:The Great CoffeeScript to Typescript Migration of 2017 by dgoldstein0 on Friday May 15, 2020 @05:30PM (#23197709)
yup, types are a huge advantage, especially in large codebases where you probably don't know all the people who may write code to interact with your code.

Readability of types can become an issue over time, but with the right naming of interfaces and useful type aliases, that can be mitigated to some extent. And as the typescript language and community evolve together, there are new ways to make some types even more readable - I've seen generics for getting the return type of a function, which seems potentially really useful (and some people swear by; I haven't used them extensively, but it looks like a promising idea).

Re:The Great CoffeeScript to Typescript Migration of 2017 by momokoko on Saturday May 16, 2020 @02:44AM (#23201025)
After ten years of JavaScript and after working on TypeScript apps that have now been around for 5+ years, I can assure you TypeScript is less maintainable long term than most languages.

Did you know that TypeScript’s type system is turing complete? Good luck figuring out literal bespoke type frameworks in TypeScript. Did you know you can have a TypeScript application that takes more than 8GB of memory to compile?

TypeScript is literally a Microsoft play to regain Visual Studio market share they lost by creating a language that much like C# and Java, practically speaking, requires a massive feature rich IDE for most developers to write software efficiently with.

You all fell for it, and at this point it’s too late. Millions of extra development hours will wasted maintaining legacy TypeScript apps for years due to a Microsoft marketing stroke of genius.

Re:The Great CoffeeScript to Typescript Migration of 2017 by d3nj4l on Saturday May 16, 2020 @06:50AM (#23202358)
If genuine developer satisfaction from everyone I know IRL who's used typescript is due to Microsoft's marketing, I say they deserve to win this one.
Re:The Great CoffeeScript to Typescript Migration of 2017 by Shacklz on Friday May 15, 2020 @06:10PM (#23198114)
> where the typings aren't matching up with reality.

There are also libraries which provide runtime type validation, such as zod or io-ts. Can only recommend; they allow that in combination with typescript's strict mode your types become completely reliable.

Re:The Great CoffeeScript to Typescript Migration of 2017 by brazzy on Friday May 15, 2020 @06:38PM (#23198341)
Uh... welcome to static typing. Yes, it's nice.
Re:The Great CoffeeScript to Typescript Migration of 2017 by 2019-nCoV on Friday May 15, 2020 @06:27PM (#23198256)
It is not at all trivial to see what a function is supposed to do from its type sig. There are an infinite number of valid type safe implementations for:

    transform(a: number): number
Re:The Great CoffeeScript to Typescript Migration of 2017 by keymone on Friday May 15, 2020 @06:42PM (#23198374)
It makes a number out of a number. Type signature isn’t supposed to explain the implementation, just the interface.
Re:The Great CoffeeScript to Typescript Migration of 2017 by hombre_fatal on Friday May 15, 2020 @07:22PM (#23198668)
Something you run into when adding Typescript annotations to existing JS / libraries in the wild is when the signature turns out to be:

    function transform(a: number | string): number | "" | false
And it's usually all by accident. And it works because in practice it's used with a `if (!transform(x))` check.

Static typing doesn't just tell you what's going on, but it also helps you keep your implementation honest with your intent. It's also why it's a good habit to annotate top-level functions instead of relying on their inference.

Re:The Great CoffeeScript to Typescript Migration of 2017 by ygra on Saturday May 16, 2020 @04:29AM (#23201517)
You can sometimes use overloads to make it better:

    function transform(a: number): number
    function transform(a: string): false
    function transform(""): ""
Depending on how predictable the output is from the types, of course. But for many things it works better than just using union types everywhere.
Re:The Great CoffeeScript to Typescript Migration of 2017 by realharo on Saturday May 16, 2020 @03:54AM (#23201338)
This is especially true with `| undefined` helping address the billion dollar mistake.
Re:The Great CoffeeScript to Typescript Migration of 2017 by 2019-nCoV on Friday May 15, 2020 @08:36PM (#23199232)
Exactly. The parent post claimed:

> Once you are able to comfortably read type signatures, it is trivial to see what a function is supposed to do

Typing gives minimal insight into what a function actually "does".

The solution is intention revealing naming, available in all languages.

Re:The Great CoffeeScript to Typescript Migration of 2017 by gavinray on Friday May 15, 2020 @10:26PM (#23199932)
It doesn't really matter what the function does, if the input and output signatures are Interfaces or Types that have been annotated with JSDoc.

You see "Put an object with these properties and types in, get an object of this shape back out."

The beauty of types is in this black-box, abstract behavior.

You, as a library author, can define an Interface/Contract for the behavior of something completely abstractly, and other people can all use each other's implementations or contribute original ones because they obey the contract.

Think about an "Abstract class File, which implements open, read, and write."

There are a lot of ways you could write these methods but if your type signatures match the inputs and outputs they're all equally valid with predictable behavior.

Design by contract is a beautiful thing.

Re:The Great CoffeeScript to Typescript Migration of 2017 by keymone on Saturday May 16, 2020 @07:37AM (#23202603)
it matters when the function isn't pure but otherwise contracts are good.
Re:The Great CoffeeScript to Typescript Migration of 2017 by int_19h on Friday May 15, 2020 @09:01PM (#23199423)
Naming is where it starts, but the type signature also carries plenty of information it it, especially once you get to non-primitive types.
Re:The Great CoffeeScript to Typescript Migration of 2017 by baddox on Friday May 15, 2020 @05:33PM (#23197726)
In my view, the primary advantage of CoffeeScript was to provide ways to avoid JavaScript footguns. I think that a combination of ES 2015 and wider propagation of best practices have made many such footguns avoidable in practice without using CoffeeScript.
Re:The Great CoffeeScript to Typescript Migration of 2017 by city41 on Friday May 15, 2020 @05:49PM (#23197891)
But it brought along its own footguns. The article has one example

> For example, we had a major production bug in the fall of 2013 due to a misplaced space character.

Re:The Great CoffeeScript to Typescript Migration of 2017 by agency on Friday May 15, 2020 @06:19PM (#23198181)
Definitely my experience. Implicit returns are just a breathtakingly bad idea and I have personally witnessed them cause countless bugs.
Re:The Great CoffeeScript to Typescript Migration of 2017 by city41 on Friday May 15, 2020 @06:30PM (#23198282)
I think they can be ok in a language where it’s been well thought out. Like implicit return in clojure has never bugged or surprised me.
Re:The Great CoffeeScript to Typescript Migration of 2017 by sullyj3 on Saturday May 16, 2020 @02:41PM (#23206004)
Interesting, I've never heard complaints about implicit returns before. I really enjoy them in languages like rust. What kind of bugs?
Re:The Great CoffeeScript to Typescript Migration of 2017 by agency on Tuesday May 19, 2020 @12:43PM (#23236973)
I recall several resulting from the fact that lodash's _.forEach terminates iteration early if the function you pass it returns a falsey value for any element. Most people (myself included) weren't aware of this functionality and thought of the callback as a void function and weren't even thinking of what the last expression in it would evaluate to.
Re:The Great CoffeeScript to Typescript Migration of 2017 by sullyj3 on Sunday May 24, 2020 @12:24PM (#23292580)
That just seems like a poor choice of api design for forEach, rather than a fundamental problem with implicit returns.
Re:The Great CoffeeScript to Typescript Migration of 2017 by acdha on Friday May 15, 2020 @05:57PM (#23197980)
That matches my experience: the pitch was writing less, safer code but I found that JSHint (back then) had a comparable effect without a stop-the-world migration and a lot of the size reductions weren’t significant compared to following any style standards for naming, comments, etc.
Re:The Great CoffeeScript to Typescript Migration of 2017 by blitmap on Friday May 15, 2020 @05:16PM (#23197521)
I think it does depend on how familiar the syntax feels to each individual. To me Coffeescript is the right balance. I absolutely love writing Literate Coffeescript. I am _not_ a fan of strictly typed languages but I do hope Coffeescript finds a friendly syntax for gradual typing like TS in the future. I usually prototype in a 'ducky' way and then lock down type expectations when I'm polishing.
Re:The Great CoffeeScript to Typescript Migration of 2017 by dgoldstein0 on Friday May 15, 2020 @06:08PM (#23198090)
this is totally fair, but these days you are far more likely to find engineers to hire who know JavaScript or Typescript, than Coffeescript. This certainly matters more to larger projects and larger companies.
Re:The Great CoffeeScript to Typescript Migration of 2017 by jessaustin on Saturday May 16, 2020 @12:21AM (#23200471)
I can understand that people don't prefer coffeescript, but if someone "knows" JS or TS they could surely use coffeescript if they needed to do so... since we're still calling them "engineers" anyway.
Re:The Great CoffeeScript to Typescript Migration of 2017 by dgoldstein0 on Saturday May 16, 2020 @03:13AM (#23201138)
Sure, but if there majority of your customers want a different language? You should probably listen. That's what happened here, and we are way happier for it.

You might even guess that the "old guard" could have been against such a migration. As someone who should have been a member of that, I wasn't a fan of changing... But then got a few rude reminders from debugging coffeescript that didn't mean what I meant to write. At which point I started thinking that maybe everyone else had a point.

Re:The Great CoffeeScript to Typescript Migration of 2017 by jessaustin on Saturday May 16, 2020 @08:38AM (#23202910)
Your comment above seemed to refer to constraints in the other direction: "we can't use Lisp because the only coders available to hire only know Java!" The point is, coffeescript and javascript are much more similar than that, especially now that javascript has imperfectly copied some of coffeescript's improvements.
Re:The Great CoffeeScript to Typescript Migration of 2017 by dgoldstein0 on Saturday May 16, 2020 @05:37PM (#23207408)
It's not we can't use it, but rather using it for everything would make hiring, onboarding, and retention tougher, as well as maintenance.

Apologies if I have the wrong impression in the earlier post.