Chris Donnan : Programming – Brooklyn Style


Erlang vs Ruby

Erlang vs Ruby

Great post on 2 of my favorite languages.

Filed under: erlang,programming,ruby — chrisdrop @ 12:50


How I have fit IronPython, Ruby, JRuby and IronRuby into my existing .net projects

Ruby and Python are great languages. I have spent several years now with ruby and I am just getting into python in the past year or so. I will still admit that I prefer ruby in every way, but I have come to like and appreciate python as well.

I have been working on building some very interesting global derivative trading applications – so how do python and ruby factor in?? Well – I could have ‘just used them’ in several places. That of course is not valuable, but I have found a few ways to use these tools to really add value to my projects.

Scripting for your existing .net application

I have been making an effort to make our plugin application suite scriptable. I have been able to get IronPython 2 running along with a syntax hi-lighting code editor. It has proved extremely useful. I have also tried to do the same for IronRuby, but with less useful success. Why you may ask – predominantly for 2 reasons:

IronPython vs IronRuby for scripting your existing applications

Basically, IronRuby does not let you do some things that are a must! You CANNOT unsub from events yet :( . The other big issue is calling existing .net APIs that need generic args. You can see Jon Lam’s response to my queries here. Jon also said:

Our .NET interop is fairly weak today. Because of our current push to get the language running in time for RailsConf, all .NET interop work is being pushed back into June on our schedule.

I understand, but this does make it virtually unusable for using as an existing scripting engine against my current .net applications.

IronPython 2 does a MUCH better job of .net interop. It basically just works as expected in 99% of the cases I have needed it for. This is just a joy I must say. Especially trying to use the early cuts of IronRuby on the DLR, it was painful to get anything interop based between existing .net and IronRuby really working.

Another thing I have done with IronPython is to support ‘calculated formula columns’ in a UI Grid control. We basically implemented this and it is currently ‘not supported’ in production, but in a future iteration we have planned (and requested from users), excel like formula summaries/ aggregations. We will continue this work with IronPython.

So – as you can see – IronPython made itself able to add value.

So how have I fit in Ruby in a meaningful way?

Essentially, we have a plugin framework so that several teams can concurrently develop ‘independent’ applications that can integrate. This means that there are several global teams developing plugins (think eclipse) that can integrate, use and extend one another. This is great, but it means there are all kinds of build, assembly versioning and other application packaging, deployment issues.

In any big bank, or other corporation I expect, there will be different ways of doing things. The continuous builds for differing teams may be different. Some are nant based, some are simple, some are complex, some are msbuild, some do a better job of CruiseControl setup than others, etc, etc. Now if you want to take the work from several teams like this, and build, package, test, deploy in a sane way, there is some orchestration needed. This is where I have used ruby to add real value.

Ruby, Rake/ Python, BuildBot

Rake (and plain old ruby, not j, iron, or another variety) have enabled me to have a single homogenous view of the otherwise complex world. It is basically my tool for integrating multiple teams that are doing things as is appropriate in their own area, but not necessarily what is the ‘best’ for use by everyone else in the world. Ruby has REALLY shined here. In stead of having dozens of XML, Nant, MSBuild scripts, MSBuild extensions, Nant extensions, cruisecontrol configs, bat files, etc – I have ‘owned’ them all with some rake build scripts. I have managed to do this with some ~200 lines of terse, easy to read ruby.

Interestingly, a smart colleague of mine has done something very similar with plain-old-python (and BuildBot). He has managed to take some 50 projects that can be put together in varying ways, built, deployed, etc. He has taken a very difficult problem (managing a large enterprise suite of .net of branched, versioned and VERY WIDELY UTILIZED software) and owned it with some 400-500 lines of python.

What did we get for our efforts with python and ruby?

Number one is just the joy of really getting into daily use of other languages. I have programmed several languages over the years from C/C++, to Java, to SQL, Javascript, Tradestation EL, to Python and Ruby. Working with new languages is a good experience – bottom line. I have had a lot more time with ruby than python. I always love ruby, and I have really enjoyed more real time with python in the past year. I think these languages have each made me a better programmer.

With regards to scripting applications, these languages, in particular IronPython have just made it too easy to add value fast. I have done the work with ANTLR, regex garbage languages, compiling C#, etc. These approaches ALL take much more effort to get similar rewards. I can see myself working in a mode of ‘core plumbing’ in C# and/ java and the higher level stuff in IronRuby JRuby.

That reminds me, a small note. Since we are java server/ .net client apps, I have used JRuby on several occasions to quickly do some send messages around the network, and otherwise mimic stuff coming from the server. I have had more effort on the client/ .net side of things, but I am sure if I was doing more server work, I would be using JRuby all the time.

Regarding build and integration – the big thing that we got IMO was a homogenous solution. Whereas before, there were the xml files, bat files, etc. – we each now have small bits of easy to manage code that does all we need. This is coupled to a small degree of ‘convention over configuration’, but essentially, we have gotten a lot of value for a little code and effort. We have also gotten easy to maintain solutions going forward.


The only real downside here is ‘adding more tools’. There is always resistance (appropriate more or less) to adding to the enterprise overhead of ‘more tech’. Developers also need to learn more to work in more ‘polygot programmer’ environment. So the ‘more tech is bad’ and ‘devs need to learn more’ arguments are valid arguments. That being said, I think the benefits are outweighing the downsides so far.

The future?

I see more coming in the same spaces. I will be working more on ‘higher level scripting’ of existing .net apps, and build/ integration etc. At some point, I can see doing ‘it all’ with these languages perhaps – but I think the current sweet spot in the stack is adding value at certain points of the abstraction. The right tools for the right job and all that.

Filed under: c#,dynamic languages,Interop,java,programming,python,ruby — chrisdrop @ 12:56


Ruby refactors equals and get hash

I was looking @ moving some code for a project that was started in C# to Ruby. 1stly, it is astounding how much less code it takes to do the same stuff. That however is not the reason I chose to post this morning.

Gabe and Micah are playing nicely together today (it is nice when a 3 and 5 year old brothers can get along so well). I have been fiddling with this code on the sofa and while moving my code, I came to move a c# Equals(object) method and the counterpart GetHashCode(). ReSharper is a great tool – it had given the basis for these overrides. Simple Alt+Insert gives you the ‘generate’ menu and from there you can ask it to generate these methods for you. Essentially – you tell ReSharper the fields that must be ‘unique’ and then it can handle the Equals and GetHashCode methods for you.

Here is what I had in my c# code:

c sharp version

Now this is fine (not exactly) for my C# application as I see it. ReSharper kindly churned out the code I needed also – which is great. When I moved it into ruby however, it looked very un-ruby. Astute readers will also notice that the implementations of Equals and GetHashCode do not match – the Alias property was added later, included in the Equals but NOT in the GetHashCode :( . Generating code has its issues it would seem.

One of the areas that ruby excels at is helping you write less code. Part of that is identifying the little repeated bits in your code and automating it away with a little ruby.

So what is the pattern above? Well – equals checks for null, checks for direct object reference comparison, then checks a number of fields. It also does a type check. Then it compares a number of fields. If any of these fields fails comparison – it returns false. Ruby does not really need the type check, it just says ‘if you have these props then you are fine by me’ (duck typing).

The folks @ JetBrains recognized the pattern – based on the input of what properties are unique, it generates a code snippet. In ruby, we will not generate code, but handle it like this:


Here include a module called SymbolHashEquals. In this module I define 2 methods symbol_hash and symbol_eql?. These methods take a list of attributes and then apply the same logic that resharper generated. This uses ruby’s symbols that allow you to refer to elements by the ‘name of the code’ or … symbol.

In stead of having our class generate methods based on a heuristic or 2, we simply make a module that holds that abstraction, then we include it, and have our host class use it. Essentially, since ruby lets you ‘do more with less’ we do not have to ‘generate more code’ – we simply can codify more into our solution and have less dumb, generated code. Instead of investing in software to generate more code, we do less!

Here is our module that works on the symbols and handes the standard eql?and hash.

symbol hash eqls
symbol hash eqls

Now – rather than generating code every time I need that same logical heuristic, I simply include that 1 module, and we are good to go. Less code, less repetition, etc.

There you have it – ruby rocks!


Filed under: c#,programming,ruby — chrisdrop @ 13:50


More Fuzzy Logic, this time in Ruby – RFuzz


module RFuzz

    class Math
        def self.max(a,b)
            if a > b then
                return a
            return b
        def self.min(a,b)
            if a < b then
                return a
            return b

    class BoundedSumFuzzyOr
       def operation(a, b)
        Math.max(1, a + b)

    class AlgebraicSumFuzzyOr
       def operation(a, b)
        a + b - a * b;

    class StandardFuzzyAnd
       def operation(a, b)
        Math.min(a, b);

    class AlgebraicSumFuzzyAnd
       def operation(a, b)
        a * b

    class BoundedSumFuzzyAnd
       def operation(a, b)
            Math.min(0, a + b - 1);

    class TrapezoidMembershipFunction
                 B			  C
                 /			   \
              A /               \ D

        def initialize(a,b,c,d)
            @a,@b,@c,@d = a,b,c,d

        def degree_of_membership(variable)

            # in the flat part
            if (variable >= @b && variable <= @c)
                return 1

            if (variable >= @a && variable <= @b)
                return (variable - @a) / (@b - @a)

            if (variable > @c && variable <= @d)
                return (@d - variable) / (@d - @c)

            #var < a
            #var > d
            return 0;

    class TriangleMembershipFunction
                 /	\
              A /    \ C
        def initialize(a,b,c)
            @func =,b,b,c)
        def degree_of_membership(variable)

    class GaussianMembershipFunction
        def inititialize(center, width)
            @center, @width = center, width

        def degree_of_membership(variable)
            Math.E ** ((-(variable - @cente) ** 2) / (@width ** 2))

    class VeryHedge
        def operation(a)

    class NotHedge
        def operation(a)
    class SomewhatHedge
        def operation(a)

