June 28, 2007

NetDug last week...

I thought this was funny.

Last week I gave a presentation on C# 3.0 and LINQ to NetDug. Mind you, this is a really well run group. We meet at the ProClarity ---erm Microsoft -- building in downtown Boise. Usually someone from Microsoft lets us in, guards over us, and things go really well. Not this time.

It started with one of the group leaders sending me an email, the day before the meeting, telling me that he could not get onto their server, ergo: they couldn't send an email to the group telling them that the meeting was on, and what we were talking about.

Not great, but I can work around that. I sent out a message to the BSDG group, which is also largely Boise area developers and told them. It is largely the same people anyway.

One day goes by.

OK, day of the meeting. I show up and there are already people there waiting outside the building. I'm early so I don't think much of it. The Microsoft building here in Boise is actually a nice spot. There is this cool little spot that had some places to sit in the shade with lots of trees, which was needed because it was over 80 degrees at the time. So we just sat there until someone was going to open the building for us.

Janitors walked in, a few people walked out. I even knew a few of them. It was getting really close to the time of the meeting so I started talking to one of them as they came out. Asking if certain people who are usually there to open the building for us are still in the building to open the building so we can have our meeting. (yes, that is a run on sentence, but appropriate since the person I talked to was a tech writer -- who taught tech writing). They were not there.

Great. First there is no email to tell anyone about the meeting we were supposed to have, and now we don't even have a room to have it in. This is getting better all the time.

By this time there were about eight people there. That is a small gathering for this group. It usually gets 20 people. But, they were still interested in what I had to show them. But we were outside, and my laptop is useless outside running on battery power -- so no power point. There are worse things in life than giving a talk with no power point, really. So next best option: wing it with a pen and paper.

This is where it is a good thing that there were only eight people there. So I started the meeting, outside, and started talking. One thing that does happen when giving a talk like this, you cut out all of the extraneously stuff.

Array initializers -- didn't talk about it.
Extension Methods -- yes, but just enough
Object and Collection initializers -- just barely
Expression Trees -- mentioned that I didn't know anything about them.

But we did talk quite a bit about the var keyword, anonymous types, LINQ, and Lambda. All via pen and paper (which I now refer to as the original Power Point).

So, obviously, I wasn't trying to get the attendees to really grok the material, but I think they did capture some of the general zen. Which, as far as I can tell, is to rethink how and when you use a for loop on a list. With LINQ and Lambda, we should be seeing a lot fewer of them.

In the process we also talked about PLINQ, XLINQ, DLINQ, LINQ for SQL, NHibernate, SubSonic, and Log4Net. It was a good meeting. Not bad for considering the circumstances.

Then to close off the evening for myself, my mom and brother were attending a dairy conference a few blocks away, so I snuck into there and bored myself to sleep. They were talking about whey futures (as in stock market like futures).


I thought I had given a reasonable presentation with no slides earlier, on the street, in 80 degree weather. Here was a guy giving a presentation inside, with a huge projector (20 foot screen - at least) to 50 people and doing it badly.



Now all of this comes from my own general preferences. There is an art to displaying lots of numerical data on a slide. There is also an art to showing charts on a slide. This guy knew about neither, and probably never read anything by Edward Tufte.

Note: I have read Edward Tufte, but please don't blame my bad slides on him -- they are my fault for not reading his books enough.

All of his slides were white. All of his text was black. There was no variation. They could have been printed on a black and white printer and no one would have known the difference. Imagine trying to decipher slide after slide filled with large grids of numbers, each row having a different type of number, and only a thin black line between them. Not good. Then to show emphasis on a particular number -- out comes the laser pointer.

I about made my brother buy me a beer after that. And dinner.

My mom did instead.

June 14, 2007

Fake Objects in RhinoMocks

It seems Ayende is keeping busy with Rhino Mocks (aside from blogging 5 times per day). He has now implemented Fake Objects (called a Stub in Rhino Mocks).

First to give some background, there is a difference between a Mocked object and a Fake object.
With Fake Objects, think of a simple class with only properties containing both getters and setters. You can set any property to a value, but the fake object really doesn't care what happens to it. If you set a property to a value, it returns that value until that value is set to something else. I am not sure, but I don't thing you can tell a Fake object function what to return. So if you need that, you should probably use the Mock Object -- read on.

With Mock Objects, they are much more complex beasts. You must warn the Mocked object for every call made to the object, and tell the Mocked Object what to return. One nice thing about Mocked Objects is that functions can be mocked.

