<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>His Deeds Are Dust &#187; Poor choices</title>
	<atom:link href="http://hisdeedsaredust.com/category/poor-choices/feed/" rel="self" type="application/rss+xml" />
	<link>http://hisdeedsaredust.com</link>
	<description>surveying sub-optimal solutions</description>
	<lastBuildDate>Wed, 02 May 2012 13:16:04 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>The undervalued bool</title>
		<link>http://hisdeedsaredust.com/2010/06/the-undervalued-bool/</link>
		<comments>http://hisdeedsaredust.com/2010/06/the-undervalued-bool/#comments</comments>
		<pubDate>Wed, 16 Jun 2010 13:43:04 +0000</pubDate>
		<dc:creator>Paul Flo Williams</dc:creator>
				<category><![CDATA[Poor choices]]></category>
		<category><![CDATA[C]]></category>

		<guid isPermaLink="false">http://hisdeedsaredust.com/?p=155</guid>
		<description><![CDATA[A colleague of mine wanted to reduce the repetition in this fragment of C++: funcA(false); funcB(false); funcC(false); funcD(false); funcA(true); funcB(true); funcC(true); funcD(true); and, in a burst of sheer genius, came up with this solution: for (bool status = false; status]]></description>
			<content:encoded><![CDATA[<p>A colleague of mine wanted to reduce the repetition in this fragment of C++:</p>
<pre>
funcA(false);
funcB(false);
funcC(false);
funcD(false);
funcA(true);
funcB(true);
funcC(true);
funcD(true);
</pre>
<p>and, in a burst of sheer genius, came up with this solution:</p>
<pre>
for (bool status = false; status <= true; ++status) {
  funcA(status);
  funcB(status);
  funcC(status);
  funcD(status);
}
</pre>
<p>He then scratched his head as the program looped for eternity.</p>
<p>Who could have predicted that a common-or-garden <code>bool</code> could have so many values? Let me count them. The possible values of <code>bool</code> are <i>false</i>, <i><a href="http://www.snopes.com">snopes</a></i>, <i>statistically_significant</i>, <i>almost_true</i>, <i>true</i>, <i>very_true</i> and <i>tautology</i>. <code>++tautology</code> gives you <i>tautology</i> right back, as <a href="http://en.wikipedia.org/wiki/Nigel_Molesworth">any fule kno</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://hisdeedsaredust.com/2010/06/the-undervalued-bool/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Security through perversity</title>
		<link>http://hisdeedsaredust.com/2009/12/security-through-perversity/</link>
		<comments>http://hisdeedsaredust.com/2009/12/security-through-perversity/#comments</comments>
		<pubDate>Thu, 17 Dec 2009 08:00:31 +0000</pubDate>
		<dc:creator>Paul Flo Williams</dc:creator>
				<category><![CDATA[Poor choices]]></category>
		<category><![CDATA[firebug]]></category>
		<category><![CDATA[greasemonkey]]></category>
		<category><![CDATA[intranet]]></category>

		<guid isPermaLink="false">http://hisdeedsaredust.com/?p=126</guid>
		<description><![CDATA[The corporate Information Services overlords have recently introduced a single sign-on solution for our intranet applications, CA SiteMinder. Somewhere along the lines, a discussion must have taken place about a feature of that pesky Mozilla Firefox, helpfully remembering passwords. Although we have to sign on to even access our internal network, there must have been [...]]]></description>
			<content:encoded><![CDATA[<p>The corporate Information Services overlords have recently introduced a single sign-on solution for our intranet applications, <cite>CA SiteMinder</cite>. Somewhere along the lines, a discussion must have taken place about a feature of that pesky Mozilla Firefox, helpfully remembering passwords. Although we have to sign on to even access our internal network, there must have been raised eyebrows that Firefox could automatically sign us on to intranet applications as well. I&#8217;ll show you how our webgrunts &#8220;solved&#8221; the problem. I have no idea whether this is part of SiteMinder, or simply a local perversion.</p>
<p>Firstly, I&#8217;ll tell you what I&#8217;m <em>not</em> showing you.</p>
<ul>
<li>I&#8217;m not showing you that this claims to be an XHTML page, despite the invalid element nesting that makes Firebug mark many of the elements of the DOM in its faded &#8220;what the hell?&#8221; style</li>
<li>I&#8217;m not showing you that the same JavaScript function is included twice, for no useful purpose.</li>
</ul>
<p>In fact, I&#8217;m showing you a cleaned-up snippet that demonstrates the behaviour of the login form while sparing you some of the worst syntax of the original.</p>
<h3>The login form</h3>
<p>The login form appears on the page as two text fields, for username and password, and a &#8220;Connect&#8221; button, as you&#8217;d expect. What is not apparent until you examine the source, is that the username and password are in different forms, which I believe is the key to this trick.</p>
<pre>
 &lt;form name="login"
       action="sm_login.fcc"
       method="post"
       onsubmit="connect(); return false;">
    &lt;input type=hidden name=SMAUTHREASON value="0">
    &lt;input type=hidden name=SMAGENTNAME value="IoqEFNY64K">
    &lt;input type=hidden name=POSTPRESERVATIONDATA value="">
    &lt;input type=hidden name="SMENC" value="ISO-8859-1">
    &lt;input type=hidden name="SMLOCALE" value="US-EN">
    &lt;input type="hidden" name="PASSWORD" value="">
    &lt;input type="hidden" name="lang" value="">
    Username: &lt;input type="text" name="USER" maxlength="8" size="23">
  &lt;/form>
  &lt;form name="pwd"
       onsubmit="connect(); return false;"
       method="post"
       action="">
    Password: &lt;input type="password" name="tpep" size="23">
  &lt;/form>
  &lt;input type="button" value="&nbsp;Connect&nbsp;" onclick="javascript:connect()">
</pre>
<p>So here we have two forms. One is the real login form, <var>login</var>, but what should have been a password text field has been made hidden. A second form, called <var>pwd</var>, has been used to hold a new password text field. The &#8220;Connect&#8221; button doesn&#8217;t belong to either form, but calls a global <code>connect()</code> function, just as the other two forms do.</p>
<h3><code>connect()</code> function</h3>
<p>Both forms run submissions through a piece of JavaScript:</p>
<pre>
function connect() {
  if (document.login.USER.value == "") {
    alert('Enter your user name');
    document.login.USER.focus();
  } else {
    if (document.pwd.tpep.value == "") {
      document.pwd.tpep.focus();
    } else {
      document.login.PASSWORD.value = document.pwd.tpep.value;
      document.login.lang.value = document.pwd.lang.value;
      document.pwd.tpep.value='';
      document.login.submit();
    }
  }
}
</pre>
<p>This little beauty does some standard checking that neither the username or password are blank, but then it copies the password field that we typed into the other form&#8217;s hidden field, blanks the visible password, and then forces submission of the login form.</p>
<p>This function can&#8217;t just return <tt>true</tt> or <tt>false</tt> to allow or stop the normal submission event, because it might have been invoked from the second form, &#8220;pwd&#8221;, if I pressed Enter after typing my password.</p>
<h3>Greasemonkeying this baby</h3>
<p>I routinely use <a href="http://www.greasespot.net">Greasemonkey</a> to make our intranet even vaguely usable, which for me means making sure that text isn&#8217;t too small for me to read, correcting structural defects that Internet Explorer ignores but which break the layout on Firefox, and adding functionality to applications.</p>
<p>Unfortunately, the structure of the real page that contains this snippet is ugly enough that I&#8217;ve so far failed to fix it. What I need to do is to defang the <tt>connect()</tt> function and put the password field in the first form, but I&#8217;m going to have to rewrite quite a chunk of the login page to achieve this.</p>
<p>While considering how to do it, however, I was playing around in <a href="http://getfirebug.com">Firebug</a>, and quite by accident managed to rewrite the form enough to get Firefox to remember the password, and then insert it in the real thing. Bizarre, but satisfying <img src='http://hisdeedsaredust.com/wp-includes/images/smilies/icon_razz.gif' alt=':-P' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://hisdeedsaredust.com/2009/12/security-through-perversity/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>The magic of #ifdef</title>
		<link>http://hisdeedsaredust.com/2009/12/the-magic-of-ifdef/</link>
		<comments>http://hisdeedsaredust.com/2009/12/the-magic-of-ifdef/#comments</comments>
		<pubDate>Wed, 16 Dec 2009 10:10:27 +0000</pubDate>
		<dc:creator>Paul Flo Williams</dc:creator>
				<category><![CDATA[Poor choices]]></category>
		<category><![CDATA[C]]></category>

		<guid isPermaLink="false">http://hisdeedsaredust.com/?p=117</guid>
		<description><![CDATA[The beauty of the preprocessor #ifdef . . . #endif directives in C and C++ is that there are so many ways to abuse them. I&#8217;ve been working on some vintage code (at least 15 years old) that provides a model for how not to do things. The compilation is controlled by no fewer than [...]]]></description>
			<content:encoded><![CDATA[<p>The beauty of the preprocessor <tt>#ifdef</tt> . . . <tt>#endif</tt> directives in C and C++ is that there are so many ways to abuse them.</p>
<p>I&#8217;ve been working on some vintage code (at least 15 years old) that provides a model for how not to do things. The compilation is controlled by no fewer than 750 <tt>#ifdef</tt> switches. Many of these are used in header files as guards against double inclusion, but the others roughly split into these jobs:</p>
<ul>
<li>controlling platform-specific code generation</li>
<li>controlling project-specific code generation</li>
<li>experimental features</li>
<li>controlling different versions of hardware</li>
</ul>
<p>The oddest of these switches are:
</p>
<p><i>For the people who don&#8217;t like to document</i>:
</p>
<pre>#ifdef __
</pre>
<p><i>For dyslexic programmers</i>:
</p>
<pre>#ifdef DSTL_UPGRADES
#ifdef DTSL_UPGRADES
</pre>
<p><i>For those who think the code runs too quickly</i>:
</p>
<pre>#ifdef INEFFICIENT
</pre>
<p><i>For those hopeful of a quick fix</i>:</p>
<pre>#ifdef MAKETHISWORK
</pre>
<p><i>For those who aren&#8217;t confident of our source control systems (and are dyslexic)</i>:</p>
<pre>#ifdef OLD_SLOW_WAY
#ifdef ORIGINAL_CODE
#ifdef OROGINAL_CODE
#ifdef REDUNDANT_CODE
#ifdef REDUNDANT_FUNCTIONS
</pre>
<p><i>For those who can&#8217;t quite remember which operating system they are using</i>:</p>
<pre>#ifdef _vxworks
#ifdef __vxworks
#ifdef VXWORKS
#ifdef _VXWORKS
#ifdef __VXWORKS
</pre>
<p><i>For those trying the super-secret go-faster-stripes</i>:</p>
<pre>#ifdef WIN32_LEAN_AND_MEAN
</pre>
<p><i>For those who super unpositively don&#8217;t no way double negative want that code</i>:</p>
<pre>#ifdef _WIN32_trynot
</pre>
<p><i>. . . but just the once, or later, or huh, maybe not at all?</i>:</p>
<pre>#ifdef __JUSTONCE__
#ifdef _JUST_ONCE_
#ifdef notdef
#ifdef __NOTSMART_
#ifdef _NOTSMART_
#ifdef notyet
#ifdef NOTYET
#ifdef THIS_IS_NECESSARY
#ifdef THIS_IS_TOO_EXPENSIVE
</pre>
<p>Even the choice of names for include guards shows how coding standards change over time, or are ignored, or how the language standards themselves are ignored (the leading underscores):</p>
<pre>xxx_inc_
_xxx_H_
__xxx_H__
xxx_include
xxx_H
xxx_inc
xxx_h
xxx_Hinc
_INC_xxx
INC_xxx
</pre>
]]></content:encoded>
			<wfw:commentRss>http://hisdeedsaredust.com/2009/12/the-magic-of-ifdef/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The not so super SuperDisk</title>
		<link>http://hisdeedsaredust.com/2009/04/the-not-so-super-superdisk/</link>
		<comments>http://hisdeedsaredust.com/2009/04/the-not-so-super-superdisk/#comments</comments>
		<pubDate>Wed, 08 Apr 2009 18:47:26 +0000</pubDate>
		<dc:creator>Paul Flo Williams</dc:creator>
				<category><![CDATA[Poor choices]]></category>
		<category><![CDATA[storage]]></category>

		<guid isPermaLink="false">http://hisdeedsaredust.com/?p=32</guid>
		<description><![CDATA[In 1997, I bought a new PC, and specified that I wanted a SuperDisk drive on it. It seemed like a good idea at the time. The LS-120 drive was a reasonable alternative to the Zip drive, and it had the advantage of being able to read 3½&#8221; floppy disks as well as the 120 MB [...]]]></description>
			<content:encoded><![CDATA[<p>In 1997, I bought a new PC, and specified that I wanted a <a href="http://en.wikipedia.org/wiki/SuperDisk">SuperDisk</a> drive on it. It seemed like a good idea at the time. The LS-120 drive was a reasonable alternative to the Zip drive, and it had the advantage of being able to read 3½&#8221; floppy disks as well as the 120 MB SuperDisks, at nine times the speed of a normal floppy drive. I had one at home, my mate CMoS bought one too, and we bought a new web development PC for work with a third drive.</p>
<p>This all made sense until we discovered the shortcomings of the disks and drives. We&#8217;d buy disks, write them on the work PC, then take them home and find that we couldn&#8217;t read them. After a while, you could be unlucky enough to not even read disks on the machine you&#8217;d used to write them. We sighed heavily and moved onto writing CD-Rs instead.</p>
<p>Moving on a decade, I&#8217;ve recovered my old PC from under the bed in the guest bedroom and set about reading my old SuperDisks. Rather than fire up the old Windows 95 box, I moved the Matsushita LS-120 drive into my current desktop PC, running Fedora 9 Linux. I still have ten SuperDisks, and I know that one of them contains the contents of a bunch of old floppy disks that I thought, ten years ago, would be better off consigned to a single disk. Ho hum. Those floppy disks contained a load of Type&nbsp;1 fonts that I made, the PostScript files that I used to design and test them and the programs, written in VAX Pascal, that I used to build them.</p>
<p>Of the ten SuperDisks, two turned out to be unreadable, but the remaining eight had a just a single read error, corrupting a zip file containing some programs from my day job, so no real loss. All in all, I&#8217;ve recovered 300&nbsp;MiB of old work, fonts and photographs. I must confess, I&#8217;m shocked and impressed at the success rate.</p>
<p>The recovered work is being stored on the hard drive of my desktop PC, being burned to a CD <em>and</em> squirrelled away on my ReadyNAS. I&#8217;m not making <strong>that</strong> mistake again!</p>
]]></content:encoded>
			<wfw:commentRss>http://hisdeedsaredust.com/2009/04/the-not-so-super-superdisk/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

