<?xml version="1.0" encoding="utf-8"?>


<rss version="2.0">
    <channel>
        <title>secondboyet.com  :  julian m bucknall's old blog</title>
        <link>https://secondboyet.com</link>
        <description>An old site that discusses and teaches algorithms, data structures, development methodologies, and the like</description>
        <language>en-US</language>
        <pubDate>Sat, 28 Dec 2019 16:13:58 MST</pubDate>
        <lastBuildDate>Sat, 28 Dec 2019 16:13:58 MST</lastBuildDate>
        <copyright>Copyright 2003-2019 Julian M Bucknall.</copyright>
        <managingEditor>julianb@boyet.com</managingEditor>
        <webMaster>julianb@boyet.com</webMaster>
        <image>
            <title>secondboyet.com  :  julian m bucknall's old blog</title>
            <url>https://secondboyet.com/images/rssbridge.gif</url>
            <link>https://secondboyet.com</link>
            <width>140</width>
            <height>50</height>
            <description>An old site that discusses and teaches algorithms, data structures, development methodologies, and the like</description>
        </image>

		
<item>
	<title>All Change!</title>
	<link>https://secondboyet.com/Articles/AllChange.html</link>
	<description><![CDATA[ 
		<p>
After many years of static HTML pages on my website, today's the day
I'm launching my new blog. Yes, Web 2.0 has now been around for many a
year, and the Bucknall-meister finally gets round to using ASP.NET in
the guise of <a href="http://graffiticms.com">Graffiti CMS</a>.
</p>
<p>
So the new place to bookmark is 
<a href="https://boyet.com">boyet.com</a>, and the new feed to
subscribe to is <a href="http://feeds.feedburner.com/boyet/blog">here</a>.
</p>
<p>
This original website will remain in stasis, with all the action happening 
on the new blog. See you over there!
</p>
		<p>
		<a href="mailto:julianb@boyet.com?subject=re: All Change!">Email me</a> if
		you have comments about this article.
		</p>
	]]></description>
	<pubDate>Sat, 28 Dec 2019 15:57:45 MST</pubDate>
</item>

<item>
	<title>Pandora is costing me a pretty penny</title>
	<link>https://secondboyet.com/Articles/Pandora.html</link>
	<description><![CDATA[ 
		<p>
<a href="http://www.pandora.com/">Pandora</a> is an internet radio
station with a difference. First of all it's free (which seems to
negate my blog title). Second it creates a playlist at run-time based
on the music you like.
</p>
<p>
What you do is to create an account (it makes it easier later on), and
then tell it what music you like by specifying an artist, a band, an
album, or a song. From that, and from some metadata on what the music
is all about, Pandora then creates your own personal "radio station"
selecting and playing songs that are similar in vein to the
information you provided. 
</p>
<p>
Easy enough. I created a radio station based on Massive Attack and
another on Thievery Corporation as an experiment to see what it could
do. Blimey, it ain't 'arf good at it. The music it's been playing has
been very interesting and some of it makes me pause to see what's
playing. This is supposed to be background music, dammit, to help me
work, and instead I'm checking to see what's playing.
</p>
<p>
Worse than that, some of it I like so much, I end up buying the album.
Hence the blog. 
</p>
<p>
Every time this happens, I'm spending another $10 at Amazon's MP3
store. Help!
</p>
<p>
Here's some examples of what I've purchased since listening to
Pandora using these two "radio stations". None of these artists I'd
heard of before, but I certainly like what I've bought very much.
</p>
<ul>
<li><a href="http://www.amazon.com/gp/product/B000XU77O4"><em>Freaks &amp;
Icons</em></a> by dZihan&amp; Kamien
</li>
<li><a href="http://www.amazon.com/gp/product/B000SYYX7E"><em>Reflections</em></a> by 
Paul van Dyk
</li>
<li><a href="http://www.amazon.com/gp/product/B00138KCTW"><em>Vertigo</em></a> by 
Groove Armada
</li>
<li><a href="http://www.amazon.com/gp/product/B00122OC7W"><em>Far Away
Trains Passing By</em></a> by Ulrich Schnauss
</li>
<li><a href="http://www.amazon.com/gp/product/B000UKN74Q"><em>A Heap
of Broken Images</em></a> by Blue Sky Black Death
</li>
</ul>
<p>
I will note in passing that these artists are all British or European.
Hmm. 
</p>
<p>
Anyway, I certainly recommend you trying Pandora <strike>if you want
to spend a nice chunk of cash</strike> if you want to want to listen
to music that you like.
</p>
<p>
<strong>UPDATE</strong>:
One of my readers in Germany (hi, Joe!) tells me that Pandora is 
US-only at this point. Their license agreement does not extend outside 
the US. Bummer.
</p>
		<p>
		<a href="mailto:julianb@boyet.com?subject=re: Pandora is costing me a pretty penny">Email me</a> if
		you have comments about this article.
		</p>
	]]></description>
	<pubDate>Mon, 11 Aug 2008 16:14:28 MST</pubDate>
