{"id":65,"date":"2002-11-08T14:24:08","date_gmt":"2002-11-08T19:24:08","guid":{"rendered":"\/?p=65"},"modified":"2014-07-14T10:17:43","modified_gmt":"2014-07-14T14:17:43","slug":"code_generation-2","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2002\/11\/08\/code_generation-2\/","title":{"rendered":"Code Generation"},"content":{"rendered":"<p><a href=\"http:\/\/www.iunknown.com\/Weblog\/Whenlessismore.html\">John Lam<\/a> writes about code generation as a means of capturing abstractions:<\/p>\r\n\r\n\r\n\r\n<blockquote>During my code generation experiments, I was able to condense approximately 8000 lines of hand-written C# code into about 600 lines of a custom XML language that was in turn fed to about 500 lines of scripting code that generated a functionally equivalent parser. While I was writing this software, I was continuously amazed by the subtle semantics that kept popping up while I was defining my custom XML language. This led to an iterative development process where I would see a new abstraction, modify my language, tweak my code generator, and then test the results of the change using traditional tools (in my case Visual Studio .NET).\r\n\r\n<\/blockquote>\r\n\r\n\r\n\r\n<p>Paul Graham has written a lot about how Lisp&#8217;s excellent support for code generation (macros) is its most distinguishing feature:<\/p>\r\n\r\n\r\n\r\n<blockquote>\r\n\r\nI wonder if these patterns are not sometimes evidence of case (c), the human compiler, at work. When I see patterns in my programs, I consider it a sign of trouble. The shape of a program should reflect only the problem it needs to solve. Any other regularity in the code is a sign, to me at least, that I&#8217;m using abstractions that aren&#8217;t powerful enough&#8212;often that I&#8217;m generating by hand the expansions of some macro that I need to write. (<a href=\"http:\/\/www.paulgraham.com\/lib\/paulgraham\/sec.txt\">Beating the Averages<\/a>)\r\n\r\n<\/blockquote>\r\n\r\n\r\n\r\n<blockquote>The source code of the Viaweb editor was probably about 20-25% macros.  Macros are harder to write than ordinary Lisp functions, and it&#8217;s considered to be bad style to use them when they&#8217;re not necessary.  So every macro in that code is there because it has to be.  What that means is that at least 20-25% of the code in this program is doing things that you can&#8217;t easily do in any other language. (<a href=\"http:\/\/www.paulgraham.com\/icad.html\">Revenge of the Nerds<\/a>)<\/blockquote>","protected":false},"excerpt":{"rendered":"<p>John Lam writes about code generation as a means of capturing abstractions: During my code generation experiments, I was able to condense approximately 8000 lines of hand-written C# code into about 600 lines of a custom XML language that was in turn fed to about 500 lines of scripting code that generated a functionally equivalent [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"apple_news_api_created_at":"","apple_news_api_id":"","apple_news_api_modified_at":"","apple_news_api_revision":"","apple_news_api_share_url":"","apple_news_coverimage":0,"apple_news_coverimage_caption":"","apple_news_is_hidden":false,"apple_news_is_paid":false,"apple_news_is_preview":false,"apple_news_is_sponsored":false,"apple_news_maturity_rating":"","apple_news_metadata":"\"\"","apple_news_pullquote":"","apple_news_pullquote_position":"","apple_news_slug":"","apple_news_sections":"\"\"","apple_news_suppress_video_url":false,"apple_news_use_image_component":false,"footnotes":""},"categories":[4],"tags":[70,941,71],"class_list":["post-65","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-lisp","tag-macros","tag-programming"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/65","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/comments?post=65"}],"version-history":[{"count":1,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/65\/revisions"}],"predecessor-version":[{"id":9146,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/65\/revisions\/9146"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=65"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=65"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=65"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}