Tuesday, August 19, 2014

Hacking on Atom Part I: CoffeeScript

Atom is written in CoffeeScript rather than raw JavaScript. As you can imagine, this is contentious with “pure” JavaScript developers. I had a fairly neutral stance on CoffeeScript coming into Atom, but after spending some time exploring its source code, I am starting to think that this is not a good long-term bet for the project.

Why CoffeeScript Makes Sense for Atom

This may sound silly, but perhaps the best thing that CoffeeScript provides is a standard way to declare JavaScript classes and subclasses. Now before you get out your pitchforks, hear me out:

The “right” way to implement classes and inheritance in JavaScript has been of great debate for some time. Almost all options for simulating classes in ES5 are verbose, unnatural, or both. I believe that official class syntax is being introduced in ES6 not because JavaScript wants to be thought of as an object-oriented programming language, but because the desire for developers to project the OO paradigm onto the language today is so strong that it would be irresponsible for the TC39 to ignore their demands. This inference is based on the less aggressive maximally minimal classes proposal that has superseded an earlier, more fully-featured, proposal, as the former states that “[i]t focuses on providing an absolutely minimal class declaration syntax that all interested parties may be able to agree upon.” Hooray for design by committee!

Aside: Rant

The EcmaScript wiki is the most frustrating heap of documentation that I have ever used. Basic questions, such as, “Are Harmony, ES.next, and ES6 the same thing?” are extremely difficult to answer. Most importantly, it is impossible to tell what the current state of ES6 is. For example, with classes, there is a proposal under harmony:classes, but another one at Maximally Minimal Classes. Supposedly the latter supersedes the former. However, the newer one has no mention of static methods, which the former does and both Traceur and JSX support. Perhaps the anti-OO folks on the committee won and the transpilers have yet to be updated to reflect the changes (or do not want to accept the latest proposal)?

In practice, the best information I have found about the latest state of ES6 is at https://github.com/lukehoban/es6features. I stumbled upon that via a post in traceur-compiler-discuss that linked to some conference talk that featured the link to the TC39 member’s README.md on GitHub. (The conference talk also has an explicit list of what to expect in ES7, in particular async/await and type annotations, which is not spelled out on the EcmaScript wiki.) Also, apparently using an entire GitHub repo to post a single web page is a thing now. What a world.

To put things in perspective, I ran a git log --follow on some key files in the src directory of the main Atom repo, and one of the earliest commits I found introducing a .coffee file is from August 24, 2011. Now, let’s consider that date in the context of modern JavaScript transpiler releases:

As you can see, at the time Atom was spinning up, CoffeeScript was the only mature transpiler. If I were starting a large JavaScript project at that time (well, we know I would have used Closure...) and wanted to write in a language whose transpilation could be improved later as JavaScript evolved, then CoffeeScript would have made perfect sense. Many arguments about what the “right JavaScript idiom is” (such as how to declare classes and subclasses) go away because CoffeeScript is more of a “there’s only one way to do it” sort of language.

As I mentioned in my comments on creating a CoffeeScript for Objective-C, I see three primary benefits that a transpiled language like CoffeeScript can provide:

  • Avoids boilerplate that exists in the target language.
  • Subsets the features available in the source language to avoid common pitfalls that occur when those features are used in the target language.
  • Introduces explicit programming constructs in place of unofficial idioms.

Note that if you have ownership of the target language, then you are in a position to fix these things yourself. However, most of us are not, and even those who are may not be that patient, so building a transpiler may be the best option. As such, there is one other potential benefit that I did not mention in my original post, but has certainly been the case for CoffeeScript:

  • Influences what the next version of the target language looks like.

But back to Atom. If you were going to run a large, open source project in JavaScript, you could potentially waste a lot of time trying to get your contributors to write JavaScript in the same way as the core members of the project. With CoffeeScript, there is much less debate.

Another benefit of using CoffeeScript throughout the project is that config files are in CSON rather than JSON. (And if you have been following this blog, you know that the limitations of JSON really irritate me. Go JSON5!) However, CSON addresses many of shortcomings of JSON because it supports comments, trailing commas, unquoted keys, and multiline strings (via triple-quote rather than backslashes). Unfortunately, it also supports all of JavaScript as explained in the README:

