Monday, June 27, 2005
Programming as Theory Building
Peter Naur wrote an article that describes the internal process of writing programs. It one of those things you read and instinctively know that it is right.
One important conclusion from this is documentation should be trying to explain why a program does things, and why is it designed the way it is.Naur also explains why programs degrade over time, and that program modification has very real costs.
Read the full article here.The impossibility of communication
A couple of recent events have reminded me about the impossibility of communication, i.e. communication is never perfect and complete. There is always an "information gap" between two people, and the width of gap over which we can communicate varies depending on our shared experiences.
In software development, we need to remember that we can never write specification and design documents that actually explain what we mean. We have to assume the reader has a certain level of experience.
- the more experience the user has, the less we need to write.
- the less experience the user has, the more detailed the document needs to be.
Argument
Have you noticed that people only argue about things that cannot be proved one way or another. As soon as you can prove something, there is no argument. Next time you are involved in an argument that is not getting anywhere, remember this post.
Wednesday, June 15, 2005
Methods and Delegates in C# V2.0
One of my first posts on this blog was moaning about the method/delegate/refelection mismatch. I'm glad to see that in C# V2.0, at least one of my wishes has come true. You can implicitly convert a method to a delegate, like this:
class ConsoleApp
{
static void Main(string[] args)
{
SomeDelegate dele = SomeMethod;
dele();
}
delegate void SomeDelegate();
void SomeMethod()
{
Console.WriteLine("hello");
}
}
Tuesday, June 14, 2005
NT command shell
There are lots of things the NT command-line shell can do. Start "cmd.exe", then type
hh ntcmds.chmfor more functionality than you thought possible!
Dialog-like web applications
When learning Ruby, I came across Wee, which is based on the ideas introduced in Seaside. I love the idea of abstracting web applications, putting the server back in control, so I have been working on "Seaside.NET". For example, here is the code to control an on-line shop:
protected override void Go()I've written my code in C#, based on the ideas of Seaside, but without looking at the source code. The basic concept works, now i'm working on backtracking, i.e. handling when the user presses the "back" button in the browser.
{
StoreCart cart = new StoreCart();
do
{
FillCart(cart);
} while (!ConfirmContentsOfCart(cart));
Address shipping = GetShippingAddress();
Address billing = UseAsBillingAddress(shipping) ? shipping ? GetBillingAddress();
Payment creditCard = GetPaymentInfo();
Ship(cart, shipping, billing, creditCard);
DisplayConfirmation();
}
Friday, June 10, 2005
More C# number conversion
Oh, and you use the System.Convert class instead of int.Parse, like so:
int value = Convert.ToInt32(sometext);
Thursday, June 09, 2005
C# string to number conversion
What do you do to convert a string to a number in C#? I use't to use the "number.Parse" methods, but these always need wrapping in a try...catch block, e.g.
bool ok = true;I turns out there is a way to do this without exceptions being involved, the double.TryParse method:
int result = 0;
try
{
result = int.Parse(sometext);
}
catch (Exception e)
{
ok = false;
}
int result = 0;
double temp;
if (double.TryParse(sometext, NumberStyles.Integer, null, out temp))
result = (int)temp;
else
// not a valid number....