</item>

<item>
	<title>Porting to Tiburón, part 1</title>
	<link>https://secondboyet.com/Articles/TiburonPart1.html</link>
	<description><![CDATA[ 
		<p>
We're slowly getting released from at least part of our NDA with
<a href="http://www.embarcadero.com/">Embarcadero</a> so that we 
can talk a little about Delphi 2009, codename Tiburón.
</p>
<p>
Being as I'm yer actual CTO with 
<a href="http://www.devexpress.com/">DevExpress</a>, one of if not
<em>the</em> biggest third-party VCL component vendors, I get to play
with the new toy before many others. Several times a month, in
fact. Betas are popping out like rabbits in a lush green field. To say
Delphi R&amp;D have been going through smacking bugs in the bug reporting
system like Orkin does with the ants in my garden is an understatement.
</p>
<p>
Only a couple of days ago, some of us were asked to discuss
Tiburón publicly after we'd used it for a while. Well, "a
while" for me is a couple of recent evenings, playing with it using my
particular codebases.
</p>
<p>
I duped a nice clean Windows XP virtual machine (VM) and installed the
latest beta on it. OK, it <em>was</em> a VM and, to alleciate that a
little, I do have a fast four-core 64-bit monster of a machine, but
the install was nevertheless nice and rapid. Delphi 2007 was a little
slothful, shall we say, about installing, but Tiburón was
decidedly snappy. So much so, that your intrepid reporter didn't even
make a note of how quick it was to install. Doh! I did some other simple
work that was on my plate and the next thing I noticed was the
install was complete. In the order of 10 minutes, perhaps. Now, agreed
I didn't install the C++Builder personality, nor was there any help
install with this particular beta, but this was certainly a major leap
in the right direction.
</p>
<p>
I then loaded my venerable <a href="https://secondboyet.com/FixedArticles/EZDSL.html">EZDSL library</a>
into the IDE and recompiled it.
</p>
<p>
One hint, no errors, and that was it. It was really boring. Honestly,
I was flexing my mental and authorial muscles ready to desk check my
string usage, modify it, and then talk at length about it, but there
was nothing to do. Damn.
</p>
<p>
So, apart from adding another compiler option block for Delphi 2009
($IFDEF VER200, don'tcha know), all I had to do was remove the word
"packed" from a single record type definition. To be honest I don't
think even that was needed, so I've got a query on the internal
newsgroups about it.
</p>
<p>
Well then, er, sorry, but there's no big story about burning the
midnight oil on this one. EZDSL works with Delphi 1 through Delphi
2009, at least in my VM, without very much ado at all.
</p>
<p>
The test programs though, gaak, what a mess; compiler warnings all
over the place. To be expected somewhat since I'd been mixing short
and long strings willy-nilly in there, so next time I'll talk about
how I fixed all that. And of course, I'll be porting my book's code as
well, so stay tuned.
</p>
		<p>
		<a href="mailto:julianb@boyet.com?subject=re: Porting to Tiburón, part 1">Email me</a> if
		you have comments about this article.
		</p>
	]]></description>
	<pubDate>Thu, 07 Aug 2008 09:05:04 MST</pubDate>
</item>

<item>
	<title>Final Notice!</title>
	<link>https://secondboyet.com/Articles/FinalNotice.html</link>
	<description><![CDATA[ 
		<p>
Today I wrote about education being a primary source for better
security 
(<a href="http://community.devexpress.com/blogs/ctodx/archive/2008/08/06/security-is-broken-when-you-leave-it-to-end-users.aspx"><em>Security 
is broken when you leave it to end-users</em></a>) over on 
<a href="http://community.devexpress.com/blogs/ctodx/default.aspx">my 
blog at DevExpress</a>. To flesh out my argument a
little more, here's a postcard I received just recently.
</p>
<p>
<img src="https://secondboyet.com/Images/FinalNoticeFront.JPG" alt="Final Notice Front" />
</p>
<p>
No matter how I look at this, it has scam writ large all over it, even
on the front.
</p>
<ol>
<li>The postage was paid for in Florida, but the company is in
Missouri.
</li>
<li>It has a big red band with "Final Notice" written on it. Funny
that I don't recall receiving any prior notice.
</li>
<li>The company name, "Dealers Warranty" is to make me think this is
part of the network of dealers for my car. Except I have two cars, of
two different makes.
</li>
<li>Nice random GUID-like customer number there. Maybe the "-07" means
July?
</li>
</ol>
<p>
<img src="https://secondboyet.com/Images/FinalNoticeBack.JPG" alt="Final Notice Back" />
</p>
<p>
Turning to the back now. Man, it's looking bad for me. "Final" is all
over the place, in red again, and to make it more urgent, it mentions
48 hours and 20% discount. Twice. There's a special code too! Oh, noes!
I'd better do something right now. Except...
</p>
<ol>
<li>48 hours from when exactly? There is no date. The postcard was
bulk mailed from Florida, taking, what, 3 or 4 days to arrive?
</li>
<li>Why do they want the VIN#? Surely they know, since they're part of
the dealer network? Can't they track it from my (random) customer
number?
</li>
<li>I've been pre-selected for this exclusive program, so you'd
imagine they'd know something about me, like 
<a href="https://secondboyet.com/Articles/ApplaudingAudi.html">what I drive</a>. Er, that
would be no.
</li>
<li>In short, there is absolutely no mention of the actual car the
final notice is all about. Zero, nada, zilch. As I mentioned I have
two, neither of which is anywhere near falling out of warranty. So
which car is this for again?
</li>
<li>And I'm supposed to phone at certain times, CST, Central Standard
Time. But it's summer and they're presumably in daylight savings time
now, aren't they? Why not just put CT? Or is the postcard so generic
they could post it in the winter?
</li>
</ol>
<p>
So, all in all, this is one postcard I won't be replying to. 
(<a href="http://thesop.org/index.php?article=10289">More.</a>)
</p>
<p>
<strong>UPDATE</strong>: These types of car warranty scam artists are 
prone to phoning you as well. All you get is a recorded message with  
"Press 1 to speak to an operator or 2 to be removed from the list". Yeah, 
right. Dream on. The thing is, there is no list. These are robocalls from 
some computer system. They don't know who they're calling because they're 
just calling all numbers in rotation. In fact, they don't know if it's a 
landline (we're on the Do Not Call list, but they don't have it and 
wouldn't pay attention to it if they did) or a cell phone (that's illegal).
</p>
<p>
Here's a list of numbers from which I've been phoned about car warrenty 
scams. I'd add to it as and when I get called. Since they're paying for 
the call I generally listen to the entire message.
</p>
<ol>
<li><a href="http://www.google.com/search?q=323+581+3046">323 581 3046</a> &nbsp;(06-Aug)
</li>
<li><a href="http://www.google.com/search?q=805+985+4838">805 985 4838</a> &nbsp;(11-Aug)
</li>
<li><a href="http://www.google.com/search?q=304+862+3407">304 862 3407</a> &nbsp;(14-Aug)
</li>
<li><a href="http://www.google.com/search?q=843+248+9071">843 248 9071</a> &nbsp;(15-Aug)
</li>
<li><a href="http://www.google.com/search?q=804+417+1862">804 417 1862</a> &nbsp;(22-Aug)
</li>
<li><a href="http://www.google.com/search?q=207+674+2609">207 674 2609</a> &nbsp;(29-Aug)
</li>
</ol>

		<p>
		<a href="mailto:julianb@boyet.com?subject=re: Final Notice!">Email me</a> if
		you have comments about this article.
		</p>
	]]></description>
	<pubDate>Fri, 05 Aug 2016 15:21:01 MST</pubDate>
</item>

<item>
	<title>Code from the internet</title>
	<link>https://secondboyet.com/Articles/CodeFromInternet.html</link>
	<description><![CDATA[ 
		<p>
I've done it, you've done it, if anyone programs for a living I'll bet
they've done it. What, exactly? Got some code off the internet to
solve a particular problem and used it in your current program.
</p>
<p>
That's all very well, but you should practice some what I may call
prophylactic procedures first.
</p>
<p>
Take a look at the code you're about to use. Do you understand it? Is
it using classes, methods, properties you've not met before? Read up
on them. Put it into a test harness and run it. Does it run as you'd
expect? Think of failure cases, and try them out: does it behave?
</p>
<p>
But most of all: read the code and understand it. 
</p>
<p>
</p>
<p>
Let's take an example. There's a 
<a href="http://www.covingtoninnovations.com/michael/blog/">blog</a> I
read occasionally, found though 
<a href="http://www.duntemann.com/Diary.htm">Jeff Duntemann</a>,
hosted by Michael Covington. Very interesting blog, especially with
regard to astronomy photos. He takes some stunning photos of planets,
stars, clusters, galaxies. Magic.
</p>
<p>
I wish however he'd keep away from programming. Here's a very recent
example: finding the speed of the CPU using C# and WMI (Windows
Management Instrumentation).
</p>
<p>
I learnt a whole bunch about WMI when I worked at Configuresoft, and
in those days I learned how flaky it could be (I dare say things have
improved since then). In essence it's an interface to a whole bunch of
configuration options and values from the current or perhaps remote
system. It runs as a service that you can stop or disable.
</p>
<p>
So Covington has this code, the idea for which was obtained from the
internet, I'm guessing.
</p>
<div class="codebackground"><pre>
    <span class="codeKeyword">static</span> <span class="codeKeyword">double</span><span class="codePunct">?</span> CpuGHz() {
      <span class="codeKeyword">double</span><span class="codePunct">?</span> GHz <span class="codePunct">=</span> <span class="codeKeyword">null</span>;
      <span class="codeKeyword">try</span> {
        <span class="codeType">ManagementClass</span> mc <span class="codePunct">=</span> <span class="codeKeyword">new</span> <span class="codeType">ManagementClass</span>(<span class="codeString">"Win32_Processor"</span>);
        <span class="codeKeyword">foreach</span> (<span class="codeType">ManagementObject</span> mo <span class="codeKeyword">in</span> mc<span class="codePunct">.</span>GetInstances()) {
          GHz <span class="codePunct">=</span> <span class="codeNum">0.001</span> <span class="codePunct">*
</span>             <span class="codeType">Int16</span><span class="codePunct">.</span>Parse(mo<span class="codePunct">.</span>Properties[<span class="codeString">"CurrentClockSpeed"</span>]<span class="codePunct">.</span>Value<span class="codePunct">.</span>ToString());
          <span class="codeKeyword">break</span>;
        }
      }
      <span class="codeKeyword">catch</span> {
        <span class="codeBkGrnd">// do nothing
</span>      }
      <span class="codeKeyword">return</span> GHz;
    }
</pre></div>
<p>
As soon as I read the piece and the code red flags appeared. 
</p>
<p>
The first was the blithe justification for the empty catch block.
This is just bad coding practice. You should never have an empty catch
block because it will catch everything, not just exceptions form your
own code. Even very bad exceptions that really say "shut down now,
abandon all hope, Buster" will be caught and tossed aside. Equally as
bad is a catch block that catches objects of type
<code>Exception</code>. Nuts to that: you should catch only those
exceptions you are willing to catch and process, If you are not
willing to handle any exceptions then don't catch them, let something
else further up the food chain worry about handling them. If you find
out later that there's some exception type you can catch and, say,
ignore, then modify the code to do so. Ignoring all exceptions is
never "precisely the desired action".
</p>
<p>
So I decided to play around with the code. First I paused the WMI
service. I then added a couple of lines to the catch block to actually
catch the damn exception and print it out. The call to create the
<code>ManagementClass</code> takes a long time to execute now, but
eventually it fails with a
<code>System.Runtime.InteropServices.COMException</code>. The message
is "Server execution failed (Exception from HRESULT: 0x80080005
(CO_E_SERVER_EXEC_FAILURE))". So now I know what to put in my catch
block should the code be run on a system without the WMI service
running. (Some other research revealed that
<code>System.Management.ManagementException</code> could be thrown
too.)
</p>
<p>
Habing done thnis research I decided that a "low-level" method such as
this shouldn't be in the business of catching anything, expecially
<code>COMException</code>s. So I took out the try..catch.
</p>
<p>
The next red flag is just as visible, since Covington brings attention
to it as well. The result value of the <code>GetInstances()</code>
call is some kind of enumerable collection that does not indexing
defined on it, so you have to use an enumerator. Covington just breaks
after the first item, but my immediate reaction was are there any more
items in this collection. What is so special about the first?
</p>
<p>
So I altered the code to print out all of the items. As it happened
there was only one. I did wonder, since I'm using a quad core, whether
there might be 4 items in this collection. Guess not.
</p>
<p>
Next up is the requirement to convert the <code>Value</code> property
of the <code>CurrentClockSpeed</code> value to a string and then parse
it back into an integer. Yuk. Let's write a little code to check what
type <code>Value</code> is in this instance, ah, <code>UInt32</code>.
(In fact, browsing through the MSDN documentation for WMI reveals the
same type for this property.) Cool: we can get rid of the
<code>ToString()</code> and <code>Parse()</code> calls.
</p>
<p>
The next red flag is more subtle, but it's something I've learned from
the school of hard knocks to watch out for. If there's a class being
instantiated I don't know, especially when it's going to be discarded
pretty much immediately, I go check to see whether it's implementing
<code>IDisposable</code>. If it is, I should use the
<code>using()</code> construct in C# to ensure that Dispose is called.
</p>
<p>
With <a href="http://www.devexpress.com/Products/NET/IDETools/Refactor/">Refactor! 
Pro</a>, this check is really simple. Put the caret on the
new object being created, press the Refactor key, and look to see if
the "Introduce Using Statement" option is present. If it is, select
it. 
</p>
<p>
So, after that little bit of research and experimentation, here's a
better (more efficient, more robust, won't knife you in the back)
routine to get the current CPU speed.
</p>
<div class="codebackground"><pre>
<span class="codeKeyword">using</span> System;
<span class="codeKeyword">using</span> System<span class="codePunct">.</span>Management;

<span class="codeKeyword">namespace</span> CpuSpeed {
  <span class="codeKeyword">class</span> <span class="codeType">Program</span> {

    <span class="codeKeyword">static</span> <span class="codeKeyword">double</span><span class="codePunct">?</span> GetCpuSpeedInGHz() {
      <span class="codeKeyword">double</span><span class="codePunct">?</span> GHz <span class="codePunct">=</span> <span class="codeKeyword">null</span>;
      <span class="codeKeyword">using</span> (<span class="codeType">ManagementClass</span> mc <span class="codePunct">=</span> <span class="codeKeyword">new</span> <span class="codeType">ManagementClass</span>(<span class="codeString">"Win32_Processor"</span>)) {
        <span class="codeKeyword">foreach</span> (<span class="codeType">ManagementObject</span> mo <span class="codeKeyword">in</span> mc<span class="codePunct">.</span>GetInstances()) {
          GHz <span class="codePunct">=</span> <span class="codeNum">0.001</span> <span class="codePunct">*</span> (<span class="codeType">UInt32</span>) mo<span class="codePunct">.</span>Properties[<span class="codeString">"CurrentClockSpeed"</span>]<span class="codePunct">.</span>Value;
          <span class="codeKeyword">break</span>;
        }
      }
      <span class="codeKeyword">return</span> GHz;
    }

    <span class="codeKeyword">static</span> <span class="codeKeyword">void</span> Main(<span class="codeKeyword">string</span>[] args) {
      <span class="codeType">Console</span><span class="codePunct">.</span>WriteLine(<span class="codeString">"The current CPU speed is {0}"</span>, (GetCpuSpeedInGHz() <span class="codePunct">??</span> <span class="codePunct">-</span><span class="codeNum">1.0</span>)<span class="codePunct">.</span>ToString());
      <span class="codeType">Console</span><span class="codePunct">.</span>ReadLine();
    }
  }
}
</pre></div>
<p>
My point here is you really should make some effort to sanitize code
you download from the internet. This is not an NIH attitude, but a
recognition that you really don't know how experienced the developer
at the other end of the URL really is. 
</p>
		<p>
		<a href="mailto:julianb@boyet.com?subject=re: Code from the internet">Email me</a> if
		you have comments about this article.
		</p>
	]]></description>
	<pubDate>Sat, 03 Nov 2018 21:22:34 MST</pubDate>
</item>



	</channel>
</rss>