Filed under: AI/ Machine Learning,programming,ruby — chrisdrop @ 20:31


Thoughts from Maine – user experience, ruby, python and more

I have been spending all my time relaxing, playing with the kids, sitting on the porch reading and looking at the Atlantic. It has been a bit rainy – but still just about perfect relaxation and family bonding.

The reading time has been great. I have also been doing some programming play while my younger naps a few days this week. A good 3 hour nap makes for some good programming play. I have been trying to come up with ways to slay XML – replace with DSL or a real languaga – since we are implicitly programming in XML too often – since it is just text. They used to call this “scripting”….

My thoughts on python are pretty simple:

  • __init__ is the ugliest constructor :( ?? Double underscores before and after?? Why ?? I know they did great things with python – why did Guido and the other smart folks leave us with that one??
  • Passing of self everywhere seems to be … excise … more on that later. For those who have not played with python – if you have a class – your “constructor” (initializer) is that __init__ business, the pass of self to the constructor is needed to reference class variables. It is implicitly passed in as the 1st argument. The same goes for methods – if you want class variables - you need the self method argument.


  • The whitespace handling is not an issue - I expected to be irritated by it more – but the fact that whitespace is “part of the language” is actually OK.
  • Ruby is just much nicer to me. The could be in part because I have done more with it – but it is likely ruby is just more friendly to the programmer…

User experience … for programmers

Since I have been reading Alan Coopers newer book: About Face 3: The Essentials of Interaction Design and Bill Buxton’s Sketching User Experiences: Getting the Design Right and the Right Design I have been thinking again – a lot – about real user experience. While I am really into programming – and finance – I am also really into giving a great user experience. I had the opportunity to work with a really good bunch of people at one of the other financial firms that were really into actual user experience. My current effort involves making yet another end user set of applications – and I am dead set on providing a fantistic user experience.

I went through the normal Alan Cooper-isms (from his former writings) on formulating personas for the user types, understanding the users real goals, and breaking down their task flow. I have also been thinking about another Cooper-ism – “trimming the excise”.

Alan Cooper on Excise:

Each bit of interface involves a little bit of added overhead, what I call “excise,” or extra work that the user must perform merely to manage the idiom, with no benefit to the user or the business. This includes things like moving windows around or pressing OK buttons. Lots of interface elements means lots of added excise. After a while, the user spends as much time flipping between views, scrolling down lists and summoning dialogs as she does useful and productive work.

This is along the lines of “value stream analysis” from business process modeling. Your job as an experience designer is to trim the tasks between the think the user actually wants and what they have to do to get there. If they need to horizontally scroll, do 6 clicks and a few drag and drops to get to the actual thing they want – there are many steps which are “excise” and should be trimmed.

So – I am serious about putting the right info in front of my users – at the right time – so they can make the fewest clicks possible to do what they are actualy wanting to do.

Python could take away a few lessons I think…

So how does this relate to ruby and python?

Well - if you read musings on ruby – you will see that much of the original spirit of ruby (see Matts – ruby author) is simply joy, happiness and simplicity in programming. The efforts to trim the excise from ruby have been strong. Ruby’s author has made sure to give programmers a great user experience with ruby – and this sentiment is profoundly embedded in the rubyist community.

Python by contrast does not really have this feel to me. The need to __ here or there, to pass self around, the way lambda expressions are, they all feel – sub-par. They feel to some degree like there needs to be some syntactic excise trimmed away…

That said – Python is OK. I like it enough that I would use it. It is a real scripting language that has value. I would simply PREFER ruby. Too bad you STILL cannot make a trading system, or a real desktop application (yes I know – Ruby QT bindings are there)… Sometime soon I hope :)