“CSON is fantastic for developers writing their own configuration to be executed on their own machines, but bad for configuration you can't trust. This is because parsing CSON will execute the CSON input as CoffeeScript code...”
Uh...what? Apparently there’s a project called cson-safe that is not as freewheeling as the cson npm module, and it looks like Atom uses the safe version. One of the unfortunate realities of the npm ecosystem is that the first mover gets the best package name even if he does not have the best implementation. C’est la vie.

Downsides of Atom Using CoffeeScript

I don’t want to get into a debate about the relative merits of CoffeeScript as a language here (though I will at some other time, I assure you), but I want to discuss two practical problems I have run into that would not exist if Atom were written in JavaScript.

First, many (most?) Node modules that are written in CoffeeScript have only the transpiled version of the code as part of the npm package. That means that when I check out Atom and run npm install, I have all of this JavaScript code under my node_modules directory that has only a vague resemblance to its source. If you are debugging and have source maps set up properly, then this is fine, but it does not play nice with grep and other tools. Although the JavaScript generated from CoffeeScript is fairly readable, it is not exactly how a JavaScript developer would write it by hand, and more importantly, single-line comments are stripped.

Second, because Atom is based on Chrome and Node, JavaScript developers writing for Atom have the benefit of being able to rely on the presence of ES6 features as they are supported in V8. Ordinary web developers do not have this luxury, so it is very satisfying to be able to exploit it! However, as ES6 introduces language improvements, they will not be available in CoffeeScript until CoffeeScript supports them. Moreover, as JavaScript evolves into a better language (by copying features from language like CoffeeScript), web developers will likely prefer “ordinary” JavaScript because it is likely that they will have better tool support. As the gap between JavaScript and CoffeeScript diminishes, the cost of doing something more nonstandard (i.e., using a transpiler) does not outweigh the benefits as much as it once did. Arguably, the biggest threat to CoffeeScript is CoffeeScript itself!

Closing Thoughts

Personally, I plan to develop Atom packages in JavaScript rather than CoffeeScript. I am optimistic about where JavaScript is going (particularly with respect to ES7), so I would prefer to be able to play with the new language features directly today. I don’t know how long my code will live (or how long ES6/ES7 will take), but I find comfort in knowing that I am less likely to have to rewrite my code down the road when JavaScript evolves. Finally, there are some quirks to CoffeeScript that irk me enough to stick with traditional JavaScript, but I’ll save those for another time.

