TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

CoffeeScript for TypeScript

162 pointsby paulsbabout 2 years ago

32 comments

hsn915about 2 years ago
Way back in the early 2010s I was very &quot;excited&quot; about coffee script and similar projects. They sounded like they should be great for productivity.<p>When I actually tried to write a project in coffee script, the results were the opposite of what I expected.<p>The code was harder to read, harder to modify, harder to understand, harder to reason about.<p>There&#x27;s something about removing stuff from syntax that makes programming harder. My hypothesis is this: your brain has to spend extra effort to &quot;decompress&quot; the terse syntax in order to understand it, and this makes reading code unnecessarily difficult.<p>So I fundamentally disagree with the underlying premise of these projects, which seems to be based on PG&#x27;s concept of &quot;terse is power&quot;.<p>My experience suggests the opposite: there&#x27;s power in being explicit. Type declaration is an example of such a feature: it makes explicit something about the code that was implicit.<p>Type declarations add more to the parse tree, and require you to type more, but they actually give you more power.<p>The same can be said about being explicit in the language constructs.<p>There of course has to be a balance. If everything is way too explicit (more so than needed) then your brain will do the opposite of what it needs to do with terse code: it has to spend more effort to remove the extra fluff to get to the essence of what the code is doing.<p>Being terse is good, up to a point. Same with being explicit.<p>Languages that try to bias too strongly towards one extreme or the other tend to miss the mark. Instead of aiming for balance, they start to aim for fulfilling some higher telos.
评论 #34964046 未加载
评论 #34963578 未加载
评论 #34968087 未加载
评论 #34963450 未加载
评论 #34964123 未加载
评论 #34963518 未加载
评论 #34968605 未加载
评论 #34968062 未加载
评论 #34967912 未加载
评论 #34966450 未加载
评论 #34964767 未加载
lukehobanabout 2 years ago
It’s funny - when we were first designing TypeScript - I often described it as &quot;TypeScript is to CoffeeScript as C#&#x2F;C++&#x2F;Java is to Ruby&quot; often adding &quot;and there are 50x more of the former developers than the latter&quot; [0]. And CoffeeScript’s approach of transpiling down to clean JavaScript was a big inspiration for TypeScript. In the 10 years since then, some of the Ruby&#x2F;CoffeeScript aesthetic has become more mainstream in other programming languages (Swift, Rust), and gradual type systems have become more of an expectation even in dynamic languages like Ruby (Sorbet), Python (mypy) and PHP (Hack). So it does seem very natural to bring these back together now like Civet is doing.<p>[0] <a href="https:&#x2F;&#x2F;medium.com&#x2F;hackernoon&#x2F;the-first-typescript-demo-905ea095a70f" rel="nofollow">https:&#x2F;&#x2F;medium.com&#x2F;hackernoon&#x2F;the-first-typescript-demo-905e...</a>
justsomeuserabout 2 years ago
Under &quot;Everything is an Expression&quot;:<p><pre><code> items = (() =&gt; { const results = []; for (const item of items) { if (item.length) { results.push(item.toUpperCase()); } else { results.push(&quot;&lt;empty&gt;&quot;); } } return results; })(); </code></pre> Seems like they are purposely making the JS version extra long. It could be:<p><pre><code> items = items.map(x =&gt; x.length &gt; 0 ? x.toUpperCase() : `&lt;empty&gt;`) </code></pre> Edit: Just realised the code on the right is the compiled code, not the &quot;equivalent hand written JS&quot;.
评论 #34963136 未加载
评论 #34963169 未加载
评论 #34963223 未加载
评论 #34963132 未加载
评论 #34963131 未加载
nforgeritabout 2 years ago
It might be me but &quot;expressive syntax&quot; does not automatically translate to any metric of productivity or &quot;fun&quot;. Especially not in a job, where we put most of our work time into reading, researching, searching, conception and discussions. Only a fraction of my work time consists of &quot;actually typing in some form of syntax&quot;.<p>I for one appreciate simplicity and would prefer Clojure anytime over Scala. The further comes with barely any syntax, has a couple of quick-to-grep concepts and once you trained your brain to read it and your editor to juggle the parens it is a lot of fun. The latter looks very nice and casual in the beginning but to me feels like a rabbit hole of complex concepts that were always heavier than the domain I was using it for. YMMV.<p>Tho civet code examples look nice I&#x27;m afraid it adds much more complexity than needed, both the concepts you have to keep in your brain&#x27;s working memory and the whole TS toolchain which is already kind of horrible these days.
voreabout 2 years ago
I&#x27;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.
评论 #34966849 未加载
评论 #34967560 未加载
评论 #34963117 未加载
Waterluvianabout 2 years ago
&quot;The Modern Way to Write TypeScript.&quot;<p>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.
评论 #34963826 未加载
0x62c1b43eabout 2 years ago
If I were going to do this, I’d probably go all the way to using ReScript, but it’s a nice idea.<p>I’m quite surprised it’s not called ToffeeScript though.
评论 #34963292 未加载
评论 #34963287 未加载
评论 #34966345 未加载
feeelaabout 2 years ago
Is this an April fools joke? You compile Coffeescript to Typescript to JavaScript to bytecode.<p>What problem ist actually solved by being able to compile pseudo-languages like Coffeescript or Typescript into each other?
评论 #34981100 未加载
评论 #34969099 未加载
Yahivinabout 2 years ago
Hello! I created Civet ask me anything.<p>Or just curse me for keeping the dream of CoffeeScript alive :P
评论 #34966018 未加载
评论 #34967778 未加载
评论 #34966294 未加载
评论 #34963908 未加载
评论 #34969096 未加载
throwaway09432about 2 years ago
Very tastefully done. Every one of these items is a huge improvement. This one in particular drives me crazy: `x.map(($) =&gt; $.name)`, `x.map .name` is almost Haskell level terseness.<p>Can this all not be done as experimental typescript though, rather than a new language?
评论 #34964117 未加载
haolezabout 2 years ago
The maintainer - Erik Demaine - seems very talented[0].<p>[0] <a href="https:&#x2F;&#x2F;github.com&#x2F;edemaine">https:&#x2F;&#x2F;github.com&#x2F;edemaine</a>
评论 #34963737 未加载
ocimboteabout 2 years ago
Everything old is new again.<p>I have had a non-trivial experience with CoffeeScript. Maybe one can find the syntax easier on the eye, but it is always at the cost of added ambiguity, both for the parser and the reader.<p>After one too many parsing error debug session in CS, I just moved back to plain JS (later, TS), only to be happy with it ever after. to the point that after this comment, I won’t even consider trying Civet further than their homepage.
runesabout 2 years ago
Just started using Civet and it&#x27;s really impressive, works well with TypeScript, understands my tsconfig.json, &amp; has a working language server.
评论 #34964208 未加载
Yaggoabout 2 years ago
I liked CoffeeScript back in the days. However, it had its problems, the biggest being too terse &#x2F; too much optional syntax.<p>I think Civet would success better if it addressed those issues by making the syntax a bit more familiar and consistent.<p>Keep the python&#x2F;ruby-like significant indentation and everything-is-expression approach, but add little more verbosity for clarity, for example:<p><pre><code> - require and reserve {} for objects - require () in function calls - require explicit var&#x2F;let&#x2F;const </code></pre> Also, because CoffeeScript got so controversial reputation, I would not ride on its legacy. Just market Civet as &quot;TypeScript with modern syntax&quot;.
popcorncowboyabout 2 years ago
&quot;Experimental Typescript&quot; is a nice way to look at this. There are some great ideas (opinions?) in there and some <i>terrifying</i> ones (imho). I can literally see the bear traps waiting to take the legs off of our junior&#x2F;mid devs. But if this sparks TS to up its game I think some of the sharpest edges in Civet might be left safely as opinionated experiments while the best edges make it into the lang. +1 @Yahivin great project.
iendsabout 2 years ago
CoffeeScript solves the wrong problem. You never want to trade long term maintainability for writing code faster and more concisely. Maybe if you’re a solo developer and smarter than me there are benefits, but on a team, CoffeeScript was a detriment.<p>I spent years writing enterprise scale CoffeeScript with a sizable team and it was pretty rough. We converted to ES5 and now TypeScript (well mostly) and that solved a lot of our problems.
adamwong246about 2 years ago
Finally. I miss coffeescript everyday.
评论 #34963344 未加载
bshimminabout 2 years ago
I&#x27;m slightly surprised no one has commented on the custom infix operators. I think if I encountered the example in the wild, I&#x27;d understand it was a clamp function based purely on the names, but if it were used for anything else I&#x27;d have to spend quite a lot of time puzzling over it. Perhaps they make more sense to Haskell people, though!
donatjabout 2 years ago
I wrote this 10 years ago, it&#x27;s made the rounds. I stand by it even if it&#x27;s a little long in the tooth. I would word it a little differently these days, but it stands on it&#x27;s own.<p>I like to think I helped lead people away from CoffeeScript.<p><a href="https:&#x2F;&#x2F;donatstudios.com&#x2F;CoffeeScript-Madness" rel="nofollow">https:&#x2F;&#x2F;donatstudios.com&#x2F;CoffeeScript-Madness</a>
评论 #34964061 未加载
meandmycodeabout 2 years ago
Given that JavaScript syntax evolution seems to have stalled again (a decade of proposals for bind operator?) I feel like I know why languages like this are appearing, having written quite a bit of swift and kotlin recently, JavaScript really would benefit from shipping bind syntax.
duttaoindrilabout 2 years ago
I feel like this would be great as another Emmet style tool for the modern day - write code really quickly and have it convert to production grade typescript following all eslint &#x2F; prettier rules, and use it as a personal speed up tool for writing instead of reading.
maxcanabout 2 years ago
Maybe its being a former haskeller, but the engineer in me absolutely loves this.<p>The CTO in me is horrified at the idea of writing a whole bunch of civet code for it to die a coffeescript style slow death. If it catches on I&#x27;ll be all over it though.
capablewebabout 2 years ago
Not the first time I see the proposed pipe operator syntax but oh my god, did they have to make it so messy?<p><pre><code> data |&gt; Object.keys |&gt; console.log </code></pre> when you could have done<p><pre><code> |&gt; data Object.keys console.log </code></pre> Or even better, don&#x27;t introduce new syntax and just make it a simple function instead<p><pre><code> |&gt;(data, Object.keys, console.log)) </code></pre> Yes yes, I know &quot;|&gt;&quot; is not a legal variable&#x2F;function name right now, but also, why not?!
评论 #34963326 未加载
评论 #34967071 未加载
评论 #34967634 未加载
评论 #34963752 未加载
l0rnabout 2 years ago
Oh no it&#x27;s back :D<p>Immediately getting ptsd of abandoned coffescript codebases
radicalriddlerabout 2 years ago
If you take &quot;Modern&quot; in the same vein as &quot;Modern Art&quot;, then yes, I guess you could say it&#x27;s &quot;The Modern Way to write Typescript&quot;.
评论 #34964064 未加载
fortyabout 2 years ago
If you don&#x27;t want to make the same mistake as me: don&#x27;t ever choose to use a language whose syntax doesn&#x27;t distinguish between variable assignment and variable declaration. Yes this includes coffeescript. This seems optional in civet [1].<p>[1] <a href="https:&#x2F;&#x2F;civet.dev&#x2F;cheatsheet#variable-declaration" rel="nofollow">https:&#x2F;&#x2F;civet.dev&#x2F;cheatsheet#variable-declaration</a>
评论 #34964202 未加载
jcuenodabout 2 years ago
The greatest thing about this thread is that I realize I&#x27;m not alone in my nostalgia for coffeescript.
评论 #34971978 未加载
iansowinskiabout 2 years ago
Ah **, here we go again
jatinsabout 2 years ago
I kinda like it.<p>I wouldn&#x27;t use it in a team project subjecting my teammates to learn &quot;yet another thing&quot; but can see myself using this for personal projects
agumonkeyabout 2 years ago
If you like that, there&#x27;s coconut, based on python. Similar syntactic feel and ideas. Types aside.
jevgeniabout 2 years ago
Hard pass on the switch statement.
giraffe_ladyabout 2 years ago
please just use rescript it addresses every problem with js&#x2F;ts and is simpler and you get a sound type system please.
评论 #34964074 未加载
评论 #34963200 未加载