<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xml:base="http://www.developerdotstar.com/community" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
 <title>developer.* Blogs - Brian Kernighan&amp;#039;s Beautiful Code? - Comments</title>
 <link>http://www.developerdotstar.com/community/node/773</link>
 <description>Comments for &quot;Brian Kernighan&#039;s Beautiful Code?&quot;</description>
 <language>en</language>
<item>
 <title>Pike and Kernighan: .6 secs: C Sharp: 2.7</title>
 <link>http://www.developerdotstar.com/community/node/773#comment-9700</link>
 <description>&lt;p&gt;...for a long string, AFTER one million iterations.&lt;/p&gt;
&lt;p&gt;See main blog post.&lt;/p&gt;
</description>
 <pubDate>Wed, 02 Jan 2008 22:46:26 -0800</pubDate>
 <dc:creator>Edward G Nilges</dc:creator>
 <guid isPermaLink="false">comment 9700 at http://www.developerdotstar.com/community</guid>
</item>
<item>
 <title>((((poot)*)*)*)</title>
 <link>http://www.developerdotstar.com/community/node/773#comment-9698</link>
 <description>&lt;p&gt;I also failed to realize that the test variable in Pike&#039;s &quot;Beautiful&quot; code isn&#039;t at all updated in matchhere() or matchstar() on behalf of match(): as in match() itself, the copy of test on the stack is used as a working variable. Basically, no effort at all was made by the Pikester to return the position of the satisfying string, and in the so-called real world, isn&#039;t this exactly your next question?&lt;/p&gt;
</description>
 <pubDate>Sun, 30 Dec 2007 04:53:46 -0800</pubDate>
 <dc:creator>Edward G Nilges</dc:creator>
 <guid isPermaLink="false">comment 9698 at http://www.developerdotstar.com/community</guid>
</item>
<item>
 <title>(((poot)*)*)</title>
 <link>http://www.developerdotstar.com/community/node/773#comment-9697</link>
 <description>&lt;p&gt;Sorry, hopefully only one more error: I imply that you DO get the address IF you pass the test string in a variable. This is incorrect since value parameters in C are copied to the stack and, if modified, that modification is lost.&lt;/p&gt;
&lt;p&gt;Which means that the original objection stands. The code isn&#039;t at all useful for finding WHERE the string, that satisfies the regular expression, exists in test. It merely finds WHETHER it occurs.&lt;/p&gt;
&lt;p&gt;Is such spare functionality Beautiful? I don&#039;t know. It sure isn&#039;t Reusable.&lt;/p&gt;
&lt;p&gt;Nonsense prevails, modesty fails&lt;br /&gt;
Grace and virtue turn into stupidity&lt;br /&gt;
While the calendar fades almost all barricades to a pale compromise&lt;br /&gt;
And our leaders have feasts on the backsides of beasts&lt;br /&gt;
They still think they&#039;re the gods of antiquity&lt;br /&gt;
If something you missed didn&#039;t even exist&lt;br /&gt;
It was just an ideal -- is it such a surprise?&lt;/p&gt;
&lt;p&gt;What shall we do, what shall we do with all this useless beauty?&lt;br /&gt;
All this useless beauty&lt;/p&gt;
</description>
 <pubDate>Fri, 28 Dec 2007 04:15:24 -0800</pubDate>
 <dc:creator>Edward G Nilges</dc:creator>
 <guid isPermaLink="false">comment 9697 at http://www.developerdotstar.com/community</guid>
</item>
<item>
 <title>kscaldef&#039;s comment on the Kernighan code in reddit</title>
 <link>http://www.developerdotstar.com/community/node/773#comment-9696</link>
 <description>&lt;p&gt;kscaldef points out, with respect to my point (1), that you don&#039;t need in a minimal implementation to support a+ where + means one or more times: you just use aa*!&lt;/p&gt;
&lt;p&gt;But I add at reddit that the code doesn&#039;t support nesting in the regular expression as in (a+c)*.&lt;/p&gt;
&lt;p&gt;It&#039;s syntactic sugar to insist that Rob should have supported postfixable strings as well as characters (although the failure to support international characters is significant). But by allowing parentheses Rob could have had strings for free as in (abc)*.&lt;/p&gt;
&lt;p&gt;I&#039;m on admittedly shaky ground. A pure mathematician would ACCEPT only character processing, equating the char with a symbol on a Turing Machine square, and assume that any string could be represented as any one of an infinity of possible characters, as Chinese ideograms represent thousands of ideas. &lt;/p&gt;
&lt;p&gt;A programmer like Rob simply restricts himself to the problem statement, so Rob did good.&lt;/p&gt;
&lt;p&gt;What remains for me unforgiveable is that this hack is considered Beautiful Code by Brian, at least without a considerable discussion of its limitations. I&#039;d accept it as neo-Primitive art if only Brian had done so.&lt;/p&gt;
</description>
 <pubDate>Thu, 27 Dec 2007 10:47:04 -0800</pubDate>
 <dc:creator>Edward G Nilges</dc:creator>
 <guid isPermaLink="false">comment 9696 at http://www.developerdotstar.com/community</guid>
