Roslyn, deux qui la tiennent...

Roslyn September CTP is out, despite rumors of it  being dead, and although there is no redist, it solves all the issues I had with type dependency (Mono's terrible API really does not help) and opens-up the road for VS.Net integration.

This is very exiting news for C#ylon!

using Roslyn.Compilers;
using Roslyn.Compilers.CSharp;

namespace RoslynTest
{
    class Program
    {
        static void Main(string[] args)
        {

            var comp = Compilation.Create("Test.dll"
                , syntaxTrees: new[] { CreateTree("Foo", "Bar"), CreateTree("Bar", "Foo") }
                , references: new[] { new MetadataFileReference("mscorlib.dll") }
                                   , options: new CompilationOptions(OutputKind.DynamicallyLinkedLibrary)
                );

            EmitResult a = comp.Emit("Test.dll");
        }

        private static SyntaxTree CreateTree(string a, string b)
        {
            return SyntaxTree.Create(Syntax.CompilationUnit()
                                         .WithUsings(Syntax.UsingDirective(Syntax.ParseName("System")))
                                         .WithMembers(Syntax.List(CreateCoDep(a, b))));
        }

        private static MemberDeclarationSyntax CreateCoDep(string typeName, string fieldName)
        {
            return Syntax.ClassDeclaration(typeName)
                .WithMembers(
                    (Syntax.FieldDeclaration(Syntax.VariableDeclaration(Syntax.ParseTypeName(fieldName))
                .WithVariables(Syntax.SeparatedList(Syntax.VariableDeclarator(fieldName))))));
        }
    }
}


Back to hacking  tonight!

Project of the week: Left-handed guitar

All this quest for a perfect keyboard layout made me realize that I have lost a lot of mobility in my left hand.

I had a series of pretty bad accidents when I was a kid that damaged my left hand, and I believe that coupled with old age, my left hand is getting weaker and weaker. Here's the list of mishaps:

-Left hand stuck in the emergency brake of my mother's car.
-Middle finger stuck in security door.
-Torus fracture of the cubital bone (x2)
-Wrist fracture (x1)
-RSI, stayed stuck for 3 weeks, never fully recovered (damned ants in my left hand)!

So, I picked-up my guitar to relieve stress after a particularly nasty time spent with ceylon and Irony (If I get my hand on the smartass who decided to add the \i and \I prefixes to identifiers....) I realized my ring and middle fingers were just inert.

So here's a fun experiment, I will restring my sg upside-down tonight, and have a go at it. I'll try to use GnR's Nightrain solo as my benchmark (I am never playing Are You Gonna Go My Way ever again...) and report when things improve!







Ceylon's cool features are too addictive for my own good

I have been playing around with Ceylon after hearing UnFromage singing its praises and it is very addictive.

In my mind there is no contest the C# language is much, much more streamlined and expressive than Java7

BUT...


I am already wishing C# used some of Ceylon's cool features, namely union types.
Consider the following scenario where we use the template method pattern.
    public abstract class Handler<T>
    {
        // do some stuff but don't let the implementor decide of the ordering of actions
        public void DoIt(T value)
        {
            // we're handling the ordering here!
            //  Implementor only provides ways to start and complete
            CompleteStart(value));
        }
 
 
        protected abstract T Start(T value);
        protected abstract void Complete(T value);
    }


Now,  suppose we want to provide a handler that does satisfy both intand double. We have to write two implementations, as C# doesn't do multiple inheritance. If Foo and Bar's implementation are similar we've got to break-down the handler in a third common class. Moar clutter. Don't like it.


Introducing Ceylon's union types!

A union type is defined as being any of the possible types in the union. The type system works its magic retrieves the correct value. Let's pretend our C# union also defines implicit conversion operators and let's take a ride to wonderland.


    public class NumberHandler:Handler<int|double> 
    {
        protected override int|double  Start(int|double value)
        {
            return Math.Pow(value,2);
        }
        override  override void  Complete(int|double value)
        {
            Console.Out.WriteLine("Got {0}",value);
        }
    }


The compiler has to do some magic casting behind the scenes for this to actually work

I'm spoiled already.

Go get hooked on Ceylon now!

I'm itching to see some of those features in the .Net framework...

Weekly project: Dev Dvorak

So I'm nearly touch-typing in QWERTY at a whooping 30WPM...

I realized something in the process. I HATE this layout as a developer, I spend most of my time with my pinky on punctuation.

Exit QWERTY, come-in Developer Dvorak : placing punctuation on the home row and stronger fingers.

Here's my current setup using the mighty Portable Keyboard Layout which works even when remoting / using RGS...

I might switch to Programmer's Dvorak which does not use any dead keys and also works on Macs but we will see...


Resharper lifesaver: Complete current statement

You've entered all your text, your cursor is in the middle of a 200chars long lambda and you can't be bothered to close all parenthesis, go to the end of line and add the last semicolumn?

CTRL-SHIFT-ENTER!

You will thank me later. With bacon. And kisses.

Weekly Project

