Posts in the Software Development category

Experiments in WPF… Part 1

Just for the hell of it, I’m learning WPF and Silverlight (I’m sure it’ll be useful for work at some point).

Here’s the result of my second hacky experiment in building UIs. No real code behind this yet; just UI hackery – although it does show up on-screen and you can resize it:

WPF Facebook App

Let’s look at how this is built.

The Window and Border

First, I have a 4-pixel corner, 2-pixel wide on all sides Border element inside the Window and outside the DockPanel which forms the root of the UI layout.

The Window is set to have a transparent (null) background brush. It has a WindowStyle of None, AllowTransparency is set to True, and its ResizeMode is ResizeWithGrip.

You can move the Window by dragging any non-clickable control in the title-bar. This is achieved by adding an event-handler to the MouseDown event, checking if it’s the Left mouse button which is down, and then if it is, calling DragMove on the Window object’s instance from the handler.

Inside the window is a DockPanel, which forms the root of the layout. In the Top, we have the Title Area. In the Bottom, we have the Status Bar. Left as the last item is a ListBox which is going to fill the remaining space. (Although I still need to play around with this and maybe just switch it to a ScrollView; all of the clicking you’ll do on the app is via Hyperlinks as I see it right now).

The Title Area

The Title area is another DockPanel, where the Bottom docking area is filled with the Update Status TextBox and associated buttons (which is, itself another DockPanel).

After this in the file (so that the update status are fills the whole width of the window, but so that the logo stays flush-left instead of taking up the whole left-hand side) is the facebook logo, which is a simple Image element.

Filling the rest of the space, there’s a horizontal StackPanel, which contains the TextBlock containing a Hyperlink (the “more…” text).

The comment, like and share items are all Hyperlink elements inside a WPF TextBlock element.

The sneakiest part here is the use of a BulletDecorator in the “Update your Status” area. The name part – Simon Cooke in the diagram – is the BulletDecorator’s bullet, whereas the TextBox is the BulletDecorator’s content. The reason this is sneaky? Because this gets us the text on the left auto-aligned with the baseline of the text in the textbox. Pure awesomeness :)

The Status Bar Area

The Status Bar area (which will collapse when it’s not doing anything so as to not take up wasted space) is at the bottom of the first DockPanel. It’s literally a StatusBar control, with two StatusBar items; a TextBlock for the text, and a ProgressBar for the progress indicator. The only real trick here is the use of a margin on the ProgressBar of about 10 pixels, so that the sizing grip doesn’t overwrite it. (This should probably be grabbed from the system properties, but it isn’t yet).

The Main Window

The main part of the window (containing the status updates) is a ListBox, filled with a bunch of ListBoxItems. Each of these contains:

A Grid, with a 54-pixel wide column on the left, which the facebook user image goes into. The right-most column fills the available space.

The right-most column then contains a textblock with runs, spans, images, hyperlinks etc to fill in the relevant info for that item.


Well, it looks like the job of doing something that looks nice & stylized in WPF is pretty easy. Next up, I try to find out how hard it is to grab real live data and stash it in. (I’ll post the XAML code up at some point for those who are interested).


Getting Interested In Language Design... C++ 2.0 anyone?

One of the things I’ve noticed while programming is the number of times when I’ve found really annoying edge cases in the C++ language that I wish I could fix.

One example – its complete lack of support for tables.

I’d love to be able to define a list of things, with columns of a given type. Under the hood, the compiler would generate arrays for me from the rows of each of the columns.


Quite simply, the advantage is that there’s a bunch of coherency there that can be exploited. If you create several separate arrays, it’s hard to make sure that they’re all synched up. If the data is all in a single row, you have a hope of keeping it together. Not doing so is just asking for bugs.

Similarly, I’d like the ability to define a struct or class and be able to direct the compiler to split it up into several pieces. The “hot” data would end up in one chunk, the rest in another. Nice for cache coherency. Support for “banding” of structs would also be awesome. (Kind of like based-pointers from the old MSVC extension days).

Along the same lines, built in support for auto-generated serialization code would be freakin’ awesome. Especially if it could handle endianness, and also figure out for inherited classes the most efficient way to serialize the whole kit & caboodle wholesale.

These are all problems for which solutions exist today. Except they’re hacky, hokey and all-round pretty lame.

I may have to just settle for a code-gen solution on the front-end.


Note to the Internet: Videos aren’t THAT cool

A quick note to the Internet, especially those out there who run tech information sites. (Channel 9? I’m looking at YOU guys).

Videos are compelling. They get your face out there. You get a modicum of celebrity. People hear your voice. Heck, you can even show your family.

