I recently upgraded to Microsoft Money 2007, and decided to finally add in some treasury bonds that I have had for years. I couldn’t figure out, how to do it, however, until I came across this FAQ.
The hidden purpose behind private web browsers and history cleaners.
Does anybody else think that the real purpose behind the big movements in privacy, hiding web browsing habits, building anonymizers, and more… is really just a movement to allow everyone to view pornography without their SO’s finding out?
Come on, perhaps there really are people in a public library who need to look up an embarrassing medical question and don’t want the next user to spy on them and confront them about it, but let’s be honest–is that REALLY the motivation?
On a personal computer, what excuse is there really? To hide your browsing habits from your children? your spouse? What web sites are you visiting that your family shouldn’t know about? Maybe you should work on your honesty with them…
At work? I’ll cut a little slack here, but not much. You REALLY shouldn’t be browsing bad sites at work–that creates liability problems. On the other hand, maybe you have some dishonest coworkers who would stoop to spying on your habits…
Simple Command Mapping Infrastructure in .Net
Unlike MFC, .Net does not offer a built-in framework for message handling in WinForm applications. MFC developers, for better or worse, have a rather large mechanism that automatically maps command messages from menus, toolbars, and windows into the classes that want them.
.Net has no such all-encompassing framework, though some 3rd-party frameworks exist (perhaps I’ll go over some in a a future entry).
The lack of a built-in application framework gives developers more freedom by not locking them into a certain mind set, but it also means that you have to develop your own framework or do everything from scratch in every application.
Short of developing an entire framework, there are some practices you can follow in .Net (and any GUI application, for that matter) to ease management of commands.
I’ll talk about one possibility that I recently chose to implement in a small WinForms application. First of all, let’s look at the overall architecture I’m aiming for:
It’s roughly a Model-View-Controller (MVC) architecture. What I want to do is almost completely isolate the GUI layer from knowledge of how the program actually works. The breakdown of responsibility is as follows:
- GUI – contains menus, status bar, views, panels, toolbars, etc. and routes messages from them to the controller via command objects.
- Controller – coordinates views, reports, and GUI.
- ReportGenerator – the “model” in this architecture. Generates and stores the actual data that will be presented.
- Views – Does the drawing for the report in different ways.
With this architecture, the GUI is restricted to doing only a few things, all of them related to the state of the GUI:
- Receiving events from toolbar buttons, etc.
- Setting menu/button states based on general program state (i.e., report running, idle)
- Changing the current view based on a request from controller.
Command Objects
A popular way to handle commands from toolbars and menus is to use the Command design pattern. The advantages to this pattern are numerous, but as far as isolating the GUI from implementation details, they allow us to put all the work required to get things done into command objects and the controller.
Here’s a sample design for commands. As you can see, it’s exceedingly simple.
An interface defines the basic functionality: Execute(). The concrete base classes are created with parameters that tell it the information it needs to know. When the user selects a command in the GUI, the GUI must then run the associated command.
For example, here’s a command that merely changes the current view:
class ChangeViewCommand : ICommand
{
private ViewType viewType;public ChangeViewCommand(ViewType view)
{
this.viewType = view;
}#region ICommand Members
public void Execute()
{
DiskViewController.Controller.SetCurrentView(viewType);
}#endregion
}
When the command is created, it is initialized with the view type. When it’s executed, it merely calls the controller to do the work. The amount of work that is done in the controller versus command objects really depends on the application and individual commands. In this specific case, it might not seem like it’s doing a lot, but it would be easy to add Undo support, logging, coordination among multiple classes, or any other requirement for a command. In addition, the benefit of using command objects even in simple cases like this will become clear shortly.
Associating GUI objects with Command objects
Many applications use menus as well as toolbars with duplicate functionality. There are also keyboard shortcuts that can invoke the same command. An easy way in .Net to associate the GUI with command objects is to use a hash table. The keys consist of the menu and toolbar objects, and the values are the command objects.
//declaration:
private Dictionary<object, ICommand> commandMap = new Dictionary<object, ICommand>();
//toolbar
commandMap[toolStripButtonPie] = new ChangeViewCommand(ViewType.Pie);
commandMap[toolStripButton3DPie] = new ChangeViewCommand(ViewType.Pie3D);
commandMap[toolStripButtonStart] = new StartCommand(controller);
commandMap[toolStripButtonStop] = new StopCommand(controller);
//menu
commandMap[pieToolStripMenuItem] = commandMap[toolStripButtonPie];
commandMap[Pie3DToolStripMenuItem] = commandMap[toolStripButton3DPie];
commandMap[startAnalysisDriveToolStripMenuItem] = commandMap[toolStripButtonStart];
commandMap[stopAnalysisToolStripMenuItem] = commandMap[toolStripButtonStop];
 You can see that some commands take the controller as argument–an option to discovering it from a static class variable. Also notice that commands from menu objects can reuse the same object that is associated with the toolbar button.