Each object, Fake and Mock, has their place in a testing scheme, so it is important to know the difference. If you need simple returns with getters and setters, and don't care if something does or doesn't get called use a Fake Object. Otherwise use a Mock Object.

Anyway, if I have an interface that looks like this:

   1:  public interface IMyObject
   2:  {
   3:        public string MyProperty1 { get; set; }
   4:        public string MyProperty2 { get; set; }
   5:  }

I can create and use a Fake Object for it like this:
   1:  IMyObject o = MockRepository.GenerateStub<imyobject>();
   2:  o.MyProperty1 = "Hi";
   3:  o.MyProperty2 = "There";   
   4:  Assert.AreEqual("Hi", o.MyProperty1);
   5:  Assert.AreEqual("There", o.MyProperty2);
as apposed to creating and using a Mock Object
   1:  MockRepository mock = new MockRepository();
   2:  IMyObject o =  mock.CreateMock<IMyObject>();
   3:  Expect.Call(o.MyProperty1).Return("Hi");
   4:  Expect.Call(o.MyProperty2).Return("There");
   5:  mock.ReplayAll();
   6:  Assert.AreEqual("Hi", o.MyProperty1);
   7:  Assert.AreEqual("There", o.MyProperty1);
   8:  mock.VerifyAll();
As you can see, there is nothing special to using a Fake Object, just set and get the properties like normal. Whereas with Mock Object you have to call Expect.Call for everything that gets touched.

Have fun.

June 13, 2007

Visual Studio Shortcuts: Collapsing and Expanding text

OK, here are some shortcuts I recently rediscovered. These are in response to me suddenly finding a lot of code collapsed in Visual Studio so only the definitions were visible.

All of these shortcuts are found in the Visual Studio menu Edit->Outlining

Ctrl-M, Ctrl-M: Toggle Outlining Expansion
This one is useful if you have a single function you want to view or hide
Ctrl-M, Ctrl-L: Toggle All Outlining Expansion
Use this to view or hide an entire file
Ctrl-M, Ctrl-O: Collapse to Definitions

This is painful

There is just something painful about listening to the sound of your own voice. Almost as bad as having someone point out all of my grammatical mistakes. Then there is the added pain of watching yourself on video. You get to hear and SEE how goofy you really are.

Anyway, we recorded that last half of our BSDG meeting last Thursday where I was covering C# 3.0. The video misses all of the good stuff (like 'var', collection initializers, object initializers, extension methods, and such) and just focuses on LINQ and Lambda Expressions.

This being the web, there are far better sources of information than this video, but if you are really starved for information -- have at it.

Link to the video.

June 07, 2007

Computers and Cars

I was talking with my neighbor the other day. He was remarking on how his computer had crashed, his daughters computer had crashed, and other computer crashes. In all of these cases, the machines had been working for years with no problems -- then boom!

I asked him about his daughters computer, being the caring person I am, but she lives in another state -- but no worries, she knows a bunch of computer people who are helping her out.

Then a thought struck me (and probably not a very original one): computers are like 1960 era cars were in the 1960s. The cars back then looked good, had style, but very little in the way of safety features, and broke down from time to time. And back then, everyone knew a mechanic.

Computers today have many of the same qualities. The difference is that today, I know very few mechanics and everyone knows a computer guy or three.

Well, back in the 1960, they weren't worried about safety quite then, more on performance and reliability. And try as they might, no one really got the reliability thing down until the 1990s. That is 30 years! But for the most part, with cars today, you add gas, change the oil, and you are good to go. If something does go wrong you look up a mechanic with a computer and the car tells you what is wrong. Also, cars today are getting better gas mileage. My Suburban gets 18 MPG of all things. That is better than my old Nissan Pathfinder which was a much smaller SUV.

Granted, there is still work to be done. I do know a few mechanics and not many of them are board.

But computers are the same, we have been working on processor speed and hard-drive size that reliability has taken a back seat. Remember, 30% of backups fail to restore. But now today, we have reached our theoretical cpu performance peak, and now we are just adding more CPUs. And that can't go on for too much longer. Also, hard drives are only supposed to last for 5 years, and often last for less. But again, how much bigger can we get in our current size restrictions with our current technology.

There has to be a new push coming, if you think that history repeats itself, where reliability will be pushed. If one hard drive manufacturer could stand out and say their hard drives last for 10 years -- I know people who would buy them, lots of them.

Also is power usage. Energy isn't getting cheaper, and computers are very inefficient with power. Google has an announcement about a new power supply that would save 30% of power costs. I would buy that.

Anyway, computers are still changing rapidly, just like cars are. And trends being as they are, I suspect that will continue. Change is a given, but what is changing is not.