« | » Main « | »

Protected members in sealed classes?

Friday 29 April 2005

Here's the latest .NET head-scratcher: I wanted to put up an Open File dialog. Simple, use the OpenFileDialog class. Works great. Now I want to change the text of the Open button to "Insert". In the Win32 world, there's a hook procedure you can provide that lets you intercept window messages. You can customize the dialog by adding behaviors to specific messages. For example, on WM_INITDIALOG, you can change the text of a button.

Looking at the members of the .NET OpenFileDialog class, I see it has HookProc, described as:

Defines the common dialog box hook procedure that is overridden to add specific functionality to a common dialog box.

Perfect! Except that OpenFileDialog is a sealed class (C# lingo meaning you can't derive your own classes from it, like Java final). What?! How is this useful to me? D'oh! How do I override behavior in a common dialog?

And another thing: Why show me this member in the docs? Just as the docs don't describe private members, they should omit protected members in sealed classes.

ANTLR in Python

Friday 29 April 2005

Updates often beget updates. Yesterday I tweaked my Python parsing tools, which prompted Bruce Dickey and Sergej Zagursky to write in to say that ANTLR now generates Python parsers.

ANTLR is a mature parser generator. It is written in Java, but can generate parsers in Java, C++, C#, and now Python. Due to its long history, it has a large user base, which means a large collection of available grammars. ANTLR is a powerful and popular system, and its addition to the Python toolset is good news.


Wednesday 27 April 2005

Larry Hastings uses Cog, but worries about missing new files that need to be Cog'ged. To solve the problem, he wrote Nocog. As he describes it, "Nocog scans over its input files, and if any of them contain Cog code, it prints an error and returns -1. If none of them contain any Cog code, it prints nothing and returns 0."

This isn't a problem I've encountered, but I understand the impulse: the more that code can detect its own problems, the fewer problems will persist. This applies even to builds.

QR Code

Tuesday 26 April 2005

A mysterious link from Jim Flanagan's del.icio.us page led me to QRコードBlog ("Not just about QR code; all the entries are in QR code"). I encountered a site with many graphics, a little bit of text in Japanese, and many odd-looking black and white mosaic images. These turned out to be QR Code, a 2D barcode developed about 10 years ago in Japan and now an international standard.

Nowadays, Japanese cell phones come equipped to scan these code with their built-in cameras, so QR code is extremely popular as a way to get data into cell phones. For example, business cards are printed with QR-encoded versions of personal data, allowing a recipient to simply take a picture of the card, and all the info is slurped into the phone.

So QRコードBlog is not only about QR code (including such eccentricities as QR implemented as chocolate sauce on a white chocolate bar), but all of the entries are encoded in QR as well. Not to be outdone, here's the first paragraph of this entry as QR:

A QR code rendition of a paragraph of text

(The image came from QR Code Generator.)

Dictatorship of relativism

Tuesday 26 April 2005

A few days before becoming Pope Benedict XVI, Joseph Cardinal Ratzinger gave his now famous homily in which he deployed the phrase "dictatorship of relativism". I don't like this phrase, for a few reasons.

First, the phrase itself is an oxymoron. The essence of dictatorship is that one has absolute power over all. The essence of relativism (as Ratzinger described it) is that its "ultimate goal consists solely of one's own ego and desires". Surely "anarchy of relativism" is a much better description. But like "terrorism" or "Hitler", "dictatorship" is a universal boogieman that anything can be compared to, and then is accepted to be a Bad Thing. Dictatorship of relativism is not a good metaphor, but it is not bad sloganeering.

More importantly, though, I am suspect of anyone railing against "relativism". All too often, the "absolute" we are urged to adhere to is in fact a point along a sliding relative scale, but a point a little bit in the past. American conservatives seem to yearn for the 1950's, for example. Those who were outraged by the recent attempt to remove "under God" from the Pledge of Allegiance conveniently ignored the fact that the words weren't in the original version.

Surveys report that 63% of Americans believe the bible is literally true. Presumably those 63% shun "relativism". Yet almost none of them keep kosher as (for example) Deuteronomy 14:8 rules:

And the swine, because it divideth the hoof, yet cheweth not the cud, it is unclean unto you: ye shall not eat of their flesh, nor touch their dead carcase.

Apparently Christians accept this seeming inconsistency because Paul said it was OK. Sounds like relativism to me.

This is what gets me about the "Bible is truth" crowd: The Bible is a big book written a long time ago. It is easy to ignore the parts that don't seem right. Everyone does. No one accepts all of it. Partly this is because it is filled with metaphor. Has anyone really been offended enough by their right hand to cut it off? But mostly it is because times change, and people construct their faith and beliefs from a wide range of sources, including their society around them.

Getting back to Benedict XVI, do we think he'll run the church just as Benedict XV would have? Or Benedict XIV? Bendict XIII? Of course not. (Actually, what with objecting to Turkey joining the EU, maybe I shouldn't be so sure!)