</item>
<item>
 <title>Recursive brain fart ((poot)*)</title>
 <link>http://www.developerdotstar.com/community/node/773#comment-9695</link>
 <description>&lt;p&gt;Of course, most users of the Pike code will pass a string literal as the &quot;test&quot; parameter, thereby losing the address of the satisfier.&lt;/p&gt;
&lt;p&gt;(poot)*&lt;/p&gt;
</description>
 <pubDate>Thu, 27 Dec 2007 08:21:19 -0800</pubDate>
 <dc:creator>Edward G Nilges</dc:creator>
 <guid isPermaLink="false">comment 9695 at http://www.developerdotstar.com/community</guid>
</item>
<item>
 <title>Summary of the flaws I think are in the Kernighan and Pike code</title>
 <link>http://www.developerdotstar.com/community/node/773#comment-9694</link>
 <description>&lt;p&gt;A discussion of the above blog post has started on programming.reddit.com in the usual way, with complaints about literary style rather than technical remarks, because, as one poster says, pointer arithmetic is hard.&lt;/p&gt;
&lt;p&gt;Because the reddit posters complained about the political observations, I posted the following technical discussion at &lt;a href=&quot;http://programming.reddit.com/info/63vc1/comments/&quot; title=&quot;http://programming.reddit.com/info/63vc1/comments/&quot;&gt;http://programming.reddit.com/info/63vc1/comments/&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Here is a summary of what I think are the flaws in the code Rob Pike wrote for Brian Kernighan, and which Brian presents as Beautful Code in a book of that name, published this year by O&#039;Reilly, on page 3 (an unindented copy of Rob&#039;s code as keyed by me, and wrapped in a C++ class, is at my developerDotStar blog). I read C but have long since abandoned it because I don&#039;t think Beautiful Code can be written in C: the Pike code, I think, is an example of code that only seems Beautiful.&lt;/p&gt;
&lt;p&gt;I won&#039;t include any postmodern theory in this particular post despite the fact that aesthetics is political.&lt;/p&gt;
&lt;p&gt;(1) Pike&#039;s code doesn&#039;t implement a regular expression interpreter insofar as &quot;regular expressions&quot; have a formal, mathematical meaning. For example, it makes no provision for a character which must occur at least once.&lt;/p&gt;
&lt;p&gt;(2) It is idiomatic C, which uses a parameter passed by value as the changeable index into the string it points-at and it expects the user to grok the fact that she has a useful value in that value parameter (the start of the text conforming to the regular expression), something unexpected outside of C. If the user passes the text as a string literal, the useful point at which the regular expression occurs is lost.&lt;/p&gt;
&lt;p&gt;(3) While advertised as a string processor, it does not handle modern Unicode or double-byte strings containing international input.&lt;/p&gt;
&lt;p&gt;(4) Its comments are unilluminating especially as regards need-to-know the fact that its value parameter contains a useful result (the start position of the regular expression), and Brian&#039;s discussion in Beautiful Code is unhelpful. Of course, as noted above, this address is lost when a string literal is passed.&lt;/p&gt;
&lt;p&gt;(5) The length of the substring of characters that satisfies the regular expression is lost.&lt;/p&gt;
&lt;p&gt;(6) Kernighan does express, in the text of the essay, the concern that the code, which does heavy recursion proportional to the string length, might run slowly or overrun stack limits.&lt;/p&gt;
&lt;p&gt;But no consideration exists in the code that a semi-beautiful way exists to avoid most recursion. If the regular expression does not start with a string start carat or string end dollar sign, its first character, if not followed by an asterisk, is a &quot;handle&quot; which which can be scanned-for in a nonrecursive loop or by a strcspn function.&lt;/p&gt;
&lt;p&gt;Even if the first character (that&#039;s not dollar or carat) is followed by an asterisk, if the asterisked character occurs frequently, the code can search for the first character, and return a match immediately upon finding it, or, entering the recursive code upon failure.&lt;/p&gt;
&lt;p&gt;What would be Beautiful about this? The fact that it&#039;s not the sort of thing an optimizing compiler would &quot;think&quot; of, whereas the apparent efficiency of Pike&#039;s code is often discovered by an optimizing compiler (although an optimizing compiler would not &quot;see&quot; the utility of recursion in an iterative solution, to be sure).&lt;/p&gt;
&lt;p&gt;It would, I think, amortize the cost of using a platform, whether Java or C Sharp, that handles real strings through an abstraction.&lt;/p&gt;
&lt;p&gt;Please feel free to point out where I&#039;ve gone off the rails, since I have such respect for Kernighan that I&#039;m astonished that he feels that this snippet is Beautiful Code.&lt;/p&gt;
</description>
 <pubDate>Thu, 27 Dec 2007 08:19:27 -0800</pubDate>
 <dc:creator>Edward G Nilges</dc:creator>
 <guid isPermaLink="false">comment 9694 at http://www.developerdotstar.com/community</guid>
</item>
<item>
 <title>Brain Fart</title>
 <link>http://www.developerdotstar.com/community/node/773#comment-9693</link>
 <description>&lt;p&gt;It wasn&#039;t until I posted to comp.programming that in an exchange with Malcolm McLean that I realized that you DO know where the string occurs when you use the Rob Pike code.&lt;/p&gt;
&lt;p&gt;Because the &quot;test&quot; variable is used as an index-address, it contains the start of the regular expression&#039;s occurence on exit from a successful search or a null length &quot;string&quot;, in the case of failure.&lt;/p&gt;
&lt;p&gt;Is this &quot;elegant&quot;? No, since you&#039;re not given the length of the string that satisfies the regular expression, and this cannot be determined from very simple regular expressions such as C*! &lt;/p&gt;
&lt;p&gt;Furthermore, although it was sorta dumb of me not to see that the test value is a result as well as input, and to recall to mind that C &quot;value&quot; parameters can contain results, Brian should have spelled this out.&lt;/p&gt;
&lt;p&gt;No, Brian, I&#039;m not saying &quot;Don&#039;t Make Me Think!&quot; I am saying I would have spelled this out and not assumed a knowledge of C, because shibboleths (using idioms to select an audience) are tribal.&lt;/p&gt;
&lt;p&gt;Primitive art linked to magic and ritual is beautiful, but it isn&#039;t beautiful to in effect celebrate 1971 as a computing year in which the theory of parameter types was in its infancy.&lt;/p&gt;
&lt;p&gt;It is said that elegance is in the mind of the beholder, and a reputable literary theory, reader-response, affirms that in part literary elegance depends on an audience.&lt;/p&gt;
&lt;p&gt;But this means that the very word, &quot;elegance&quot;, has to be subscripted with the name of the audience.&lt;/p&gt;
&lt;p&gt;The C expert no doubt gets a *frisson* of delight when he sees, a lot faster than I, that (1) test is used as a work area and (2) test gives back the starting address of the satisfier string.&lt;/p&gt;
&lt;p&gt;However, what&#039;s missing is an acknowledgement that there&#039;s an audience out there of intelligent professional programmers who don&#039;t use C, or who used to, but then got help. What&#039;s missing is a true computing cosmopolitanism, that of the Algol publication language, that was short-changed by IBM&#039;s development of Fortran, and the Eisenhower administration&#039;s post-Marshall Plan desire to let the Western Europeans know that they were junior partners.&lt;/p&gt;
</description>
 <pubDate>Wed, 26 Dec 2007 23:50:42 -0800</pubDate>
 <dc:creator>Edward G Nilges</dc:creator>
 <guid isPermaLink="false">comment 9693 at http://www.developerdotstar.com/community</guid>
</item>
<item>
 <title>Brian Kernighan&#039;s Beautiful Code?</title>
 <link>http://www.developerdotstar.com/community/node/773</link>
 <description>&lt;p&gt;Nonsense prevails, modesty fails&lt;br /&gt;
Grace and virtue turn into stupidity&lt;br /&gt;
While the calendar fades almost all barricades to a pale compromise&lt;br /&gt;
And our leaders have feasts on the backsides of beasts&lt;br /&gt;
They still think they&#039;re the gods of antiquity&lt;br /&gt;
If something you missed didn&#039;t even exist&lt;br /&gt;
It was just an ideal -- is it such a surprise?&lt;/p&gt;
&lt;p&gt;What shall we do, what shall we do with all this useless beauty?&lt;br /&gt;
All this useless beauty&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://www.developerdotstar.com/community/node/773&quot;&gt;read more&lt;/a&gt;&lt;/p&gt;</description>
 <comments>http://www.developerdotstar.com/community/node/773#comment</comments>
 <category domain="http://www.developerdotstar.com/community/taxonomy/term/20">Software Development</category>
 <pubDate>Tue, 25 Dec 2007 22:06:40 -0800</pubDate>
 <dc:creator>Edward G Nilges</dc:creator>
 <guid isPermaLink="false">773 at http://www.developerdotstar.com/community</guid>
</item>
</channel>
</rss>
