Ivan Porto Carrero

IO(thoughts) flatMap (_.propagandize)

12

Dec
2007

ASP.NET Mvc Taken for a Test Drive

A couple of days ago Microsoft released a CTP of the much discussed ASP.NET MVC handler. I decided to take it for a test drive.

At first I just wanted to have a look at how to use the MVC handler with the ADO.NET Entities but quickly found that I can easily replace like the view engine.

So I diverted my intentions and wanted to look at how hard it would be to plug it straight into the architecture of xero.

At Xero we currently use a 2 step view approach where each page transforms its output through xsl and renders html that way.  Our O/R Mapper of choice is LLBLGen Pro, who does a great job at mapping stuff but the API could be a lot nicer IMHO.

I’ll make my application available soon, as soon as I removed the dependencies on LLBLGen and some of our custom classes. I have to do it this way because we’re a publicly listed company and I’m not allowed to give out that information.

Aaanyway in all it took me about 4 hours to plug in an xslt view engine and implement attribute based filters.

Overall I’m quite happy with what I’m seeing that’s in there. A couple of convenience methods like RenderText(…) would be nice. It would also be cool if it could find out the name of the requested action and then pass that as the current view so you don’t have to specify the name of which view you want to render all the time.

We did run into some trouble while writing unit tests apparently we can’t pass the view context a temp data dictionary but I’m sure that will be fixed soon.

So my conclusion is: There did go a fair bit amount of thought into the handler. I like what I see very much and I’ll definitely keep a close eye on new developments in that space.

del.icio.us Tags: asp.net mvc,xero architecture,aspnetmvc

27

Nov
2007

Re: The Difference Between Meta Programming and IL Weaving

Ayende replied to my post from this morning. His point is that the in order to be able to do meta programming Reflection.Emit isn’t enough because it happens after the compilation has taken place. And in order to do meta programming you need to be able to do that during the compilation step. This is my reply, hence the title :)

Meta-programming can be achieved by having the language implementation change classes or generate classes at some point. In dynamic languages that is generally at run time, it’s most common use is where the data format drives the code ie. a database, csv files etc. For the sake of this discussion i’m going to keep it at runtime, if meta programming occurs at compilation time it loses a lot of its power, how is it going to respond to changes at runtime like changes in the data schema.

You could do this by having an interface of your implementation, If you’re going to use an interface implementation you can just as well generate the class or implement the class. Another thing you need for meta programming is duck typing. So for meta programming to happen you would have to forgo things like type checking, looking for existing methods on classes etc. You would lose the biggest advantage of a statically typed language and one of the biggest reasons for having a compiler at all. So, with all due respect, I wonder at that point why use a static typed language implemented on a compiler, that will make things really hard for you, at all when you can achieve the same things in other dynamically typed languages with hardly any effort.

If all you want is ruby with c# syntax, then you will lose exactly what makes ruby so attractive its more natural syntax. At this moment the IronRuby implementation still needs a lot of work but you could use Ruby.NET and get a good working version of Ruby that runs and compiles on the CLR. Or use ironpython that implementation is a lot more usable at this moment and you can do interop with .NET assemblies.

With Reflection.Emit you can get similar things. You can’t modify existing classes but when you would be using something like an IoC container that keeps track of dynamic proxy wrappers that are being generated so that it can always use the latest proxy wrapper, that way you could achieve almost the same thing. This won’t be the fastest method around but it would give you most the needed abilities. You would still need at least some interfaces and know about those interfaces upfront. After all MSIL is much like a dynamic language.

I still wouldn’t exactly call it meta programming but it can come close, you wouldn’t be able to modify existing classes but you would be able to add functionality to classes. It also won’t be the most easy thing to implement correctly but in theory it can be done.

Method missing in ruby works because the ruby interpreter walks up its tree of objects looking for an implementation of method_missing but that’s also what makes method missing not the fastest mechanism around.

This whole discussion made me think of a generalization Greenspun’s 10th law: “any sufficiently complicated program in a statically-typechecked language contains an ad-hoc, informally-specified bug-ridden slow implementation of a dynamically-checked language.” ;)