Please, keep it to YouTube.

I’ll watch videos on the internet when I want to waste a few minutes looking at a drunken squirrel, or check out Zero Punctuation. When I want information – a science based interview, or a good tutorial on how to use, say, Dynamic Data Entities in ASP.NET – believe it or not, I actually want text.

Why do I want text?

  • I can read really fast. I can skim even faster. When I’m looking for tech information, I’m looking for a couple of very specific bits and pieces.
  • It’s searchable on Google or Live Search. And you know what? I know ALL the keywords I need to know to get the search result in the first couple of links usually.
  • I can cut & paste it into OneNote if I really need to.
  • I can read it on my mobile phone if necessary.
  • I don’t have to shut out the world and put on my headphones.
  • I don’t want to look like I’m wasting time surfing the net at work (which I look like when I’m looking for tech info usually anyway). Watching a video? It’s the same problem squared.
  • Returning to point 1 – reading really fast – I don’t want to waste 15 minutes to an hour watching something that I could get through in less than 3 minutes.

If you put your information in video-only format, you’re actually just stroking your ego. If it’s technical information and it’s NOT a Photoshop tutorial, or a very SPECIFIC demonstration of new features in, say, Windows 7 - then please, don’t do it. Don’t. Just don’t. Stop it. I don’t want to hear your voice. I don’t want to watch you mug for the camera. I just want the information I came for. Give me a break.

What’s worse is when what I’m watching is someone’s cursor wandering around Visual Studio for 15 minutes. DON’T DO IT. IT’S BORING.

imagePointless ego stroking: hey look! It’s code! In a video! You can even hear them type! 

Video is great for some things. It’s my preferred medium for stories. I love it for comedy. Just please, give information in the most suitable form. And for 90% of people in a hurry, just trying to get their day-to-day done, that form is text.

(And Powerpoint mavens? I’m watching you… don’t get too complacent)


Bittorrent Bugginess... or how to use up 35% of your CPU doing nothing...

Looks like someone might need to add a little throttling to BitTorrent.

Build 4747 of version 6.0 of the client has a nasty little bug in it - one that should be really easy to fix, but a bug nonetheless.

On my laptop (a single core, old Toshiba Portege M200 Tablet PC), when I'm downloading stuff it will happily sit there, soaking up 35% of my CPU.

What's it doing when it's doing this and how did I figure it out?

Well, I looked at my TaskManager and found that Explorer was taking up 35% of the CPU. I opened up Process Explorer (it's incredibly useful - so download it here; you can find other useful tools at the site) to figure out what was going on in more detail, selected Explorer, and looked in the properties. What I got was this:

Explorer.exe Thread Properties in Process Explorer

The Explorer.exe thread properties in Process Explorer

Hmmm... a single thread is soaking up a lot of CPU. I wonder why that is? Let's pop it open by looking at the Stack for that thread by selecting it and hitting the Stack button.

Explorer.exe Highest CPU usage Thread Stack

The Explorer.exe thread stack in Process Explorer

Hmmm... well, nothing really useful at the top of the stack, and every time I break in, the thread looks the same. Which means it's mostly likely another app rapidly updating the tray icons and spamming it so much that it's just getting hammered and soaking up a lot of CPU.

But how do we find out which app?

I wussed out on this, dear reader. I just started going through the tray and closed apps one by one until I found the one that was doing it. In this case, it looks like it's BitTorrent. I close it down, and the problem goes away. Open it back up, and lo and behold, 35% CPU.

Kinda sucks. Should be an easy fix though - just update the icon on a timer instead of every time something changes in BitTorrent. Hopefully they'll fix it soon.


New side project...

I've decided to say, well, frankly, screw it and throw my hat in the ring for the Web2.0 social media kinda thing.

So I've started up a site - pyrogrya (catchy name, huh?) that will eventually blossom into a wonderful social media networking site that you can all enjoy.

Why am I doing this?

Because frankly, it doesn't seem that hard to do. And there's a project I've wanted to tackle for about 7 years now (on various devices) that since finally getting smartphones that can handle 3G no longer makes any sense whatsoever to do as a desktop or smartphone app. I can stick it on the web, and in fact, its usefulness should grow exponentially.

What is it?

Can't tell you yet. I want it to be somewhat of a surprise when it goes live. But I guarantee that a lot of you will find it handy. And heck, if I don't give too much away, it won't be so much of a pain when it doesn't go anywhere just like the rest of my side projects do.

Still, here we go. I bought a site, created a logo, and have started writing the database schema... this should be interesting :)

Developer blog can be found here.