"Relativism" is a canard. The question is not whether beliefs and actions bend to fit the times, but to what degree they do.

How to start a fire with a can of Coke and a chocolate bar

Sunday 24 April 2005

The chances of my needing to ever use this technique are virtually zero, but the ingenuity demonstrated is worth it: Fire - Can of Coke and a Chocolate Bar.

This is a good example of overcoming functional fixedness, whereby people view objects as having only one use. In this case, the can of Coke is shown to be something other than a container for a beverage. It's also a small parabolic mirror. The chocolate is more than a tasty snack: it's also a mild abrasive.

Wrapping-paper tie

Sunday 24 April 2005

Yesterday was the Passover seder, and we brought nice (button-down) shirts for the boys. My seven-year-old was unhappy with just the shirt, and wanted a tie to go with it. My father-in-law's were all too large. What to do? When a child wants to get more dressed up, you want to somehow accommodate them. He didn't want to wear the shirt in the first place, but seemed to prefer shirt and tie to just shirt.

Suddenly, inspiration struck! I pulled out a roll of stiff wrapping paper, cut a tie-shaped piece, notched a button-hole in the top, and buttoned it onto the top button:

Wrapping paper tie

At a quick glance, people asked, "Where'd you get the tie?" He wore it for the whole meal, then as a bonus, got to crumple it up in disgust when we let him change back into a T-shirt.

If I ever have to make another, I might try to add a trapezoid "knot" at the top to hide the button and make it look more like a knotted tie, but this one was quite serviceable.

Python jobs board

Wednesday 20 April 2005

Tidbit about my life: I am now the Python Job Board monkey. That is, if you follow the directions and send an email containing a job posting to jobs@python.org, I will see it, turn your job posting into good content for the web page, update the web site, and send you an email saying something chipper like, "Thanks for using the Python Job Board!".

Why am I doing this? To help Python, which I think is a good cause. It only takes an hour or two a week, and it's mindless geeky work, which I am good at. I got to learn the hard way how to use SSH from Windows (PuTTY is your friend), I fixed a few bugs in the way python.org is generated when using Windows, and as an unexpected side-benefit, I am now ned at org of python.

Big Apple Circus

Wednesday 20 April 2005

I saw the Big Apple Circus today with two of the three boys, and my dad and step-mother. I like the small circus, but Big Apple seems to be getting smaller each year. Long gone are the elephants, and the last few years have been without a trapeze act. Grandma (a clown) is still fabulous, but the juggler this year was disappointing (just ping-pong balls and saucer-like discs, no balls or clubs). The trained dog/cat/bird act appeared twice, which is at least one time too many.

The kids loved the clowns, and my youngest was now old enough to really attend to it all.