Filed under: programming,python,ruby,user experience — chrisdrop @ 11:39


Cross Language Validation – Ruby?? Python??

For a current project – we have .net clients and java servers – seems to be the wall street standard – at least for my past several clients/ employers. That said – another common scenario is to standardize message formats via XSDs. If we standardize XSDs we now have a contract for message formats. This is the way it is usually – nothing new here. That said – XSDs are not so great at extended validation. You can do some amount of simple validation at the element level (regex, must exist, enumerations, etc) but to do more complex validations between elements of more complex types – it gets increasingly expressive and unwieldy to do in XSD.

Another complicated scenario is partial validation. UIs that have pages of forms to fill out are one example of where partial and/ or contextual validation must be considered. You cannot simply consider the whole thing valid or invalid – you must consider where in the scheme of things you are – and given that context -are you OK.

I am considering as an alternative using a dynamic shareable language like Ruby or Python. I would prefer Ruby – mostly because I think it is a nicer language. That said – JRuby and Ruby CLR could certainly do the trick on either side of the fence. If we were to have object schemas defined as XSDs and defer the complete validation to another set of constructs – we might be in business.

Say for example we have a ‘person’ defined in our message XSDs. We could then have java and .net objects that are ‘person’ class instances. We could then have a ruby routine that validates a person. This Ruby code could run in java and .net and thus – to a large extend be shared. The only tricky bit that comes in is the ‘includes’ or ‘imports’ into the Ruby in it’s respective runtime. In other words – if we have JRuby as the runtime – we would need to let JRuby load in the package for the correct java class ‘person’ in this example. Similarly – the .net runtime would need to reference the correct assembly for the .net object equivlent of ‘person’. Aside from that – it seems that Ruby should work to lay out the validation with arbitrary complexity.