What would the implementation of IDynamicObject be ? Would it suddenly drop the type checking for implementing classes and defer that to runtime? How would you like to see IDynamicObject happening without losing static typing along the way ? I would like to find out these things interest me tremendously, I’m always looking for ways to make C# more dynamic but I don’t want to lose static typing along the way.  I would like to use C# instead of C++ for speed and use IronRuby for the rest for example, shifting those languages one era along.

del.icio.us Tags: Ruby,Ironruby,C# 3.0,meta programming

26

Nov
2007

Getting Mixin Like Behavior in C# 3.0

UPDATE: I titled this post wrong. I should have said that you can mimic Mixins to a certain extend with extensions methods.  But extension methods are exactly that, Exten(d)sions of classes. These methods only have access to the public interface of a class you. You also need to specify a using statement with the namespace of your extension class to every class you want to be using the extended object in. Extension methods are syntactic sugar for what you used to do with static helper methods.  That are IMHO the most important differences with a mixin because instead of mixing in functionality you are now extending an existing objects. So the title of the post used to be Mixins in C# 3.0.  And now is getting mixin like behavior in C# 3.0

Yesterday Jeremy Miller put a post up with a list of features he would like to see added to the next version of C#. I don’t agree with everything on that list and some of it is already here.

I’ll take his points and add my comments to them.:

  1. Mixins (I’ll demonstrate how to get mixin like behavior in C#)

  2. Symbols => useless, a symbol is nothing but an interned string. C# is a static language why on earth would you want to go and add non statically typed features to that language

  3. Hashes => Hashes are already a languages feature in C# 3.0, they are called dictionaries.

  4. Automatic delegation => as Ayende said: Mixins

  5. Metaprogramming => no objection here although you can do it now with reflection emit

  6. Make virtual the default to make mocking easier.

 

Ayende has got a similar reply up on his blog and he adds a couple of features.
I agree with his features so I won’t be commenting on them except for asking when do we get those?

Now the bigger problem I’ve got with this is I quite like the distinction of capabilities from one language to the next. Like say Ruby vs. C# there are things that can be easily or better done using c# and there are things that are easier using ruby. However why aren’t you using Ruby if all you want are language features from Ruby in C# ? Ruby is a beautiful language and it’s not just because of the features, they make it even nicer. It’s because of the syntax and the freedom.

I think Ayende clearly gets the benefits because he uses boo a lot. I tend to use Ruby a lot more than I do boo.

Now let’s get on to what is the title of this post.

The way I see it a Mixin is a way to add additional and common logic to classes, you can’t do that in C# at this moment but you can get mixin like behavior by using extension methods.

And this can be achieved by using extension methods in 2 different ways. The first approach has been documented by Bill Wagner but for the record I only found out about it after I had written my little test application to show you what I think is the best way of implementing Mixins. A mixin is often compared to an interface and it’s implementation (you can’t use an abstract class because that could break your inheritance chain in the long run, interfaces are the correct way to implement them)

The first method is to extend an interface and by adding that interface and the Extension methods namespace to your code file you get all those methods mixed into your class. Without the interface it doesn’t work. For simplicity I’ll use a IList in reality I would have somewhat more complex objects. There is only one thing that doesn’t feel too right to me and that is that every class you’re going to use it in needs to know about the extension methods location. I would like to see that if you implement it  on a class it gets propagated whenever you use an instance of that class. Anyway let’s see some code:

The first step is to define an interface that we can extend later.

using System.Collections.Generic;

 

namespace Mixins.Mixins

{

    public interface IAuditable

    {

        IList Auditors{ get; }

    }

}

 

The next step is to define the extension methods

using System.Collections.Generic;

 

namespace Mixins.Mixins.Auditable

{

    public static class AuditableMixin

    {

        public static bool HasBeenAudited(this IAuditable targetClass)

        {

            return targetClass.Auditors.Count > 0;

        }

 

        public static bool HasBeenAuditedBy(this IAuditable targetClass, string name)

        {

            return targetClass.Auditors.Contains(name);

        }

 

        public static IList AddAuditor(this IAuditable targetClass, string name)

        {

            targetClass.Auditors.Add(name);

            return targetClass.Auditors;

        }

 

        public static IList RemoveAuditor(this IAuditable targetClass, string name)

        {

            if (HasBeenAuditedBy(targetClass, name))

            {

                targetClass.Auditors.Remove(name);

            }

            return targetClass.Auditors;

        }

    }

}

And the last step is to create an actual object that will have our mixin.

using Mixins.Mixins;

using System.Collections.Generic;

 

//Extend our object with the mixin methods

using Mixins.Mixins.Auditable;

 

namespace Mixins

{

    public class DataRecord : IAuditable

    {

        private List auditors;

 

        public DataRecord()

        {

            auditors = new List();

        }

 

        public string Name

        {

            get;

            set;

        }

 

        public string Email

        {

            get;

            set;

        }

 

 

        #region IAuditable Members

 

        public IList Auditors

        {

            get { return auditors; }

        }

 

        #endregion

    }

}

 

Now to test it I used this console app:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

 

// Extend our object with the mixin methods

using Mixins.Mixins.Auditable;

 

namespace Mixins

{

    class Program

    {

        static void Main(string[] args)

        {

            DataRecord record = new DataRecord();

            record.AddAuditor(“Ivan Porto Carrero”);

            record.AddAuditor(“Kirk Jackson”);

 

            Console.WriteLine(“The current auditors are: “);

            record.Auditors.ToList().ForEach(auditor => Console.WriteLine(auditor));

 

            Console.WriteLine();

 

            record.RemoveAuditor(“Kirk Jackson”);

            Console.WriteLine(“The current auditors are (after removal): “);

            record.Auditors.ToList().ForEach(auditor => Console.WriteLine(auditor));

 

        }

    }

}

The second way I had in mind doesn’t provide everything I get from this first way and was by extending a base class. I’ll drop that explanation and just go for the conclusion.

 

As I said before the only thing that doesn’t make extension methods to be complete mixins is the fact that you can’t actually mix it into a class, you can get really close but not all the way there. Now that isn’t such a huge problem, it gives you a bit more granular control. Another thought I have about this is, extension methods don’t have access to the private variables of your class only to the public interface of your class. That is also a limitation that proper mixins don’t have.

 

What do you think ?

 

del.icio.us Tags: C# 3.0,mixins,programming

20

Nov
2007

Testing SSL on Vista

Today I had the requirement to add SSL encryption to some of the pages in one of my projects.

To test this I remembered that IIS6 had a tool SelfSSL and tried to use that.. failing my first attempt I also saw a folder OpenSSL in my tools folder. At which point i turned to google and google came up with this link to Scott Gu’s blog. I’m stoked about the fact that IIS7 has this ability built into it. Following the steps he outlines there helped me get going really quickly.

Thanks  Scott :)

