2009
12.30

I have started to read the book “More Effective C# by Bill Wagner” one of the early points mentioned is the fact that Value types used in closed generic definitions will have a greater memory hit at runtime relative to using reference types.

This is due to the fact that when at least one value type is used in a closed generic definition, the CLR when JIT-compiling a generic definition (either a method or a class) will create a separate “machine code page” for each value type definition e.g.

List<int> intList = new List<int>()
List<RandomStruct> structList = new List<RandomStruct>()

Generic types that will be used with multiple different reference types do not affect the memory footprint, as a shared machine code page will be used e.g.

List<string> stringList = new List<string>()
List<RandomClass> classList = new List<RandomClass>()

As the C# compiler will enforce type safety at compile time, the JIT compiler can produce a more optimized version of the machine code by assuming that the types are correct.

The reality is that Generics with value types provide many benefits that out weight the memory cost. These include the compile time type safety, the more concise code (no need to parse / cast).

When it comes to working in environments where every single little drop of memory is important such as mobile platforms, this little bit of knowledge may prove valuable, or indeed it may not, but ill leave that up to you to decide.

2009
12.28

Steps to writing some Objective C on Windows:

ObjC_On_Windows

2009
12.28

With some cash I got for Christmas I thought I would spend it on creating a chilled out area in my house for reading and for some late night coding.  I work remotely from a home office… I have a nice set-up, but I desire a space which is less formal and more relaxing.  These items will go a long way towards achieving this:

XXL Bean Bag

image

Lap Desk

image

Blue Lava Lamp

image

Blue Plasma Lamp

image

…I welcome all suggestions! Kthx =]

2009
12.28

Just thought I would share my 5 most recent programming book purchases.

The first of which is “The Art of Unit Testing (with examples in ‘C#’ .NET)” by Roy Osherove, the only book on this list I have finished reading. This book I found to be essential reading, and I don’t say that often. I rate this book so highly I recommended that it become a required text for the “Agile and Component based Development” Module at my old university.  If you are looking to improve your unit testing, or if you are just starting out with unit testing this book is for you.  The author purposefully avoids the topic Test Driven Development (TDD) in order to achieve clarity and focus on the actually unit testing of code without the confusion which can be caused by trying to do so whilst at the same time explaining the TDD workflow.

C# is the love of my life.. two more books on the language from two highly regarded individuals is exactly what the doctor ordered.

(The MEAP for the second edition (C# 4) is available here)

2010 for me is going to be the year of C# 4, Objective C, Cocoa and Ruby.

When I was a Microsoft Student Partner I got it in the neck from my friends (especially the Linux Zealot housemate) about my favourite language and framework not being portable nor open source.  This really pushed by button (as they well knew) considering I am passionate Open Source, Cross Platform development and learning new languages D= !

I am a massive fan of the Mono Project.  I love the idea of C# being truly cross platform.  I also like the fact that many of the .NET libraries are being ported to run on Linux and OSX.  Over the last year I have been working hard to get all my apps that I write in C# to work as well on Linux (where possible).  But there was one platform I did not work with.. the ever more popular OSX.

I find that Apple have an interesting platform (although I may not agree on principle with their ethos).  But this doesn’t mean that I don’t wish to expand my skill set to be a competent developer on their platform.

I purchased a Macbook this Christmas, against my better judgement, and have purchased these two books:

0596004230.01._SCLZZZZZZZ_

Why learn Objective C when I could just use C# with Mono?

Because I, as a hacker at heart, am not satisfied with some abstraction over what is going on… I want to be a strong Objective C developer with a sound knowledge of Cocoa and how things work in the Apple world.  I find the difference from Java and .NET refreshing and I love learning stuff that is completely new.  I want to be able to more effectively use and contribute back into open source projects like CocoaSharp and MacRuby / HotCocoa.

I like how its low level and not “as easy”… I have recently graduated and I am still hungry so lets hope this new educational expedition lives up to my expectations.

2009
12.28

“I think that it’s extraordinarily important that we in computer science keep fun in computing. When it started out, it was an awful lot of fun. Of course, the paying customers got shafted every now and then, and after a while we began to take their complaints seriously. We began to feel as if we really were responsible for the successful, error-free perfect use of these machines. I don’t think we are. I think we’re responsible for stretching them, setting them off in new directions, and keeping fun in the house. I hope the field of computer science never loses its sense of fun. Above all, I hope we don’t become missionaries. Don’t feel as if you’re Bible salesmen. The world has too many of those already. What you know about computing other people will learn. Don’t feel as if the key to successful computing is only in your hands. What’s in your hands, I think and hope, is intelligence: the ability to see the machine as more than when you were first led up to it, that you can make it more.”

Alan J. Perlis (April 1, 1922-February 7, 1990)

http://is.gd/5EA5f (MIT Press)

I love this quote and I am starting to really love this book.  Although it is a mammoth text I find myself finding lots of brilliant quotes and useful experience which as a junior developer I really cant get enough of.

Another great snippet from the Foreword:

“To appreciate programming as an intellectual activity in its own right you must turn to computer programming; you must read and write computer programs — many of them. It doesn’t matter much what the programs are about or what applications they serve. What does matter is how well they perform and how smoothly they fit with other programs in the creation of still greater programs. The programmer must seek both perfection of part and adequacy of collection”

Alan J. Perlis

http://is.gd/5EAlT (MIT Press)

I even thought the first line was brilliant D= !

“This book is dedicated, in respect and admiration, to the spirit that lives in the computer.”

Alan J. Perlis

http://is.gd/5EA5f (MIT Press)

2009
12.09

Recently I was wondering how PRISM (Composite Application Guidance for WPF & Silverlight) achieved a magic trick with its dependency injection (DI) container.

I knew in PRISM you are free to swop in your own DI container, which is nice but I was wondering how you achieved the trick of having your container available within itself.

What do I mean?  Put simple being able to resolve your DI Container in any class within your application.

Example: Where ‘Foo’ is just a plain old class within the application.

public class Foo : IFoo
{
	public Bar SomeProp { get; set; }
 
	public Foo(IContainer container)
	{
		Bar = container.Resolve<ibar>();		
	}
}

So I asked Glenn Block (one of the main guys behind PRISM at Microsoft) on Twitter how this was achieved and he got back to me with some great material which I thought I would share:

  • How to resolve a DI Container in Unity from itself.
  • Why this is bad.
  • How to do it but limiting the badness.

Note: Remember to read these ‘Blocks’ of tweets backwards as it is Twitter. So with 1 & 3 start at the bottom and read up.

0 – Me:

 image

1 – GBlock:

 image

(START FROM THE BOTTOM & READ UP)

2 – Me:

 image


3 – GBlock:

 image

4 – Me:

 image

So the recommendation is to not program against the container as “It makes parts tightly coupled to host configuration” & “makes code less intentful”.

But as with the deign of modular composition frameworks such as PRISM I found it to be a good fit and it allowed for “reasonably” rapid development of the UI and decoupling of the parts of the View & ViewModel that really mattered.  So I see why it was suggested, but I now also see why they now see it as an anti-pattern.

The universal access to the Container and the Event Aggregator with Composite Events made for very easy composition of a WPF user interface from separate modules, but I would have to agree, now that I have more experience, that programming against the container at this level just felt wrong deep down, and when that is the case you know its just not meant to be.

Please feel free to comment.