Fuck it I'm getting older by the minute, if I don't do stuff now I'll never do it.

Goal of the week: I can reach 74 WPM on The Hobbit Test and I'm a kind of keyboard anorak...But I have a terrible secret : I only use three fingers from each hand.

So, the goal of this week: learn to touch-type on qwerty using all fingers. See you next Friday!

3 steps to coder nirVIna

Step 1: Grab a good keyboard (Filco Majestouch 2, US layout, Cherry Browns for our tests)
Step 2: Install AutoHotKeys from http://www.autohotkey.com
Step 3: Edit your Autohotkey.ahk file in "My Documents" and add these:

; CapsLock navigation
Suspend On

i::Up
j::Left
k::Down
l::Right
u::Home
o::End
p::PgUp
`;::PgDn
a::Control 

CapsLock::
 Suspend Off
 SetCapsLockState On
Return
CapsLock Up::
 Suspend On
 SetCapsLockState Off
Return


You can now enjoy your capslock key switching between  qwerty and arrows on ijkl. Note that the indicator reflects the state of arrows vs keys, and you can use the original capslock with shift caps or ctrl caps

Fight ADHD and get instant gratification on a succesful build with Growl for Windows

In the words of Wil Wheaton, "I have the attention span of a gerbil" - sometimes I forget I have just built a project and build it again, and again... and again... then actually hit debug. Let's fix this pathetic behaviour with... technology!

Step 1: Install Growl For Windows
Growl is a system notifier that originally came to life as a Mac OSX application. The kind souls at Growl for Windows have ported it over in .Net, so grab it and install it pronto.

Step 2: Install the VS2010 build notifier plugin
Growl uses various plugins for non growl-aware applications. The Growl Visual Studio Add-In needs to be installed after Growl ran for the fist time.

Step 5: Configure notifications
Open Growl, select your favourite display (or install extras, my favourite is Risor), then configure the VS addin so it doesn't notify on every project build, but only on solution build + project failures, such as:



Now run a build and enjoy the sweet, sweet notification of success!



Fall-Through switch statements in C#

Everybody's been told C# switch statements don't support fall-through, this is a fallacy.


var foo=true;
switch (foo)
{
    case true:
        Console.Out.WriteLine("Bools have 3 values: True");
        goto case false;
    case false:
        Console.Out.WriteLine("False");
        goto default;
    default:
        Console.Out.WriteLine("FileNotFound");
        break;
}


I feel dirty.


Nobody expects the WPF inquisition


Keeping this here whenever another StackOverflow question about WPF comes around so I can just cut'n'paste $generic_reply['What is WPF's main advantage over winforms?']

WPF's chief feature is declarative composition...declarative composition and binding... binding and declarative composition....
WPF's two main features are declarative composition and binding...and hardware acceleration....
WPF's three main features are declarative composition, binding, and hardware acceleration... and an almost fanatical separation of UI and Code through MVVM...
WPF's four... no... Amongst WPF's main features... Amongst its capabilities... are such elements as declarative composition, binding...
I'll come in again.

Three Way Merging Made Painless With P4Merge And TortoiseSVN

There is a fear of merging amongst developers (mostly juniors) and it is due to the fact that they don't merge often enough and sometimes don't use the proper tooling to make this process manager-proof.


In order to ease the pain of merging, let's use some proper merging tools.

P4Merge seems the best contender as:

  • it has 3 way-merge
  • it sports an foolproof change tracker (aka. the change 'curved area thingie')
  • it costs GBP 0.00
Let's see how to install this with tortoise svn and go through a real-world conflict.


Objective-C quick reminders

Just a couple of things to keep in mind when doing Objective-C development:


Properties vs Members



  • Members are accessed through the self-> indirection 
  • Properties are accessed through self. or [self prop] or [self getProp]
Properties and members often share the same name, and by default, the member gets priority, so when a property tagged with the retain attribute doesn't retain, chances are that you are assigning a value directly on the member when you should be working with the property.


VS2010 checklist

WE all share the joys of bleeding-edge tech, but we pay the price in tears of blood. 
Well, I do.
Here's my Visual Studio 2010 checklist of things to install to get a working visual studio 2010 environment, as well as some nice addons

MVVV views / viewmodel WPF mediator : how to tame a grid without any codebehind

So we're all doing WPF/MVVM by now, great, at least we get some nice declarative UI paradigm, where everything is concise and cleanly separated, your XAML doesn't have any codebehind and all is well.

That's until you start using third-party components in your views (say, a grid for example). Most vendors don't ship MVVM-friendly WPF controls, so to interact with these controls, you ususally have two choices:
  1.  Wrapping your control, this never ends nicely
  2. Add event handlers in your view to take care of your components.
I am not satisfied by either method, as wrapping a grid can only end in tears of blood, and event handlers sprinkled all throughout your view will break separation of concern, your view, on top of having an ugly codebehind, now potentially has to pamper serveral controls. And these event handlers will end-up being copypasted everywhere.

Let's see if there isn't a third way we could use, where we still get the benefits of custom event handling without anything seeping in the view itself.