23 ms·
CoffeeScript for TypeScript
- radicalriddler 4y agoIf you take "Modern" in the same vein as "Modern Art", then yes, I guess you could say it's "The Modern Way to write Typescript".
- l0rn 4y agoOh no it's back :D Immediately getting ptsd of abandoned coffescript codebases
- vore 4y agoI'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.
- Klathmon 4y agoEh, 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.
- bigyikes 4y agoYou check in the transformed code and it’s gone, except for the Ghost of Syntactic Sugar which will haunt your codebase forever and make the juniors wonder why all the code is so awful.
- smt88 4y agoJS is flexible enough that you can get 90% of the sugar from CoffeeScript without leaving the language. That said, I always found CoffeeScript to be a worse language (syntactically) than JS.
- vichle 4y ago> 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!).
- zarzavat 4y agoDo 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!
- winrid 4y agoOh God, that = this made my heart jump a little. Is this what it's like to feel old? :)
- polyamid23 4y agowas function() { .. }.bind(this) not around yet?
- dagw 4y agoAs someone who used to be a big CoffeeScript advocate, I agree that adopting CoffeeScript over modern JavaScript isn't worth it. However adopting CoffeeScript when it came out over what JavaScript looked like at the time was a much bigger win. That being said, as much as I liked using CoffeeScript in my own personal projects, adopting it for a non-trivial project at work probably turned out to be a net mistake all things considered. The only positive was that the .js output files where clean any easy enough to work with that we could quite easily just drop CoffeeScript and continue developing directly with those .js file
- justsomeuser 4y agoUnder "Everything is an Expression": items = (() => { const results = []; for (const item of items) { if (item.length) { results.push(item.toUpperCase()); } else { results.push("<empty>"); } } return results; })(); Seems like they are purposely making the JS version extra long. It could be: items = items.map(x => x.length > 0 ? x.toUpperCase() : `<empty>`) Edit: Just realised the code on the right is the compiled code, not the "equivalent hand written JS".
- deleted 4y ago[deleted]
- deleted 4y ago[deleted]
- 8f2ab37a-ed6c 4y agoMy kingdom for "everything is an expression" in JS/TS, but that would likely require an entirely new language.
- davedx 4y agoAt some point you might as well just use lisp, right? :D
- eyelidlessness 4y agoI 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.
- slifin 4y agoHave you considered https://github.com/squint-cljs/squint 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
- deleted 4y ago[deleted]
- giraffe_lady 4y agoplease just use rescript it addresses every problem with js/ts and is simpler and you get a sound type system please.
- 0x62c1b43e 4y agoThe compilation speed of ReScript is also great
- miffy900 4y agoI took a look at rescript's facillities for migration from JS and at step 1 (https://rescript-lang.org/docs/manual/latest/converting-from-js https://rescript-lang.org/docs/manual/latest/converting-from...), it tells you: > First, copy the entire file content over to a new file called src/Main.res by using our %%raw JS embedding trick: > %%raw(`const school = require('school'); etc. `) I stopped reading there - I'm sorry but that is horrifying. Wrapping JS in in a big backtick string?! No. That's even worse that Dart-JS interop.
- Throw999999 4y agoThat is not how you normally do interop in Rescript.
- giraffe_lady 4y agook
- adamwong246 4y agoFinally. I miss coffeescript everyday.
- ezekg 4y agoIt really is one of my favorite languages. Elegant and expressive. One of my all time favorite projects was an Electron-based React app written in CoffeeScript.
- 0x62c1b43e 4y agoIf I were going to do this, I’d probably go all the way to using ReScript, but it’s a nice idea. I’m quite surprised it’s not called ToffeeScript though.
- jacknews 4y ago+1 for tofeescript. 'Civet' certainly implies your code is being processed, but I'm not sure the connotation is desirable. And all IMHO of course, but significant-whitespace is the worst idea ever.
- capableweb 4y ago> significant-whitespace is the worst idea ever Hear hear! I never heard a single argument for significant invisible characters that makes sense, ever. Who would want to have a program that fails because you used invisible character X instead of invisible character Y?
- lmm 4y agoA distinction between invisible character X and invisible character Y is a terrible idea. But indentation is very much visible; it's generally more significant to the reader than braces are, so it should be that significant to the computer too.
- Yahivin 4y agoCivets, they're nature's transpilers.
- nkozyra 4y ago> I'm not sure the connotation is desirable. You'd think not, and yet ...
- chowells 4y agoWait, what's wrong with making sure indentation and code structure are always the same? Lying indentation structure is always wrong.
- Waterluvian 4y ago"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.
- Yahivin 4y agoHelp me come up with a better slogan and I'll use it.
- gitonthescene 4y agoA Modern Way to Write Javascript?
- Waterluvian 4y agoA Great Way to Write TypeScript A Concise and Powerful Dialect of TypeScript. (my favourite but some might argue that Civet is more than a dialect. I think it's a dialect.) TypeScript, Streamlined Write Less, Do More Expressive Syntax and Faster Coding. (there's already two slogans, and this one is great, plus you don't have to repeat the name of the project in the title section) Expressive Syntax, Fast Coding. (feels a bit crisper to my ears) I think there's many ways you can say, "this is an awesome, fast, concise way to write web code that compiles to TS/JS" without suggesting it's _the_ way to write _modern_ TypeScript.
- appleiigs 4y ago"In my opinion, not to offend, acknowledging diveristy, a modern way he/she/they write typescript"
- bogdan 4y agoFor what's worth, I think your current slogan is fine.
- jevgeni 4y agoCivet: If You Like Stubbing Your Toes, You'll Love Our Switch Statements
- capableweb 4y agoNot 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?!
- ezekg 4y agoBecause that's not how the pipe operator works in any other language.
- askonomm 4y agoIn Clojure it does: (-> "Hello, World" string/uppercase (string/split #",") first string/trim) `->` is a threading-first macro, and `->>` is a threading last macro. More here: https://clojure.org/guides/threading_macros https://clojure.org/guides/threading_macros
- eyelidlessness 4y agoBeat me to it while I was typing! Alas, I’m on mobile and your example is a better illustration of the point.
- eyelidlessness 4y agoOf course it is, at least conceptually. See various lisps’ threading macros (which are of course functions over code; but they correspond exactly to mapping over a series of functions, each one supplying input to the next).
- ezekg 4y agoI totally agree, I shouldn't have been so absolute in my statement. But JS is not a lisp. The |> foo bar baz syntax doesn't jive with any other syntax in JS, but foo |> bar |> baz does.
- deleted 4y ago[deleted]
- hsn915 4y agoWay back in the early 2010s I was very "excited" about coffee script and similar projects. They sounded like they should be great for productivity. When I actually tried to write a project in coffee script, the results were the opposite of what I expected. The code was harder to read, harder to modify, harder to understand, harder to reason about. There's something about removing stuff from syntax that makes programming harder. My hypothesis is this: your brain has to spend extra effort to "decompress" the terse syntax in order to understand it, and this makes reading code unnecessarily difficult. So I fundamentally disagree with the underlying premise of these projects, which seems to be based on PG's concept of "terse is power". My experience suggests the opposite: there's power in being explicit. Type declaration is an example of such a feature: it makes explicit something about the code that was implicit. Type declarations add more to the parse tree, and require you to type more, but they actually give you more power. The same can be said about being explicit in the language constructs. 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. Being terse is good, up to a point. Same with being explicit. 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.
- technion 4y agoI didn't mind the coffeescript experience, but it's deeply hurtful to productivity to dev in a platform that doesn't end up winning.
- hsn915 4y agoIs it? I find most of the "winning" tech deeply unproductive. Have you tried developing in a project with Webpack and Redux? It's kind of its own little hell. Everything is way too slow and complicated. Tasks that should take 20 minutes take 3 hours.
- statictype 4y ago
- brianbest101 4y ago[dead]
- haolez 4y agoThe maintainer - Erik Demaine - seems very talented[0]. [0] https://github.com/edemaine https://github.com/edemaine
- luuuzeta 4y agoI recognized his face from MIT 6.006 Introduction to Algorithms course [1] [1] https://www.youtube.com/playlist?list=PLUl4u3cNGP61Oq3tWYp6V_F-5jb5L2iHb https://www.youtube.com/playlist?list=PLUl4u3cNGP61Oq3tWYp6V...
- forty 4y agoIf you don't want to make the same mistake as me: don't ever choose to use a language whose syntax doesn't distinguish between variable assignment and variable declaration. Yes this includes coffeescript. This seems optional in civet [1]. [1] https://civet.dev/cheatsheet#variable-declaration https://civet.dev/cheatsheet#variable-declaration
- Yahivin 4y agoWe trust people to make their own mistakes :)
- Yahivin 4y agoHello! I created Civet ask me anything. Or just curse me for keeping the dream of CoffeeScript alive :P
- intellix 4y agoI've got 99 problems but the tersity in TypeScript isn't one of them. Can't wait to groan that a random project we depend on uses this and I have to learn new syntax to make a 1 line change. Whenever I saw coffeescript I just felt like the developers fancied a change for change sake and doesn't have real problems to solve. It's clever though to create a new syntax, I'll give you that
- Yahivin 4y agoI like the documentation that TypeScript types provide but I'm always running into lots of small quality of life issues that wear me down. - Rest in any position - Dedented block strings - Default to const in for loops - Lack of -> function shortand - Everything is an expression - Implicit returns - Chained comparisons - Nested unbraced object literals - Optional trailing commas in arrays - Optional trailing commas in objects - x.map .name function shorthand Each one is a fairly minor concern but they all add up. I'm sure different people will have a different list of favorite features as well. One of my goals in creating Civet was to fix my top 100 issues with TS syntax while being 99% backward compatible. The ultimate goal being: TS with my top 100 issues fixed will be the best language I have ever used.
- duttaoindril 4y agoHey Yahivin! I love the idea and would love to use it and spread it. I think the best way to jumpstart that is a VS Code extension that allows Civet to be used as an Emmet style tool for the modern developer - write code really quickly and have it convert to production grade typescript following all your eslint / prettier rules, and use it as a personal speed up tool for just writing. When your coworkers start asking how you're moving so fast you tell them about Civet!
- Yahivin 4y ago
- runes 4y agoJust started using Civet and it's really impressive, works well with TypeScript, understands my tsconfig.json, & has a working language server.
- Yahivin 4y agoThat's awesome to hear! There's still a lot of improvements we want to add to the LSP so it's only going to get better from here.
- donatj 4y agoI wrote this 10 years ago, it's made the rounds. I stand by it even if it's a little long in the tooth. I would word it a little differently these days, but it stands on it's own. I like to think I helped lead people away from CoffeeScript. https://donatstudios.com/CoffeeScript-Madness https://donatstudios.com/CoffeeScript-Madness
- Yahivin 4y agoGood news! Civet fixes several of the more contentious design decisions from CoffeeScript by trying to be more in line with ES semantics. You need to declare variables by default in Civet. You can opt in to CoffeeScript's automatic var if you need to migrate from a CoffeeScript codebase by using the "civet autoVar" directive. More info: https://civet.dev/cheatsheet#variable-declaration https://civet.dev/cheatsheet#variable-declaration
- throwaway09432 4y agoVery tastefully done. Every one of these items is a huge improvement. This one in particular drives me crazy: `x.map(($) => $.name)`, `x.map .name` is almost Haskell level terseness. Can this all not be done as experimental typescript though, rather than a new language?
- Yahivin 4y agoCivet aims to be 99% compatible with existing TypeScript so it could be considered an experimental TypeScript. With any luck Civet catches on and does to TS what CoffeeScript did to ES and all the best features trickle into the standard eventually. The difficult part for TS/JS is they can't easily opt into some of the more whitespace/context sensitive features without breaking changes to existing code or forcing people to opt in with a "jsNext" directive or something.
- duttaoindril 4y agoI 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 / prettier rules, and use it as a personal speed up tool for writing instead of reading.
- jatins 4y agoI kinda like it. I wouldn't use it in a team project subjecting my teammates to learn "yet another thing" but can see myself using this for personal projects
- iansowinski 4y agoAh **, here we go again
- lukehoban 4y agoIt’s funny - when we were first designing TypeScript - I often described it as "TypeScript is to CoffeeScript as C#/C++/Java is to Ruby" often adding "and there are 50x more of the former developers than the latter" [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/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. [0] https://medium.com/hackernoon/the-first-typescript-demo-905ea095a70f https://medium.com/hackernoon/the-first-typescript-demo-905e...
- jevgeni 4y agoHard pass on the switch statement.
- Yaggo 4y agoI 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".
- deleted 4y ago[deleted]
- feeela 4y agoIs this an April fools joke? You compile Coffeescript to Typescript to JavaScript to bytecode. What problem ist actually solved by being able to compile pseudo-languages like Coffeescript or Typescript into each other?
- altun 4y agoThe real joke, I guess, is that hundreds of people are talking about this.
- Leftium 4y agoI used to use CoffeeScript because the syntax was more convenient. I could do the same thing with less code. Less code can mean less maintenance (although some people have said CoffeeScript can overdo this...) Now I use TypeScript to get the benefit of type-checking. It really helps catch silly little mistakes. I would use Civet just to be able to use the new pipe operator syntax. There are even compilers that compile future versions of JS into the current version of JS so future language features can be used in current browsers. I've heard JS is the new assembly language.
- ocimbote 4y agoEverything old is new again. 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. 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.
- agumonkey 4y agoIf you like that, there's coconut, based on python. Similar syntactic feel and ideas. Types aside.
- bshimmin 4y agoI'm slightly surprised no one has commented on the custom infix operators. I think if I encountered the example in the wild, I'd understand it was a clamp function based purely on the names, but if it were used for anything else I'd have to spend quite a lot of time puzzling over it. Perhaps they make more sense to Haskell people, though!
- meandmycode 4y agoGiven 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.
- nforgerit 4y agoIt might be me but "expressive syntax" does not automatically translate to any metric of productivity or "fun". 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 "actually typing in some form of syntax". 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. Tho civet code examples look nice I'm afraid it adds much more complexity than needed, both the concepts you have to keep in your brain's working memory and the whole TS toolchain which is already kind of horrible these days.
- popcorncowboy 4y ago"Experimental Typescript" is a nice way to look at this. There are some great ideas (opinions?) in there and some terrifying ones (imho). I can literally see the bear traps waiting to take the legs off of our junior/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.
- iends 4y agoCoffeeScript 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. 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.
- maxcan 4y agoMaybe its being a former haskeller, but the engineer in me absolutely loves this. 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'll be all over it though.
- jcuenod 4y agoThe greatest thing about this thread is that I realize I'm not alone in my nostalgia for coffeescript.
- Yahivin 4y agoThere are dozens of us! :)