We always went to see Ringling Bros. when I was a kid (because Big Apple didn't exist yet). That's a much larger circus, with three rings. There's no way to see it all because there's always more than one thing happening at a time, and because you're sitting 50 yards from the action. So the Big Apple is better in that you can really see what's being shown, but I wish it weren't shrinking further before my eyes.

Adobe buying Macromedia

Monday 18 April 2005

Adobe to acquire Macromedia.

I'm not enough of either a graphic designer or web dude to understand the finer points of the two company's product lines, but these guys do:

Quick sum-up: Adobe is print, Macromedia is web. Lots of fear about favorites in the overlap being left to die. Competition with Microsoft is probably a big factor.

Staying organized with index cards

Monday 18 April 2005

Lately I've been trying to keep track of everything on index cards. I like the low-tech approach, and I've always been an office supplies geek at heart anyway. It turns out I'm not alone: 43folders has a whole category for index cards. They even go so far as to call a stack of cards held together with a clip a "Hipster PDA". Jazzmasterson (if that is his real name) has a detailed photo essay demonstrating his index card system. My system is far less elaborate, but works well nonetheless. Low-tech to the rescue!

Disappointed: T30 DVI

Saturday 16 April 2005

I have a T30 Thinkpad laptop that I use primarily. I use an external monitor at 1600×1200 (UXGA for those of you that prefer obscure acronyms). The T30 also has a DVI output for direct digital video. So I got a Dell UltraSharp 2001FP 20.1-inch Flat Panel LCD Monitor to use with it.

It arrived yesterday. I plugged it in, and saw that I was getting a small window onto my screen, panning around with the mouse, as if the display had a lower resolution than 1600×1200. Digging into it, it turns out that the T30 is a bit crippled in this regard: Maximum Digital Video (DVI) Resolution is 1280×1024. This is baffling. 1280×1024 is lower resolution than the built-in LCD (1400×1050), and it's being driven digitally. WTF? Looking some more turned up some dodgy sounding workarounds. I'm reluctant to start down the path of fiddling with drivers, especially if the proponents of the technique admit that there are still video corruptions.

For now, I'm using the monitor with analog video at full resolution, but I don't think it looks as good as my old CRT. The anti-glare coating is much better, though.

Abston Church of Christ

Thursday 14 April 2005

Amy Hughes has built a Lego church of truly astonishing proportions. She estimates it contains 75,000 pieces! She also has other projects in more modest, but still quite large, scales. And I liked the faux-Biblical verses she provides from Slashdot:

And on the eighth day, God created plastic, and He saw that it was good, and He made little teeny-tiny blocks out of it to give geeks something very cool to play with.

And bare of foot, man did step upon teeny-tiny blocks of plastic, and he did blaspheme.

Temporary internet files and my recent documents

Thursday 14 April 2005

I'm trying to get some info on a bit of Windows minutiae, and I can't find any. If you open a document (for example, a Word .doc file), it will appear both in the global My Recent Documents list (for example, off of the Start menu), and in the Word recent documents list (at the bottom of the File menu). But if the document is in the Temporary Internet Files directory (or any subdirectory thereof), then it doesn't appear in the list. For example, if you launch an attachment from Outlook, the file is detached to an Outlook subdirectory of the Temporary Internet Files directory, so that the temporary file doesn't appear in menus after you are done editing it.

The question is, why doesn't it appear in the list? I guessed things like "files in hidden directories aren't shown", but I've disproved all of them with empirical testing. The architect in me would like there to be an answer other than "That specific directory is treated specially by the recent documents code". I want to find a characteristic of that directory that can be applied to other directories of my creation.

Just to further confuse the issue, if you open a document from the ordinary temp directory (\Documents and Settings\ned\Local Settings\Temp), it appears in Word's recent document list, but not the system list!

And, I understand that these directories are not hardcoded, but are stored in the registry to acheive a level of indirection and customizability. So when I say "Temporary Internet Files" directory, I really mean the directory returned by SHGetFolderPath(CSIDL_INTERNET_CACHE).

Sub-pixel font rendering technology

Wednesday 13 April 2005

A friend sent an email exhorting me to take advantage of ClearType on Windows XP. (Hmmm, he's a newly-minted Microsoft employee... the beginnings of a subtle intra-friend marketing push?) I've tried it in the past, and been very impressed. I don't use it because I switch back and forth from LCD to CRT a few times during the course of a day, and ClearType doesn't look good on CRTs. I expect to be all LCD all the time in a week or so, so I'll give it a real try then.

But I was reminded of Steve Gibson's Sub-Pixel Font Rendering Technology page. It's got a lot of good information about the technology. It also has Free & Clear, a demo of the concepts of sub-pixel rendering. Perhaps most surprising about the app is that it is Windows application but only 35Kb in size, complete. It's that small not because there's a 2Mb DLL alongside it, but because it is written in assembly language, just as all of Steve's software is. I think he's nuts, but I admire his dedication.


Saturday 9 April 2005

For those of you that want to stay on the bleeding edge of version control systems, there's a new one being developed: Bazaar-NG. It looks interesting because of its goals (be distributed, but also familiar for CVS users), its implementation (written in Python), and its backer (Canonical, the guys behind Ubuntu). It's already far enough along to be self-hosting.

The disappointment of ADO.NET

Saturday 9 April 2005

Yesterday I wrote about the beauty of the relational model (actually I thought I was just working on a draft, but I published it without realizing, so now this is a two-parter!)

So how did the ADO.NET designers overlook the fundamental power of the relational model's universal rectangles? They've provided some very powerful facilities: A DataTable is an in-memory collection of DataRows. DataTable allows you to use SQL syntax to query the data in memory, tracks which rows have been changed, keeps before and after copies of changed rows, fires events when data changes, and simplifies writing the data back to the database. They're a very cool way to build an in-memory snapshot of data residing in a relational database.

A DataSet contains a number of DataTables, which can have intra-table constraints enforced on them. Finally, a DataView can provide a filtered subset of the data in a DataTable.

So this is all very nice, but where are the universal rectangles? Conceptually, there are at least three different structures that provide a bunch of rows: DataTable, DataView, and DataRow[] (which is returned by DataTable.Select). But these things are all different, and can't be used interchangeably. DataTable provides a Select method for querying its data, but DataView does not. Why not? DataViews are constructed with a DataTable and a select expression, but you can't make one from a DataView and a select expression. Why not? There's no base class or interface that both DataTable and DataView implement, so you can't write a method that uses them interchangeably.

Well, you can, but only by treating the data as an IList or IEnumeration implementation, and even then, inexplicably, the rows of a DataTable are DataRow objects, while the rows of a DataView are DataRowView objects, and the two classes have no base in common! (While I'm ranting, shouldn't DataRowView be called DataViewRow?!) So if you want to treat a DataTable and a DataView the same, the best you can do is to fill your code with ugly downcasts to get at the rows.

And using as stripped-down an abstraction as IEnumeration means that you've lost access to the facilities of DataTable and DataView other than the pure data: the column schema, the events, and so on. It's infuriating. I want to use these classes to build power in my client. I want to use the relational model of interchangeable rectangles to modularize my code and provide abstraction. But I can't.

The designers of ADO.NET valued the relational model enough to implement the whole thing, including a powerful SQL implementation in memory. How could they have overlooked the basic tenet of the approach?

They clearly value using interfaces to abstract away unimportant details, because they gave us IDataReader for filling a DataTable from a database. When they needed an interface to help them ignore details they didn't care about, they provided it. But for consumers of ADO.NET, nothing is ignorable. The details of the classes are in your face at every turn. I find it incredibly frustrating.


Thursday 7 April 2005

I ran across a mention of this open-source log file analyzer: Lire. I haven't tried it, but it seems quite full-featured. In fact, it may be too full featured. Not content to analyze web server logs, it aims to encompass all log file analysis of any kind. New log file formats can be read by writing a "DLF converter" which reads your new log format, converting it into Distilled Log Format. Then reports are generated by XML specifications somehow. Like I said, it looks very powerful. Anyone have any experience with it?

Different strokes for different folks

Wednesday 6 April 2005

I often swim laps in the morning at the Waltham YMCA. The pool is divided into two sections: one for lap swimmers, and one for water aerobics classes. The aerobics people tend to be grandmotherly types. I think most lap swimmers don't consider the water aerobics to be "real" exercise, though it's certainly more varied and more social than swimming laps.

The other day, a new lap swimmer got into the aerobics side of the pool. One of the grandmothers pointed her to our side of the pool, saying, "If you're just going back and forth, you have to do it over there". There's always another way to look at things, I guess...

Franny K. Stein

Tuesday 5 April 2005

I love reading with my kids, and I love finding a new series of books that really captures their interest. Franny K. Stein is a great find. It's a series of (so far) four books about a little girl mad scientist. The chapters are short, with pictures on every page. The series is aimed at the Captain Underpants crowd, but they're less silly, and with more of a real story to them. For example, Franny learns how to get along better with the other kids, or realizes that being laughed at isn't the end of the world. The whole thing is done with good-natured goofy humor, and a light touch on the message.


Franny K. Stein

« | » Main « | »