Thought for the Dazed

I've had to give up that Distance Learning course as I was having trouble seeing the teacher.

Flickr
www.flickr.com
RobMiles' items Go to RobMiles' photostream
Twitter
C# Yellow Book

Search entire site
Thursday
May272004

How to Shoot Yourself in the Foot

Kids, don't program tired. And don't try to fix things when you are tired. Otherwise you'll do stuff like what I just did. I've been trying to get a Wiki to work on my office PC. FlexiWiki, the wiki I'm using (by the way - wikis are great) is run by a bunch of Active Server pages. So I copy all the files onto the web root on my office PC and try to fire them up. I get a page not available error in the browser.

Ho hum. All of my asp pages are broke. So I Google the item in the event log and sure enough, a security patch has changed the protection such that you have to give the ASPNET account more access when it runs. OK. I'm equal to that, but setting file and directory protection is something I use the cacls program for. It is a command line program and very dangerous in the wrong hands - i.e. mine.

I have to give the ASPNET account permissions in a variety of directories, including System32. OK, so I work out the commands that I need and I type them in for each directory. And then my cacls program stops working. Along with lots of other commands. This is bad. Very bad. My machine is becomming a paperweight before my eyes. And then I remember. If you don't use a special option to cacls (the /E option) it doesn't add the new settings to the directory, it replaces them. So, the only person who can now look in the System32 directory is ASPNET. And he is not logged in at the moment. And the cacls program lives in, wait for it, System32!

So, I can't run the only program that I can use to fix the problem that I have made for myself. I think I said a dirty word at this point. The only ray of light is that I'm doing this from home, using Remote Desktop. I therefore have on my home PC a proper copy of cacls which I promptly email myself at my office. Once I have the program somewhere I can run it, things can be got back to normal and all my commands brought back from the grave.

And now I'm going to bed......
Thursday
May272004

Nobody knows the answer

OK, since nobody knows how to solve this one I'll post the answer tomorrow. If you want a clue; it has to do with construction.....

Oh, and in case you are wondering where I've been, I've spent a very happy time at an MVP (Most Valued Professional) day in Reading. Many thanks to Lorna and the team for making us so welcome and the time so interesting.

I reckon that in every age the people around must have reckoned theirs is the most interesting time to be alive:

"This new fire stuff really looks like a neat idea...."

"These steam engines are ushering in a new age..."

"Now that we've got electricity things are really cooking...."

However, I reckon now is most definitely the most interesting time to be around. From the chats that I've had with Microsoft people and others over the last day the changes that we have seen (which are amazing) are pretty darned small fry compared with what is coming over the horizon. It seems that everything is going to be connected, intelligent and useful. I'm not saying that I've seen the future and it works. But I've had a little glimpse of where we are going and it sure looks like fun!
Tuesday
May252004

Exam Question 2

Well done folks. Yes, the breaks were missing, which is an interesting foible of C, C++ and Java. I'd used this in a good way:
case 'a':
case 'A':


This makes sure that the code will work for upper case and lower case command letters. However, it also means that the program continues when you don't want it to:


case 'A':
AddEntry();
case 'd':
case 'D':
DeleteEntry();

Once the program has performed the AddEntry it carries on and does the delete, which is not what you want. You have to explicitly end the case clause:

case 'A':
AddEntry();
break;
case 'd':
case 'D':
DeleteEntry();
break;


C# will not let you do this, which is nice. In C# you have to explicitly chain the cases together. Of courese, I'd probably convert the command to upper case before the switch if I was really writing this code. It makes the code smaller, faster and clearer.
The missing break is one of the most common typo based programming errors. Two others that I've seen are:
for ( count = 0 ; count < limit ; count++ ) ;
{
// something in here which happens when you dont expect it
}

and
if ( x = 5 ) {
// at least Java won't let you do this one
}

Beginning programmers think that their work is done when the program compiles. Ha! If you like a good read and want to know about this kind of thing you should read Code Complete. In fact, if you haven't read this book I don't think you are a programmer at all!
And so to question 2. A couple of classes which won't compile. They are in the right source files, so what is going on here?

public class Person {
String name ;
public Person ( String inName ) {
name = inName ;
}
}
public class SecurityGuard extends Person{
int securityLevel;
public SecurityGuard ( int inSecurityLevel) {
securityLevel = inSecurityLevel ;
}
}

I've just discovered that Steve McConnell is writing another editiion of Code Complete. Wahay! Incidently, he has also written some of the best books ever on project management. Take a look at Rapid Development if you want to find out how to really do it!
Monday
May242004

Exam Question 1

Most people in my programming exam got the problem with this code. Can you? There'll be another tomorrow

switch (command) {
case 'a':
case 'A':
AddEntry();
case 'd':
case 'D':
DeleteEntry();
default :
System.out.println ( "Invalid command" ) ;
}

Sunday
May232004

Ninja Gaiden

Got another XBOX game. The man in the shop said it was a bit tough. "The first boss is the worst" he said. "Just remember to keep moving and blocking". Wow. Was he ever right. Number one son has been grappling with it and still not got past this bloke and his nun-chutcas (or however they are spelt).

An interesting approach to game design; put something in there which makes the game virtually unplayable around 1 hour in.  The good news is that the graphics and atmosphere mean that we are going to work at this until we beat the guy. And once we have got some experience we're going to set out on XBOX Live and see how we do. Me, I still prefer Steel Batallion. I'm not really very good at it, but the fun of pressing all those buttons is tremendous.