Posts Tagged ‘Ruby’

Dynamic Division in Ruby

21 July 2007

While writing one of my first Ruby projects I cam across an interesting behavior that initially had me confused. Ruby being a dynamic language, you aren’t declaring specific types so there is a degree of trust in the ruby interpreter. I was doing some simple mathematical formulas but when I ran my unit tests the result were wrong. It turns out that when you divide two integer values the default result type is an integer.

puts 9 / 2 => 4

Looking into it there seem to be two ways to address this, the first is to convert one of the values to a float and the second is to use the quo() method.

puts 9.to_f / 2 => 4.5


puts 9.quo(2) => 9/2

The thing with the last example is that the quo() method on a Fixnum type returns a rational type. Not sure about the benefits of a float v’s a rational so I will leave that choice to you.

One of the consequences of this is a re-emphasising of the importance of unit testing ruby code. If you have a method that does division you will need to include test that ensure that it will support both fixnum and float types.


def divTest(val1, val2) val1 / val2 end puts divTest(9, 2) => 4 puts divTest(9.0, 2) => 4.5 puts divTest(9.to_f, 2) => 4.5

In this case you can see that the method returns different results based on the type of numeric value that is being passed in. One of those learning curve bumps that you can burn a bit of time on.


Another Technology Barometer

3 July 2007

Just came across the TIOBE Programming Community Index as another way of measuring the popularity of various programming languages.

The ratings are based on the world-wide availability of skilled engineers, courses and third party vendors.

Technology Barometer

2 July 2007

A colleague pointed me to a metric that O’Reily keeps in relation to the trends in book sales for various languages. It is interesting to see the decline of java (-14%) and the increase in ruby sales (+107%).

Languages Q1 07 Vs 06

Architecture Epiphany

1 July 2007

I attended the inaugural Australian Architecture Forum on Friday and I must say it was brilliant. What they were able to pack into a single day was breath taking, from arriving at 8am and catching up with old friends and colleagues through to that well earned beer at 6pm it was non stop information. The sessions were mixed between keynote style presentation, breakout presentations and round table discussion sessions which added to what you could get out of the day.

The Keynote was by Dr Donald Ferguson: The key message delivered here was around Web 2.0 and the ability for an end user to assemble an application. The Web 2.0 concept is still built on SOA but as a technology it has been commercialised eg orchestration = mash-up. End result of this is that the number of applications in an enterprise is going to grow and these application are generally going to be changed more frequently than the current application.

One other point that Don made was the redundancy of technology caused by the lack of integration. A laptop has a lot of redundancy, if you have a phone you have a CPU, if you have an iPod you have a hard disk, if you have a GPS you have a screen why can’t we only have one of each?

First Breakout Session was by Andrew Dingley from Object Consulting, on an architecture process he developed at St George bank. He took the use cases and then defined them as services, he then then defining the technical services that made up those functional services as sequence diagrams. Visually these worked, he used Enterprise Architect and functionally it gave good traceability from the requirement through to the design.

The First Round Table Session was on Dynamic Languages in the Enterprise: When we got to the meaty end of the discussion around how does a ruby application live in an enterprise environment teh story fell down. Integrating ruby application with other systems and services doesn’t work at the moment, you need to use something like JRuby to be able to access the java service that provide integration (I assume you could use IronRuby as well).

 The Second Round Table Session was about Software Factories: This was an interesting session as it gave me a chance to validate my understanding of what a software factory is. A software factory seems to be two things: it encapsulates the business (domain) and also the enterprise architecture within a set of guidance. The software factory can if you are fairly standardised on technology be something like the Microsoft Guidance Automation Toolkit or to the other end it would be a set of documentation. Domain Specific Languages seem to be an important mechanism to use, if you are building a factory.

The Lunchtime Presentation was from the IASA: This was an interesting presentation introducing the International Association of Software Architects (IASA), probably the best thing to do is to quote from their web site:

The association is committed to improving the quality of the IT architecture industry by developing and delivering standards, education programs and developing accreditation programs and services that optimize the development of architecture profession.  IASA membership consists of approximately 5,000 members  located in over 40 countries.

Breakout Session Two was on legacy code: Unfortunately this was a very low level presentation looking at code examples and the like, would have been good to have addressed the topic at the architecture level. I think you could find most of the content in the book Working Effectively with Legacy Code. One interesting point was that Legacy Code is code without automated tests

Round Table Three was on the Role of the Architect in Agile Projects: I have made a comment on this topic in a previous post on How to Predict the Future, I think this position still stands. The message seemed to be that architect should to the minimal design, suggestion was to time box. The architect should then roll up his sleeves and get in and code and design work should be at the keyboard in code or on the whiteboard. An interesting analogy was that designing in agile is like designing a garden, it is living and you can easily change it, don’t know how my enterprise architects are going to respond to that one.

