Lazycoder

18Dec/080

links for 2008-12-18

Filed under: Links No Comments
17Dec/080

Object oriented programming vs. class oriented programming

In the last post, the code was pretty clean. Our resident Rhino.Mocks guru at work, Sean, left a comment saying that the new code was much better than the Do-Func stuff I had before. Sean was the one that pointed me to the Repeat.Times methods in Rhino.Mocks. I thought I'd post the old code that I had cobbled together from a StackOverflow answer.

CODE:
  1. IDataReader reader = MockRepository.GenerateStub<IDataReader>();
  2.  
  3.             reader.Stub(x => x.Read()).Do((Func<bool>) delegate()
  4.  
  5.                                                            {
  6.  
  7.                                                                m_NumberOfTimesIDataReaderHasBeenCalled++;
  8.  
  9.                                                                return
  10.  
  11.                                                                    (m_NumberOfTimesIDataReaderHasBeenCalled%2 != 0);
  12.  
  13.                                                            });
  14.  
  15.             reader.Stub(x => x["ID"]).Return(Guid.Empty);
  16.  
  17.             reader.Stub(x => x["FullName"]).Return("Test User");
  18.  
  19.  
  20.  
  21.             List<UserDTO> list = SearchProvider.ParseUserData(reader);
  22.  
  23.             Assert.IsNotNull(list);

The re-factored code using the Repeat.Times methods.

CODE:
  1. IDataReader reader = MockRepository.GenerateStub<IDataReader>();
  2.  
  3.             reader.Stub(x => x.Read()).Return(true).Repeat.Times(1);
  4.  
  5.             reader.Stub(x => x.Read()).Return(false);
  6.  
  7.             reader.Stub(x => x["ID"]).Return(Guid.Empty);
  8.  
  9.             reader.Stub(x => x["FullName"]).Return("Test User");
  10.  
  11.  
  12.  
  13.             List<UserDTO> list = SearchProvider.ParseUserData(reader);
  14.  
  15.             Assert.IsNotNull(list);

You can see how the second code sample is much cleaner than the first. A lot of the messiness of the first code sample comes from talking to the compiler instead of talking to objects. What do I mean by that? Well, in the first example we have to tell the compiler what the delegate should return

CODE:
  1. Func<bool>

You'll also notice some ugliness inside of the delegate body.

CODE:
  1. m_NumberOfTimesIDataReaderHasBeenCalled++;
  2. return (m_NumberOfTimesIDataReaderHasBeenCalled%2 != 0);

Here, I was incrementing a class member and checking to see if it was odd or even. If it was even, I'd return true, otherwise I'd return false. This allowed me to control the number of times the IDataReader.Read() method would return true. In this case, it would return true once, then the variable would be incremented to an odd number and the Read method would return false.

That's all part of me telling the compiler what to expect, when what I really want to do is just tell my objects what to do. This episode of the Alt.net podcast also talks a little bit about class-based programming versus object-oriented programming.

17Dec/080

links for 2008-12-17

Filed under: Links No Comments
16Dec/081

Wubi – Ubuntu Installer for Windows

Wubi - Ubuntu Installer for Windows

I've been running Linux on various boxes for years. For the most part, Iv'e either dedicated a machine completely to Linux, run Linux in a VM, or dual-booted. The dual-boot always required setting up a separate partition and messing with the boot.ini, or whatever, file after installing Linux into the new partition. Then I discovered the Wubi project.

Wubi lets you install Ubuntu into a virtual partition, represented by a file, and modifies your boot loader, adding a new entry. It will automatically detect your CPU type and download the appropriate version of Ubuntu (e.g. If you are running an AMD x64 chip, it will download the AMD x64 version of Ubuntu). You can select from four different desktop environments, KDE, GNome, XFCE, or the Mythbuntu media server.

After you install and reboot your machine, your new Ubuntu installation will appear in your list of boot options. All without the need to shrink and create new partitions.

If you are thinking about trying Unbuntu, but don't have the resources to run a VM or re-partition your machine, I'd encourage you to try Wubi.

15Dec/08Off

Episode 29: Miguel de Icaza (part 2)

This is the second half of our discussion with Miguel de Icaza about Mono, Moonlight, open source, and other fun stuff. Topics When re-implementing .NET, do you match re-implement known bugs? The test / regression system to maintain compatibility How do you support so many platforms What parts of Mono are written in managed code? [...]

15Dec/089

New ASP.NET MVC sample – Oxite – Needs some TLC

Last week the MIX online team announced that they are releasing the ASP.NET MVC code that powers their MIX Online blog as open source at CodePlex. This is a great thing.

The code base, while touted as a "a real-world sample written using ASP.NET MVC.", is not without some problems. The commentary on Twitter soon after it's release was pretty negative.

This is why Oxite is not good. http://pastie.org/339644

browsing the Oxite source... wondering how many people will try to learn from this mess

@robconery because microsoft doesn't deal with foibles with courage, i expect oxite will be allowed to degrade yet more customer potential

Oxite source is being slaughtered by the alt.net crowd; sad thing is, since its by MS others will use it as guidance on how to do MVC

@cwoodruff please, please, please do not use Oxite as a guide when doing MVC... PLEASE DO NOT

@lazycoder if u read the code, it's actually a collection of anti-patterns of MVC... I hope people are not going to learn from it

Rob Conery has a great post where he outlines some of the issues with the Oxite code base and how they can be fixed. He has already offered some patches to the team.

That's what I mean when I say this is a great thing. Since the team is doing all their work out in the open, we get to see how it evolves. I fear that a lot of the ASP.NET MVC code that we see written the first few years after it is released will look very similar to the Oxite code. Hopefully, the refactoring of the code base into something that embraces the strengths of MVC will be done in public as well so that first time MVC developers who find themselves writing the same code that the Oxite team has will have a lot of resources available.

I'd encourage everyone interested in the ASP.NET MVC product to watch the evolution of Oxite closely and contribute to the development.(1)

(1) That doesn't include me for quite some time as we're getting ready to have a baby soon. You don't want to see code I've written on only 4 hours sleep over two days. ;)