Live data from Hacker News

CoffeeScript for TypeScript

civet.dev

91–100 of 143 posts

Re: CoffeeScript for TypeScript

#91
post #2

I'm not sure if getting some extra syntactic sugar is worth adopting a whole other language into a codebase: at least, that seemed to be one of the lessons from CoffeeScript.

Do you like writing this everywhere?

    var that = this;
    function() {
      ...
    }
Back when there was no async/await and no promises, passing callbacks like this was extremely tedious, and node.js had a lot. CoffeeScript was worth using for the fat arrows alone.

CoffeeScript didn't die. JavaScript (ES3/5) died and we are all using CoffeeScript now!

Re: CoffeeScript for TypeScript

#92
post #35

Earlier quoted context omitted.

I find that Go errs way too strongly on the explicit side, but overall it's still better than many other alternatives. For error handling I tend to write in a style where errors are either asserted out or "folded". If I do several operations in sequence any of them could err, I code in a way where I don't check every single op: instead I make some kind of "error accumulator", or write the code in a style such that if…

Rust is one of the few languages I've seen that really does error handling right. Errors are still values in Rust - usually as part of the `Result` type - but unlike Go, it actually has tools to let you deal with them in a convenient way, like the `?` propagation operator ( https://doc.rust-lang.org/book/ch09-02-recoverable-errors-wi... ), or the functions on the `Result` type like `map`, `and_then`, `map_err`, or cr…

The fact that the anyhow/thiserror crates are basically required, or you have to make a bespoke enum for your crate's errors and write conversion functions for them, is not great.

The try operator and Result type is amazing though.

Re: CoffeeScript for TypeScript

#94
post #47

"The Modern Way to Write TypeScript." I feel like this is exactly the right kind of slogan for a project like this. Smug and opinionated, disregarding anyone who might not feel the same.

Help me come up with a better slogan and I'll use it.

Civet: If You Like Stubbing Your Toes, You'll Love Our Switch Statements

Re: CoffeeScript for TypeScript

#95
post #11

Earlier quoted context omitted.

At some point you might as well just use lisp, right? :D

I love me some lisp, but I definitely prefer my JS-hosted code to be as close to JS language and semantics as possible (and that’s after a few years working in ClojureScript). Then again I’m commenting in a thread about an article with CoffeeScript in the title so I’m probably the weird one here.

Have you considered https://github.com/squint-cljs/squint ?

Personally I couldn't let go of Clojure's other advantages but at least using the syntax would let you step off the syntax churn bus

Re: CoffeeScript for TypeScript

#96
post #5
post #2

I'm not sure if getting some extra syntactic sugar is worth adopting a whole other language into a codebase: at least, that seemed to be one of the lessons from CoffeeScript.

Eh, as long as the team is on board, and the sugar is simple enough and maps well to the underlying language without a ton of extra code, then I have no issues with it. If it ever becomes a liability, you just check in the "transformed" code and it's gone.

> If it ever becomes a liability, you just check in the "transformed" code and it's gone.

I've done this and regretted it - CS transpires to ES3 and specifically null chaining is completely unreadable.

From a backend perspective it's no biggie to instead keep the CS dependency and gradually convert files manually when you have to make changes anyway, or when you have 15 minutes to spare between meetings.

You become fluent enough to not even need tests after a while (yikes!).

Re: CoffeeScript for TypeScript

#97
post #2

I'm not sure if getting some extra syntactic sugar is worth adopting a whole other language into a codebase: at least, that seemed to be one of the lessons from CoffeeScript.

Do you like writing this everywhere? var that = this; function() { ... } Back when there was no async/await and no promises, passing callbacks like this was extremely tedious, and node.js had a lot. CoffeeScript was worth using for the fat arrows alone. CoffeeScript didn't die. JavaScript (ES3/5) died and we are all using CoffeeScript now!

Oh God, that = this made my heart jump a little. Is this what it's like to feel old? :)

Re: CoffeeScript for TypeScript

#98

Not the first time I see the proposed pipe operator syntax but oh my god, did they have to make it so messy? data |> Object.keys |> console.log when you could have done |> data Object.keys console.log Or even better, don't introduce new syntax and just make it a simple function instead |>(data, Object.keys, console.log)) Yes yes, I know "|>" is not a legal variable/function name right now, but also, why not?!

Implementation looks dead simple for this too:

    $ = (f, x) => f(x)
    flip = f => (x, y) => f(y, x)
    |> = (x, ...fs) => fs.reduce(flip($), x)
However, |> in typescript is quite hard to type (no recursive types). The best approximation you can get is to manually insert

   |> = (x:A, f1:(a:A)=>B1)
   |> = (x:A, f1:(a:A)=>B1, f2:(b1:B1)=>B2)
At that point, a simpler binary function will make more sense

   |> = flip($)
And tsc will interpret the types in the pipe more correctly. Of course, the compiler can allow functions to be called without parentheses to avoid a macro for pipe calls, which will bring our definitions to

     $ = (f, x) => f x
     flip = f => (x, y) => f y x
     |> = (x, f) => (flip $) x f
It might also help to add a simpler function composition function too, as it will greatly help reuse without requiring you to write lambdas

     $ = (f, x) => f x
     flip = f => (x, y) => f y x
     . = (f, g) => x => $ f (g x)
     |> = . flip $
It could also help to remove those pesky parentheses from lambda definitions too, maybe with simpler declarations like `f x y =` converting to `f = (x, y) =>` and enabling automatic currying:

     $ f x = f x
     flip f x y = f y x
     . f g x = $ f (g x)
     |> = . flip $
But, have you noticed that we mostly have binary functions? We could greatly improve readability by making our "modifier" functions (aka combinators or adverbs) into operators. So civet could implement a special syntax for operator definition, and then we would write for definitions like

     ($) f x = f x
     flip f x y = f y x
     (.) f g x = f $ (g x)
     (|>) = flip . $
(Oh wait, does this look like something else?) So we would be able to express `console.log(Object.keys(data))` like

    data
      |> Object.keys
      |> console.log
or equivalently

   (console.log . Object.keys) $ data
without having to special case for pipes! But more importantly, if you enjoy the Clojure method of piping, you can define

    |>> x f ...fs = f ? |>> (f x) ...fs : x
which would give you the syntax you like. And I have a feeling the types will compile just right in a language that looks like this...

Re: CoffeeScript for TypeScript

#99
post #49

Earlier quoted context omitted.

I didn't mind the coffeescript experience, but it's deeply hurtful to productivity to dev in a platform that doesn't end up winning.

Yeah, I like a lot of the language features here, especially: - Everything is an expression - Pattern matching - Spread in any position - Dedented strings/templates However, I wouldn't use it, because the chance of it becoming abandonware that I just have to migrate off of later is way too high. I'll write a few extra TypeScript characters here and there for the stability.

Unless civet's compiled output is hard to read you could always just check in the compiled Typescript source and continue from there if it gets abandoned. Not much of a risk when the migration is built in by the way the tool works in normal use.

Re: CoffeeScript for TypeScript

#100
I liked CoffeeScript back in the days. However, it had its problems, the biggest being too terse / too much optional syntax.

I think Civet would success better if it addressed those issues by making the syntax a bit more familiar and consistent.

Keep the python/ruby-like significant indentation and everything-is-expression approach, but add little more verbosity for clarity, for example:

  - require and reserve {} for objects
  - require () in function calls
  - require explicit var/let/const
Also, because CoffeeScript got so controversial reputation, I would not ride on its legacy. Just market Civet as "TypeScript with modern syntax".
Post reply on HN