19

Nov
2007

Ruby-In-Steel Is Giving Intellisense for Ironruby in Vs

The guys over at Sapphire Steel have been doing great work with the current implementation of IronRuby

Today they put a blog post online showing you how far they got for implementing intellisense.

 

I’m pretty happy with the progress ironruby is making there are a whole bunch of people contributing. The guys from the Mono team have been following the development as well to make sure you can run ironruby on MS .NET or on Mono which makes it a really good alternative to the C-ruby implementation as soon as Ironruby has matured enough.

If you have some free time and are interested in helping some really smart people implementing a programming language I suggest you check out the ironruby.net website and join the mailinglist on rubyforge.

Technorati Tags: ironruby,dynamic languages,ruby in steel

15

Nov
2007

What Do You Expect From a (I)DE?

I’ve been thinking about what I consider the bare minimum to be for a IDE.

First off let me start by saying that an editor with snippets is NOT an IDE, it’s an editor. The hardcore guys out there that favor that type of tool musn’t be suffering from Carpal Tunnel Syndrome or the likes.

I personally have found myself having a hard time accepting the fact that I have to write all my well known classes and functions completely.

Here’s my list of features:

  • Intellisense - Context sensitive autocompletion and discovery of members of a type + the type of member accros the board (xml, html, code files….)
  • Refactoring - being able to safely rename methods, classes etc.
  • Code navigation - much like ctrl-b in resharper, intellij, netbeans,….
  • integrated debugging support accross the board
  • background compilation for compiled languages (instant feedback)
  • easily extensible with your own plugins (prefferably in yaml, xml etc)
  • proper find-replace functionality with regex support
  • code formatting and folding accross the board.
  • and most importantly it has to let me get on with my job.
  • integration of unit test frameworks not just a vendor specific one.
  • integration with source control applications