79 comments:

  1. At this point I would just ignore wiki.ecmascript.org. The spec at http://people.mozilla.org/~jorendorff/es6-draft.html is feature complete (File bugs at bugs.ecmascript.org). For ES7 we are hosting our documentation on GitHub and we will eventually put the content at https://github.com/tc39/ecma262.

    ReplyDelete
  2. You've arguably missed the biggest advantage of CoffeeScript: the syntax. I don't care how many great features they throw into ES7; it won't change the fact that the Java-like syntax is not a good fit for a functional language like JS. Until they attack that issue, CoffeeScript will continue to have the advantage for development.

    What new language features doesn't CoffeeScript support, BTW? I'd be interested to hear of specific examples. In general, CoffeeScript's syntax transformations are regular enough that supporting new JS features hasn't required compiler upgrades, so this sounds a little like FUD...

    ReplyDelete
  3. @Marnen CoffeeScript doesn't support async/await or type annotations. With Babel, it's game over as far as I'm concerned.

    ReplyDelete
  4. @Marnen Oh, and also JSX for React.

    ReplyDelete
  5. A 'white hat' hacker is a moral hacker who runs penetration testing and intrusion testing. Ethical hacking is legally hacking a computer system and penetrating into its database. hackolo.com

    ReplyDelete
  6. When hired, their task is to make sure that all of their employers programs and websites remain secure from hacking attempts.Blue Portal

    ReplyDelete
  7. I learned a lot of brilliant stuff here and that's all I wanted today. This proreviewly post is probably one of the most amazing posts that I have read in my entire life and I am extremely glad that I decided to read this today. I hope to see many more posts like this on this site in the future, though.

    ReplyDelete
  8. There were also video game cheats that needed to be discovered within the game play, sometimes you were given hints and sometimes you discovered them by accident roblox jailbreak money hack

    ReplyDelete
  9. Thanks to these flaws, hackers are able to hack any Facebook account. You can easily hack facebook accounts too by using our web-based hacking application www.BluePortal.org..

    ReplyDelete
  10. Hackers are cyber criminals or online computer criminals that practice illegal hacking. They penetrate into the security system of a computer network to fetch or extract information.Android Hacking

    ReplyDelete
  11. A 'white hat' hacker is a moral hacker who runs penetration testing and intrusion testing. Ethical hacking is legally hacking a computer system and penetrating into its database.FB hack

    ReplyDelete
  12. Strong application security programs need to focus both on the code security as it’s being developed, as well as in its’ running state – and that’s where ethical hacking tools comes into play.

    ReplyDelete
  13. This comment has been removed by the author.

    ReplyDelete
  14. This blog is a punchy piece of writing, as it has a strong effect.
    Instaport

    ReplyDelete
  15. Thanks for Fantasctic blog , this web page is really wonderful
    chuyện lạ khó tin
    chuyện lạ đó đây

    ReplyDelete
  16. Great article and a nice way to promote online. I’m satisfied with the information that you provided tree removal service palm beach county

    ReplyDelete
  17. I have read your article, it is very informative and helpful for me.I admire the valuable information you offer in your articles. Thanks for posting it.
    tree removal dania beach

    ReplyDelete
  18. Great article and a nice way to promote online. I’m satisfied with the information that you provided tree removal services cooper city

    ReplyDelete
  19. I think this is one of the most significant information for me. And i’m glad reading your article. tree trimming companies coconut creek

    ReplyDelete
  20. This is a great article thanks for sharing this informative information. I will visit your blog regularly for some latest post.
    tree trimming tamarac

    ReplyDelete
  21. Hello, I have browsed most of your posts. This post is probably where I got the most useful information for my research. Thanks for posting, maybe we can see more on this.
    tree trimming services lauderhill fl

    ReplyDelete
  22. Thanks for the wonderful share. Your article has proved your hard work and experience you have got in this field. Brilliant .i love it reading. residential tree services plantation

    ReplyDelete
  23. Hi, This is a nice article you shared great information i have read it thanks for giving such a wonderful blog for the reader. tree services near me in davie fl

    ReplyDelete
  24. I have read your article, it is very informative and helpful for me.I admire the valuable information you offer in your articles. Thanks for posting it..tree care companies coral springs

    ReplyDelete
  25. I think this is one of the most significant information for me. And i’m glad reading your article. emergency tree services southwest ranches

    ReplyDelete
  26. This post is good enough to make somebody understand this amazing thing, and I’m sure everyone will appreciate this interesting things.palm tree services miramar

    ReplyDelete
  27. Hi, This is a nice article you shared great information i have read it thanks for giving such a wonderful blog for the reader. commercial tree services pembroke pines

    ReplyDelete
  28. Hello, I have browsed most of your posts. This post is probably where I got the most useful information for my research. Thanks for posting, maybe we can see more on this. Are you aware of any other websites on this subject?
    stump grinding fort lauderdale

    ReplyDelete
  29. This is my first time i visit here and I found so many interesting stuff in your blog especially it's discussion, thank you. Carding Forum

    ReplyDelete
  30. I definitely enjoying every little bit of it. It is a great website and nice share. I want to thank you. Good job! You guys do a great blog, and have some great contents. Keep up the good work. iPhone

    ReplyDelete
  31. I was just browsing through the internet looking for some information and came across your blog. I am impressed by the information that you have on this blog. It shows how well you understand this subject. Bookmarked this page, will come back for more. Guest Post

    ReplyDelete
  32. wow... what a great blog, this writter who wrote this article it's realy a great blogger, this article so inspiring me to be a better person best gaming

    ReplyDelete
  33. It is somewhat fantastic, and yet check out the advice at this treat. real estate closing gifts

    ReplyDelete
  34. Glad to chat your blog, I seem to be forward to more reliable articles and I think we all wish to thank so many good articles, blog to share with us. watch series

    ReplyDelete
  35. I read this article. I think You put a lot of effort to make this article. I like your work. christmas

    ReplyDelete
  36. It was truly significant to me. This is genuinely an extraordinary perused for me. I have bookmarked it and I am anticipating perusing new articles. Keep doing awesome. social media agency

    ReplyDelete
  37. I love the manner in which you compose and share your specialty! Interesting and unique! Keep it coming! online retailer

    ReplyDelete
  38. Beneath you will comprehend what is significant, the thought furnishes one of the connections with an energizing site: gift

    ReplyDelete
  39. I like your post. It is good to see you verbalize from the heart and clarity on this important subject can be easily observed... Sarkari Naukri

    ReplyDelete
  40. I wanted to thank you for this great read!! I definitely enjoying every little bit of it I have you bookmarked to check out new stuff you post. Amy Coney Barrett

    ReplyDelete
  41. I simply discovered this blog and have high trusts in it to proceed. Keep up the incredible work, its elusive great ones. I have added to my top picks. Much obliged to You. judi slot

    ReplyDelete
  42. Took me time to read all the comments, but I really enjoyed the article. It proved to be Very helpful to me and I am sure to all the commenters here! It’s always nice when you can not only be informed, but also entertained! relationship

    ReplyDelete
  43. It is very advantageous, despite the fact that consider the realities when it arrives at this objective. high DA

    ReplyDelete
  44. This is such a great resource that you are providing and you give it away for free. I love seeing blog that understand the value of providing a quality resource for free. Speedup Forex

    ReplyDelete
  45. I’m going to read this. I’ll be sure to come back. thanks for sharing. and also This article gives the light in which we can observe the reality. this is very nice one and gives indepth information. thanks for this nice article... judi slot online

    ReplyDelete
  46. You there, this is really good post here. Thanks for taking the time to post such valuable information. Quality content is what always gets the visitors coming. IPTV

    ReplyDelete
  47. Great job for publishing such a beneficial web site. Your web log isn’t only useful but it is additionally really creative too. RRB Group D Admit Card

    ReplyDelete
  48. I think other site owners should use this site as a model, very concise, user-friendly style and design as well as content. You are an expert on this topic!Many of our channels are in true HD providing superb picture quality and most channels have 7day catch-up so you’ll never have to miss your favourite programme again!! xtrixtv

    ReplyDelete
  49. Many guys throughout the world, I believe, are aware that the most gorgeous girls on the planet come from Ukraine. Many guys would like to meet and possibly build a family with a Ukrainian female, but they don't know where to start. So I, too, experienced this issue. I'm now corresponding with an intriguing Ukrainian girl. I'd like to suggest these guys; this is where all ukrainian brides are charismatic and kind. I can assure you that these men will not disappoint you.

    ReplyDelete
  50. Wonderful blog post! I love all the information you'd share in here. Very detailed and lots of useful info are here. I can't wait to see more post from you. Find more info here

    ReplyDelete
  51. CoffeeScript is just a prettier JavaScript. It will let you have smaller and more readable code by taking core elements of JavaScript and giving you a better way of writing it. Find the best Winchester VA Basement Waterproofing

    ReplyDelete
  52. CoffeeScript trys to be nicer JavaScript, and to keep the output code similar to the input so that debugging is trivial. Get more at https://www.treeservicemviejo.com/

    ReplyDelete
  53. One crucial difference between the two languages is that TypeScript is the superset of JavaScript while CoffeeScript is a language which is an enhanced version of JavaScript. Learn more about Orange County Tree Service

    ReplyDelete
  54. Hey man, .This was an excellent page for such a hard subject to talk about. I look forward to reading many more great posts like these. Thanks Feel free to visit my website; 바카라사이트

    ReplyDelete
  55. CoffeeScript is an attempt to expose the good parts of JavaScript in a simple way. The golden rule of CoffeeScript is: “It's just JavaScript.” The code compiles one-to-one into the equivalent JS, and there is no interpretation at runtime. See more details about the best smart installer at https://www.smarthomedc.com/

    ReplyDelete
  56. CoffeeScript is an attempt to expose the good parts of JavaScript in a simple way. The golden rule of CoffeeScript is: “It's just JavaScript.” The code compiles one-to-one into the equivalent JS, and there is no interpretation at runtime. See more details about the best smart installer

    ReplyDelete
  57. According to this survey, JavaScript clinched the #1 position as the top language in 2018. Both languages, TypeScript and CoffeeScript are relatable to the dynamic JavaScript language and have been gaining popularity in an exponential way in the developing world. Find out more about Kitchen Remodel Spokane

    ReplyDelete
  58. Great article to think about. You can check out Spokane Tree Service if you have a stump in your backyard. Check it out here.

    ReplyDelete
  59. What an amazing content! If you are looking for Tree service you can check at https://www.treeservicemviejo.com/

    ReplyDelete
  60. This month's Tiobe Index of language popularity has CoffeeScript entering its top 100 languages for the first time, ranked 64th, albeit with a rating of less than 1 percent, like most of the languages featured in the index. Figure out more about Orange County Tree Service .

    ReplyDelete
  61. I love the way you made this blog, I am very glad that I been drop by here. Keep posting for more! Click here for more info.

    ReplyDelete
  62. This comment has been removed by the author.

    ReplyDelete
  63. Nice post By reading your blog, i get inspired and this provides some useful information.

    The most important thing to start any On-demand startup is to know the approximate cost for developing it. Let's Take your pest control business to the next level! Here we are going to discuss On-Demand Pest Control App development as well as the cost and features. Contact us now!

    ReplyDelete
  64. Thank you again for all the knowledge you distribute, Good post. I was very interested in the article, it's quite inspiring I should admit.

    See now the most and trusted Spokane Certified Arborist

    ReplyDelete
  65. This comment has been removed by the author.

    ReplyDelete
  66. This comment has been removed by the author.

    ReplyDelete
  67. At My Homework Help, we are committed to providing students with the best possible academic support. We have a team of expert tutors who are available 24/7 to help students with their homework assignments. Our tutors are knowledgeable, experienced, and passionate about helping students succeed in their academic pursuits. They will work with you to ensure that you understand the subject matter and are able to complete your assignments with ease.

    ReplyDelete
  68. Usually I never comment on blogs but your article is so convincing that I never stop myself to say something about it. You’re doing a great job Man, Keep it up.

    Check my blogs at www.stampedconcretecolumbia.com

    ReplyDelete
  69. it is evident that the author provides a comprehensive overview of using CoffeeScript to extend and hack the Atom text editor. The article offers valuable insights into the benefits of CoffeeScript and its integration with Atom's development environment. It is a useful resource for developers interested in customizing and enhancing their Atom experience.
    career counseling services

    ReplyDelete
  70. If BOLINFEST is a specific term, project, or event, and you're looking for information about its changelog, I recommend checking relevant websites, forums, social media platforms, or official sources associated with the term.
    Abogado Disputas de Contratos Cerca Mí

    ReplyDelete
  71. betplay569 ความสบายสบายสำหรับในการเข้าเล่นผ่านเว็บไซต์พนันออนไลน์ pg slot ที่นอกเหนือจากตรงนี้ BETPLAY569 จะเป็นหนทางที่เหมาะสมกับคนสมัย 5G สมัยดิจิทัลสุดปี 2023 ยังมีความพิเศษ

    ReplyDelete
  72. pg ยูฟ่า168 แทง บอล สด ได้เข้ามามอบประสบการณ์ใหม่ในการแทงบอลสด pg ที่น่าตื่นเต้นมากยิ่งขึ้นสำหรับนักเดิมพันทุกคนที่หลงใหลในการแทงบอลออนไลน์การเดิมพันกับความสนุกแบบใหม่

    ReplyDelete