tag:blogger.com,1999:blog-11523536.post5219696907755537725..comments2023-10-28T06:20:02.504-04:00Comments on sernaferna: Beautiful Code: Computer-Generated CodeDavid Hunterhttp://www.blogger.com/profile/08992882297558499646noreply@blogger.comBlogger6125tag:blogger.com,1999:blog-11523536.post-72516118056527535882010-01-14T01:14:13.702-05:002010-01-14T01:14:13.702-05:00The C pre-processor is actually available to other...The C pre-processor is actually available to other languages. I've used #defines to write macros to reduce the tedium of writing tight crypto code in Java. After running through gcc's preprocessor, I get legal Java as the output, and gcc doesn't complain that it's not valid C.<br /><br />I believe m4 has been designed to provide macros for arbitrary languages, but I didn't feel like learning m4 macros.Anonymoushttps://www.blogger.com/profile/15208140686921256302noreply@blogger.comtag:blogger.com,1999:blog-11523536.post-806204043327395972008-08-05T11:02:00.000-04:002008-08-05T11:02:00.000-04:00Your point is correct; if all you’re doing is movi...Your point is correct; if all you’re doing is moving your loop to an earlier point in the process, you’re probably not buying yourself anything. For this technique to be useful, the amount of work to be done by the computer would have to be less, and/or you’d have to have good benchmarks to prove that you’re saving the computer time, not just moving instructions from place to place.<BR/><BR/>Generating code at runtime, in addition to being very strange to the eyes—meaning that you’ll have to document it well for future developers—would also only work in very isolated situations. The example that Petzold gave in the book, for the image processing, was detailed enough that I didn’t completely follow it, but he also had some very good numbers to back it up. (In fact, he documents that it’s a technique that goes all the way back to the BitBlt code in the early versions of Windows; instead of generating .NET code, of course, BitBlt was generating assembly. I don’t have the book in front of me, so I can’t give details about that, but Petzold shows how much of a performance gain it was for BitBlt.)David Hunterhttps://www.blogger.com/profile/08992882297558499646noreply@blogger.comtag:blogger.com,1999:blog-11523536.post-22435101538786617862008-08-01T05:39:00.000-04:002008-08-01T05:39:00.000-04:00My apologies if this is a silly question -- I'm re...My apologies if this is a silly question -- I'm really not that good of a programmer -- but I fail to see the value in the first example. If the program is given an arbitrary image to process, the code generator will have to go through all of those same <I>if</I> statements and loops in order to generate <I>someRidiculousFunction()</I>, right? I mean, I can see how this could be useful if it could use the same process to generate multiple <I>someRidiculousFunction()</I>s that all used the same original loop (possibly with <I>case</I> statements instead of <I>if</I>s), but the loop and <I>if</I>s would still be there somewhere, or else the work couldn't get done. You're basically just moving the loops and <I>if</I>s to an earlier point in the process.<BR/><BR/>I don't doubt that in some situations it is more efficient to create throwaway computer-generated code than to do it in a more traditional way. However, the example given does not seem like a good one.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-11523536.post-20707512516977605192008-07-30T00:04:00.000-04:002008-07-30T00:04:00.000-04:00This is a lovely concept, isn't it? I used to do a...This is a lovely concept, isn't it? I used to do a very limited version of this in an ancient procedural database called Superbase; it had a database language that had an 'execute' function that would run arbitrary text strings as commands to the database language. You could write modules that would then write customized mini-programs and run them, depending on program variables at runtime. <BR/><BR/>It made the language extremely flexible.Roberthttps://www.blogger.com/profile/07160061641869302097noreply@blogger.comtag:blogger.com,1999:blog-11523536.post-66631190298197747282008-07-22T17:34:00.000-04:002008-07-22T17:34:00.000-04:00Many apologies to Diomidis Spinellis, for misspell...Many apologies to Diomidis Spinellis, for misspelling his name in this post! It has now been corrected—hopefully before anyone noticed, or was offended.David Hunterhttps://www.blogger.com/profile/08992882297558499646noreply@blogger.comtag:blogger.com,1999:blog-11523536.post-89470571425466414252008-07-21T08:51:00.000-04:002008-07-21T08:51:00.000-04:00Regular expression is a good example here, too. Th...Regular expression is a good example here, too. The RE library will generate code at runtime that matches the patternAnonymousnoreply@blogger.com