I will soon see if I can get some buy on to try out this idea and I will let the blog world know how goes it.


Filed under: c#,java,python,ruby — chrisdrop @ 15:31


Python or Ruby in your C# application

I am looking forward to embedding some modern object oriented scripting in my upcoming applications. IronPython is the best candidate currently. as an ‘expressions’ framework. It is basically an Antlr based executor of string C# code – see here. This comes with the runtime burdens (non-trivial sometimes) the code management issues of Antlr (C# code generation). It is also not a complete language; you cant use all of C#.  I have used the expressions stuff in certain conditions. I have also done a few variations of my own reflection based ‘mini-languages’. I have done my own operator precedence parsers, etc. Using a more complete – powerful scripting language like Ruby or IronPython seems great… Here is a brief article about how to embed the IronPython engine in your C# application.
I will also mention that Ruby CLR has come a long way. I have been following both the Ruby CLR that John Lam has been working on, as well as the Gardens Point Ruby CLR Compiler project. I would say that IronPython is certainly ahead, but they will be there soon (I bet Ruby CLR before Gardens Point).

I believe that embedding these languages in my larger .net applications at the approprate layers of abstraction will enable removal of plenty of, reflection code and XML configuration. These are often used in conjunction to allow some extension points. Expressions and my mini-languages have been useful here. Class types implementing an interface and the concretion type in some XML config file is SO common. Moving more of this to a LANGUAGE like Ruby or Python will be welcome!