The Final Round Table was on Security: Rocky Heckman from Microsoft is well know for his expertise on security and this was no exception. The key at the architecture level is Threat Modeling and Microsoft have a good tool in the Threat Analysis & Modeling Tool. An interesting bit of trivia is that Microsoft Security worked featured in Popular Science 10 Worse Jobs.

Phew, writing about the days has exhausted me again. I hope you can glean from this how great the day was, it was definitely time well spent. I hope they run this again as planned because I will be there with bells on.

Why Geeks don’t play Golf

24 May 2007

It was an interesting morning today doing my usual read of blog posts and the like, over the first coffee of the day. A common theme around golf came up that seemed a little uncanny. First occurrence was while reading today’s Dilbert:

The next occurance was while reading Martin Fowler’s post on Rails Conf 2007. The comment that really caught my eye and stirred some emotion was this:

Corporate IT is dominated by bloatware. Time and time again we have to deal with expensive software purchased on golf-courses that just get in our way while sucking funds and development hours. Technologies that make it harder for programmers to do what they like to do best – make a difference for the businesses they are supporting.

Boy if this isn’t my life, if it isn’t the business bringing the solution to the table, it is them having just signed the contract for the product that delivers it as well. Thank to the benefit of a restructure every year or two the mess that all these golf course decisions creates just becomes a technology issue.

I must say that one of the skills I have been working on over the last couple of years is understanding the business drivers for a project. Technology likes to look at only the technical problems, but much like how you would compare quotes for an extension to a house, you want value for money.

Is Ruby able to revolutionise development such that we can deliver good value for money to the business? Unless it can also address the complexity of the environments that these ruby applications will have to function in, then it will only be a tool suitable for small to medium sized developments and won’t be able to break into the enterprise space.

Is Ruby running with the pack?

29 March 2007

There is a lot of discussion around Ruby and whether or not it can be mentioned in the same sentence as the Enterprise word. I’ll leave my input into this discussion for a later date but one thing I came across today caught me a little off guard.

In a recent episode of .Net Rocks there was a discussion about Cardspaces (Microsoft’s implementation of OpenID) and WCF by Michele Leroux Bustamante. Then in the same time-frame on one of my favourite blogs, Dan Bartholomew has implemented a CardSpaces module for DotNetNuke. Security is a big issue and obviously OpenID is an open standard that seems to have traction in the Microsoft space; there is an OpenID extension for Firefox….. I had better watch this space.

Then, after listening to the most recent podcast on the Rails Podcast, what should I find on Dan Webb’s blog but a post about an OpenID gem for Ruby. Now this is only a small thing but to find that the ruby community is able to add support to the ruby language for a standard like OpenID in a similar time-frame as Microsoft, makes me reconsider where Ruby is in relation to other technologies.

Softies On Rails

26 March 2007

Thanks for your post on Softies On Rails Frank. Looking around the site I came across a good looking Ruby On Rails editor Ride-Me and as only a Softie would appreciate it is written in .Net.


25 March 2007

Building a business layer for an application always seems to have a large percentage of code that you could class as plumbing. Things like getters and setters for properties and search type operations. Reading an article by Bruce Tate about the ActiveRecord framework within Rails I was met with a big suprise. Using the ActiveRecord framework with Ruby creating a business object to represent a person looks like this:

class Person < ActiveRecord::Base

Yep, that is all you need to write and you get a class with:

  • first_name and a last_name properties for all properties of the object
  • save type methods
  • search methods, eg find_by_last_name

What is giving us this is a simple design pattern called ActiveRecord that relies on the assumption that your business objects mirrors the structure of your database tables ie the person object has a corresponding person table in the database.

The ActiveRecord framework within Rails follows a trait that seems to apply to most ruby development, is that by following a convention there is no need to enter configuration information. In the person class example by having a primary key called id and not changing the search standard of find_by_<fieldname> we don’t need to configure the framework it just does it all for us. ORM mapping tools like Hibernate rely on entering configuration information to make them work.

The fact that Ruby is a Dynamic language also brings alot to the table in that we haven’t had to generate any code to comply with a static language. The person object we get has properties for each field in the table and supports the table being updated. In the article Bruck looks at implementing something similar in Jave but you end up with a method like person.get(name) which create smore problems that it solves.

The ActiveRecord framework takes a very pragmatic approach to the problem of creating a business layer in that it doesn’t try to be the solution to all problems. It is a good example of the 80-20 rule in that 80% of problem can be solved with 20% of effort, go outside of the 80% that Active record. You have to deal with the 80% of effort to solve the other 20%.

Very nice!