Category Archives: IronRuby - Page 4

Compiling Mono and IronRuby on OSX Leopard

I tried to compile IronRuby on OS X (leopard) with the dmg I downloaded from the mono website, and that didn’t work.

I then uninstalled that mono version by running monoUninstall.sh and proceeded to get mono from subversion. I’m putting these steps on my blog more for future reference when I decide to reinstall my box for some reason.

Download gettext, pkgconfig and glib2.0

extract the archives and build them in the following order gettext, pkgconfig, glib2.0

./configure –prefix=/opt/local
make
sudo make install

At this point it would be wise to set the PKG_CONFIG_PATH environment variable. I added the following line to ~/.bash_profile

export PKG_CONFIG_PATH=”/usr/local/lib/pkgconfig:/opt/local/lib/pkgconfig”

next it’s time to check out the mono sources from their repositories

cd ~/
mkdir tools
mkdir mono
svn co svn://anonsvn.mono-project.com/source/trunk/mono
svn co svn://anonsvn.mono-project.com/source/trunk/mcs
svn co svn://anonsvn.mono-project.com/source/trunk/libgdiplus
svn co svn://anonsvn.mono-project.com/source/trunk/moon
svn co svn://anonsvn.mono-project.com/source/trunk/olive
svn co svn://anonsvn.mono-project.com/source/trunk/gtk-sharp

checking those out will take a while

now go into the mono directory and build mono

cd mono
./autogen.sh –prefix=/opt/local/mono –with-preview=yes –with-moonlight=yes

–with-preview enables the .NET 3.5 features that have been implemented so far
–with-moonlight enables support for moonlight

make
sudo make install

This will also take some time and when it completes you can check if mono is installed by typing mono -V

That’s it for mono, now onto IronRuby

cd ~/tools

svn co http://ironruby.rubyforge.org/svn/trunk ironruby

sudo gem install pathname2

rake compile mono=1

And that should be all :)

UPDATE: I’ve got new instructions for building IronRuby

Using Ruby to Generate LightSpeed Models – Part 1

This is the first in a multi-part post on a little ruby application I wrote to generate models for LightSpeed.

The ultimate goal is to consume the entities we generate in this series with IronRuby and perform some data access.

Today I’ll post the code I wrote for creating the database connection. At this moment there is only code there to connect tho sql server. But I may want to add providers later if I decide to keep using this code. That’s why some bits are in a separate module.

This are the specs I wrote for the connection manager. The connection manager is the class that reads the database config, gets a connection and executes sql statements. I think this code is pretty simple so I won’t put a line-by-line explanation.

It uses DBI to connect to the database and reads out the results of the executed sql statement. In the next post I’ll talk about getting the metadata that is required from sql server.

DB::DbiSqlServer
- should return a connection
- should say it’s an ODBC connection when a dsn is provided
- should return the correct connection string for an ODBC connection


module DB

	module SqlConnectionManager

		DEFAULT_CONFIG_PATH = File.dirname(__FILE__) + '/../config/database.yml'

		attr_reader :connection_string, :connection

		def initialize(config=DEFAULT_CONFIG_PATH)
		  if config.is_a? Hash
		    initialize_config config
		  else
		    read_config config
	    end
		end

		def read_config(config_path, config_name = 'sqlserver')
			initialize_config(YAML::load(File.open(config_path || DEFAULT_CONFIG_PATH))[config_name])
		end

		def initialize_config(config)
		  @config = config
			@connection=nil
	  end

		def odbc?
		  return true unless @config.nil? || @config['dsn'].nil?
		  false
		end

	end

	class DbiSqlServer
		include SqlConnectionManager

		def connection
			if @connection.nil?
			  @connection = DBI.connect(connection_string, @config['username'], @config['password'])
			end
			@connection
		end

		def connection_string
		  if odbc?
		    "DBI:ODBC:#{@config['dsn']}"
		  else
		    "DBI:ADO:Provider=SQLOLEDB;Data Source=#{@config['host']};Initial Catalog=#{@config['database']};User ID=#{@config['username']};Password=#{@config['password']};"
	    end
	  end

		def fetch_all(sql_statement)
			result = []
			connection.execute sql_statement do |statement|
				while row = statement.fetch do
					r = {}
					row.each_with_name do |val, name|
						r[name.to_sym] = val
					end
					result << r
				end
			end
			result
		end

		def execute_non_query(sql_statement)
		  connection.do sql_statement
		end

	end

end

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.

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.

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: , ,

I’m getting to write a book !!!!!!!!!

I just got confirmation from Manning publishers that I get to write a book on IronRuby.

I personally think this is great news :D

I will keep you updated with more progress as I go along.

I just wanted to get this message out.

A little browser with ironruby and wpf

Whilst preparing for my talk on saturday I got to play a little with Iron ruby and wpf.

One of my experiments was to create a little browser which i dubbed biffy :)

You can download it here: biffy.zip

 

del.icio.us tags: , ,
Page 4 of 41234