What needs to be added to this list ?

On a side note I also want to link to a post from Mike Duncan who has aggregated a bunch of really cool tools.
15 hot tools that made me a coding Paris Hilton

del.icio.us tags: programming, ide, development tools

15

Nov
2007

Doing a Talk at the Alt.NET User Group Meeting

I’m doing my talk on the DLR and IronRuby again on wednesday for the Alt.NET user group meeting in Wellington. If you have the time please come along.

 

This is the invitation that went out:

Come along next Wednesday to our next .NET user group meeting. There’s
not that many left before the end of the year!

Note that next weeks meeting will be at the Xero office, details
below. Please RSVP in a separate email to kirkj@paradise.net.nz so we
can organise catering.

Cheers,

Kirk

Dynamic Runtime & Languages - What’s it all about?
Wellington, Wed 21/11/2007
Gather at 5:55pm, starting at 6:00pm

Presented by Ivan Porto Carrero

Ivan will be presenting on the Dynamic Language Runtime and the Ruby
programming language.

IronRuby is Microsoft’s implementation of the Ruby language over the
.NET CLR, and uses the new Dynamic Language Runtime to support the
dynamic language features of Ruby.

Come along to find out what makes dynamic languages different to
object-oriented languages, and what make the DLR and Ruby interesting.

Ivan is a regular speaker at New Zealand .NET user group events and
Code Camps, and is writing a new book on IronRuby.

Venue

Xero
Level 1
Old Bank Building
98 Customhouse Quay
Wellington
(Above Workshop)

del.icio.us tags: Ironruby, dynamic languages, dlr, user group, xero

13

Nov
2007

Innovation Anybody ?

Through Lucy McFadden’s blog I found a bunch of slides in this post talking about creativity and innovation.

One of my most used expressions is: Discontent breeds innovation

Which is my justification for being grumpy J

Anyway I’m sure this is old news to some and will be new to others:

http://www.slideshare.net/imootee/10-lessons-of-innovation-idris-mootee-keynote

I particularly like slides 7, 9 , 11

del.icio.us tags: innovation, creativity, presentations

05

Nov
2007

Congratulations to Mindscape

A couple of friends of mine own the company Mindscape

They were interviewed by Ron Jacobs at the latest NZ tech ed in August. And that has now just been put up on channel 9 as part of the ARCast series.

The interview is about their product LightSpeed which IMHO is one of the nicest ORM’s out there. I’ve used it in a couple of things now and I am absolutely surprised by the fact that lightspeed is a good name for it because it is really fast. If you haven’t taken it for a test drive you should do so immediately.

Now everybody rush over there to see their interview.

 

Well done JB, JD and Andrew.

del.icio.us tags: Lightspeed, mindscape, ARCast, ORM

03

Nov
2007

Boot Camp Session

I just finished my session at Boot Camp. A code camp organised on the south island in Christchurch.

I’d like to thank everybody for coming to listen to me, and I’d like to thank Ivan Towlson for his help on getting me started with wpf and for elaborating on the section mixins during my talk.

As promised I’ve put my slides and demos online.

Powerpoint 2003 version

Powerpoint 2007 version

Demo

Hope to see you again soon!

del.icio.us tags: wpf, ironruby, dynamic languages

To top