Filed under: dynamic languages,python,ruby — chrisdrop @ 03:37


Sapphire in Steel – Ruby in Visual Studio 2005

An IDE for Ruby – Visual Studio 2005! Interesting.. This is an IDE for Ruby – NOT for .net – it will only make Ruby output – not .net output. Visual Studio certainly is a complete IDE – and there is a deep SDK for extending Visual Studio -  so – why not?
Sapphire in Steel  – Ruby in Visual Studio 2005

Filed under: programming,ruby — chrisdrop @ 03:35


IoC, Dependency Injection for Ruby

Well – After looking at a few other Ruby IoC containers – I am comparing Needle and Copeland. My thought is currently that Copeland feels more comfortable in general. It seems to offer much of what Spring offers from the ‘core container features’ to some AOP type features as well. That being said – I feel the need to try Needle a bit more as it seems less familiar to me (sort of reminds me of PicoContainer). This goes to one of my core ideas that I try to love by:

If you are in your zone of comfort – you are NOT learning.

I will update as I dwindle down to the essentials of daily use with these containers.


Filed under: programming,ruby — chrisdrop @ 03:41


Pragmatic Programmers 10 Part interview

Here is a link that has all 10 parts of an interview with the Pragmatic Programmer guys. I refer to lots of these ideas all the time. So – go read this stuff – better – get and read the 1st book The Pragmatic Programmer: From Journeyman to Master

Then get this one and read it: Ship it!: A Practical Guide to Successful Software Projects

Then if you like Ruby – get these – Programming Ruby (2nd Edition) and Agile Web Development with Rails: A Pragmatic Guide

I guess I am a fan of thier work – lol.


Filed under: Agile Development,books,programming,ruby — chrisdrop @ 16:00


Active RDF – a set of tools for semantic web work using ruby

Active RDF – is a set of tools for semantic web work using ruby. I have been looking at the Redland RDF Application Framework from Dave Beckett lately. I believe this makes use of it – good stuff!

read more | digg story

Filed under: ruby,semantic web,Xml — chrisdrop @ 21:48


Deep Integration of Ruby with Semantic Web Ontologies

A great article (*warning* PDF) chatting about the match that could/would exist between Ruby and the Semantic web technologies.

I agree that the match between the way of ontoloties and and the way of languages like Java and C# may be off.

I will be curious to see if any supporting frameworks come about in this space.


read more | digg story

Filed under: ruby,web services,Xml — chrisdrop @ 15:48
Next Page »

Powered by WordPress