In order to run the commands, the GUI needs only respond to OnClick events from menus and toolbars and in many cases, the same delegate can be assigned to many of the menu items:
private void OnCommand(object sender, EventArgs e)
{
   if (commandMap.ContainsKey(sender))
   {
       ICommand cmd = commandMap[sender];
       if (cmd != null)
       {
              cmd.Execute();
             //could also do controller.RunCommand(cmd);
       }
   }
   else
   {
       throw new NotImplementedException();
   }
}
In conclusion, using the techniques presented here you can easily split your program into manageable chunks, with each layer doing only what it needs to.
Say no to Variable Pricing
ICANN is hearing a proposal to charge variable prices for domain names. This has to stop before it starts. How are they going to determine a price? What’s the fair market price of something? Does it depend on how many whois queries there are? Someobody will just slam that, driving up the price. Is it arbitrary?
Look at Ken McCarthy’s blog for more info.
Worse than Y2K–what if gravity changes?
Though the danger to life, civilization, and future of all that is good and beautiful was greatly oversold, Y2K was still a pretty big deal. It required the detailed analysis and updated of millions of lines of legacy code in all sectors, levels, nooks, and crannies of computer civilization.
We survived, somehow. Planes didn’t fall out of the air. Elevators did not plummet to the basement. Satellites did not launch lasers and nukes at random targets. Cats and Dogs did not start living together.
But what if something even more fundamental than our calendaring system changed?
What if a fundamental assumption about the way Earth functions changed?
Take, for example, gravity. The force of gravity is defined by the following equation:
Constants are:
- G – universal gravity constant. 6.6742×10-11Nm2/kg2
- M – mass of first object. Earth = 5.9724 x 1024 kg
- m – mass of second object.
- r – radius from center to center of objects. Earth = 6,378,100 m
This can be simplified for use on earth to:
where
- m – mass of object on earth’s surface
- g – earth gravity constant.
We can compute g by setting both equations equal to each other, canceling the common term of m, we get:
If we substitute the values above, we get g = 9.801585
That’s the value that is a hard-coded into all the missile launchers, satellite control software, airplane flight control logic, embedded physics math processors, and Scorched Earth games in the world.
So what if it changed? It’s not likely, but it could happen. If a significant amount of mass were added or taken from the earth due to, say, a catastrophic asteroid hit, gravity could be affected.Â
But how much would it have to change?
Given the current values, F = mg for 50 kg yields 490.08 N of force on the earth. If earth’s mass increased by 1%, g would be equal to 9.899601, and F would be 494.98 N. Would we feel heavier?
It would certainly destroy precision instrumentation.
However, 1% is a LOT: 5.9742Â x 1022 kg. By comparison, the moon is 7.36 x 1022Â and the mass of all known asteroids is less than that. On the other hand, if you think gravity can’t be affected by a reasonable event, read this.
So just to be safe for future modifications, make sure all your software takes as parameters G, M, m, and r, and calculates g as needed. You can never be too careful.
😉
It isn’t Infectious…
My father-in-law was visiting this week and the first thing he said to me, extending his hand to shake mine was:
“Don’t worry, it isn’t infectious.”
(He has a temporary skin condition)
ClearType is like a new pair of glasses
Many have said it already, but let me just add my voice: ClearType technology is the most wonderful thing to hit Windows in a long time. I recently received a new computer at work (3.4Ghz hyperthreaded, 1 GB RAM, 80/200 GB disks–a screaming machine, at least compared to what I used to have). and during the setup process (3 versions of Visual Studio, Office, dozens of developer tools) I remembered that I needed to turn ClearType on.
Wow. It’s like the same difference when you’ve been needing glasses for a while and finally get them and realize that the world isn’t that blurry after all.*
It doubles the perceived resolution of LCDs.
(* only a little ironic that ClearType works by deliberately “blurring” edges through antialiasing.)
Linux Reality Check part 2
Scoble has a great commentary on the state of Linux fonts. It’s something I never thought about much before, but now that he’s brought it up, I realize that poor font quality is something I’ve definitely suffered through when I did actively use Linux.
It’s just another example of one the seemingly-minor-but-actually-major issues facing Linux. It’s amazing how much effort must be expended in order to implement so many things we take for granted.
Linux Reality Check
Over at Slashdot, Fedora Project Leader Max Spevack responds to some frank question about the Fedora project.
He talks about a number of topics:
- Unified package managers across distros
- Propritetary drivers
- Differences in Linux over time
- Fedora’s biggest weakness
- Threat of Vista
- inclusion of NTFS driver in kernel
- Wacky package dependencies
- a few others…
What his article demontrates to me is that Linux is going through some growing pains and that the community is realizing the difficulties that Apple and Microsoft have already dealt with in their own ways.
For example,
I guess the “problem” with package managers is that they are so integral to the rest of a distro that it’s a major endeavor to switch them. One reason is that a switch of that kind would break the upgrade chain.
Welcome to the real world of computing. Upgrading, advancing, improving are all important issues for real users using their computers. The only reason we still use the x86 architecture is backward compatibility. The only reason Windows has universal marketshare is that it works with basically everything ever written.
Another fundamental issue:
In terms of getting people to use Linux instead of proprietary operating systems — I think that battle is best fought in the world of people who are new to computers. People will tend to be loyal to the first thing that *just works* and doesn’t cause them pain. Making that first experience for people a Linux one as opposed to a proprietary one — that’s the challenge.
How true. It’s been a while since I’ve installed Linux, but my memories of it were not all that pleasant. It worked well enough, I suppose, but it certainly isn’t as polished or streamlined as it should be. MS and Apple are still years ahead of Linux in this regard.
Windows Live Search Toolbar — not quite there yet
I forced myself to uninstall the Google toolbar and exclusively try out the new Windows Live Toolbar. I think I’m going to uninstall it today. First of all, I like a lot of things about it:
- Customizable buttons
- Lots of great features
- Search history with automatic drop down list that shows past/related searches
- Desktop search works as well as always. I couldn’t live without it.
I also noticed that the search results for Windows Live were just about as good as Google’s. That is a great thing–we need more competition in this space to keep things going.
However, with all that good there are some pretty significant issues (at least for me).
- It is sloooooooooooooooow. I mean, noticeably slow, painfully slow, distractingly slow. I want my search results nearly instantaneous. None of the pretty features matter if I have to wait 15 seconds for search results to show up when your competitor can come up with the same result in 2 seconds. Is it the web-site or the toolbar–I’m not sure yet.
- Lack of Instant Answers. One of the things I love about MSN search is the ability to track packages, get weather, and lookup addresses. Why wasn’t this built into Windows Live from the beginning? I know they’ll be adding them, but still…
- Sometimes, the toolbar refreshes or does something that erases what I’ve already typed. I think this is an issue when it first starts up–if I’m too quick to begin searching. Not a huge issue…
I’ll be getting a new computer at work in a few weeks. I’ll try again after that. Hopefully Microsoft will have made some improvements. I’ve submitted my list of issues to their feedback page, and hopefully they will make this product better.