DCSIMG
January 2009 - Posts - IronShay

January 2009 - Posts

IronRuby, IronPython and DLR Daily Builds RSS Feed Is Available!

With the help of Harry Pierson (AKA DevHawk), there is an RSS feed that will notify you when a new nightly build is available!image 
The builds are daily and you get the latest versions of IronRuby, IronPython and the DLR in Silverlight or desktop versions.

So all of you early adapters, go ahead and subscribe to the feed!

Comment: the files in the feed are the built files, not the source code.

Enjoy,
Shay.

Posted by shayf | with no comments
תגים:,

What Iron Means?

This is one of the first questions that I’m asked every time I present IronLanguages to people… So what does it really mean??

There is no straight answer to that, but I can try:

Jim Hugunin said on his PDC session that Iron might mean Implementation Running On .Net.

This is soooo NOT cool!

We must come out with a better solution! The letters are not so friendly, but it’s a job we have to do. For us, for our kids!

Here are my (rather lame) offers:

It’s Real or Not?

Invincible Romantic Old Ninja

Imagine Rain of Nickels

 

Well… What are your offers?

Posted by shayf | with no comments

The Resolver One Competition – Win $$$$$$!

Resolver One is a spreadsheet environment that is written entirely in IronPython. They’ve done some amazing work there in termsWin money!!!! of extensibility capabilities.

 

Moreover, they now have a new competition – create a spreadsheet with amazing new capabilities written in IronPython scripts, upload your creation and you can win a 2000$ prize for the best spreadsheet of the month and 15,000$ for the best of the best!

So what are you waiting for? Browse to the competition page, read the tutorial, go wild with IronPython and make mama proud! :)

Good luck!
Shay.

Posted by shayf | 1 comment(s)
תגים:,

Is There Right Code and Wrong Code?

Today I argued with my boss about a piece of code. I said that the code is wrong because it didn’t do what it had declared to do (it’s named “GetMMM” and it actually added stuff too), my boss said that this was the right place for the code because it would prevent future bugs.

My questions are simple –

  • Can a piece of code, that does not follow the “rational” coding approach, be called “wrong code”?
  • Should a piece of code that prevents bugs, and breaks all coding standards while doing so, be left in the code?

What do you say?

kick it on DotNetKicks.com

Posted by shayf | 6 comment(s)
תגים:

IronLanguages and Cross-Platformability

Most dynamic languages can run on multiple platforms. IronPython and IronRuby are no exception. The dev teams are investing lots of resources in order to make this happen because of the importance of this feature to the community.

IronPython and IronRuby can be run on top of Mono, which enables you to run .Net applications on top of different platforms, including Linux, BSD, Mac and more.

mono-gorilla

There are some great posts that show you how to do that:

Enjoy the cross-platformability! :)
Shay.

The dynamic Keyword Part 2 – IDynamicObject

This is the second part of my series about the new dynamic keyword in C# 4 (Read the first post here).

As I talked on the first post, the dynamic keyword does the dirty reflection work for you. This is very nice, but it’s like moving forward from a desktop computer to a 10kg laptop – you get to be more dynamic, but it’s still heavy to move around…

The first laptop - heavy!

The dynamic keyword holds a greater power inside, and this is what I’m going to talk about today – the IDynamicObject interface.

What is the IDynamicObject interface?

When we declare an object as dynamic and execute actions upon it, we actually use a default IDynamicObject implementation.

The IDynamicObject interface has a few methods, the important ones (for this post) are – Invoke, GetMember and SetMember.
The idea is very simple -

dynamic myObject = GetIDynamicObject();
myObject.SomeProperty = "Hello"; // This calls IDynamicObject.SetMember
Console.WriteLine(myObject.SomeProperty); // This calls IDynamicObject.GetMember
myObject.RunSomething(); // This calls IDynamicObject.Invoke

This means that we can implement our own behavior for the dynamic invocation! let’s see what we can do with that…

What can I do with that?

If we implement our own IDynamicObject, we can ease the pain of various daily operations. For example, we can develop an IDynamicObject that will give us the ability to use un-typed datasets as if they were typed. Another example can be an implementation that will enable us to dot through an xml file, with no need of XmlDocument, xpath and their friends. I’m sure there are tons of other uses that can and will be implemented.

Sample IDynamicObject implementation – Working with un-typed datasets

The first thing we’ll do is to create an extension method to the System.Data.DataSet class:

public static class Extensions
{
public static dynamic AsDynamic(this DataSet dataSet)
{
return new DataSetDynamicCaller(dataSet);
}
}
When we call DataSet.AsDynamic(), we’ll receive a DataSetDynamicCaller class in return, as a dynamic type object. 

Now what we need to do, is to generate classes that dynamically access the dataset objects. This is a very easy process as you will see in just a moment.

So let’s create the DataSetDynamicCaller class:

public class DataSetDynamicCaller : DynamicObject
{
DataSet dataset;

public DataSetDynamicCaller(DataSet dataset)
{
this.dataset = dataset;
}

public override object GetMember(System.Scripting.Actions.GetMemberAction info)
{
return new dataset.Tables[info.Name];
}
}

This is it… Now to the explanation…

Firstly, I inherit from DynamicObject – this is the basic implementation to the IDynamicObject interface (download link is at the end of the post). As I understand, the DynamicObject class will be a part of the System.Dynamic namespace in C# 4, so you won’t need this file on the final version. I won’t deep dive into this implementation, it’s a subject to another post.

Secondly, The DataSetDynamicCaller class is very simple – we get the untyped dataset in the constructor and save it in a private member. Then, whenever the user asks for a property, we return a DataTable that matches the name of the requested member.
This will give us the ability to call a table directly. For example:

DataSet ds = new DataSet();
ds.Tables.Add("MyTable");

dynamic dynDS = ds.AsDynamic();

DataTable tbl = dynDS.MyTable; // This will work!

It’s as simple as that!

I attach the class I’ve written (the link is at the end of the post). The sample contains two more classes and enables you to use the un-typed dataset even more easily. For instance, calling dynDS.MyTable.GetRow(0).MyColumn will return the value of the MyColumn column from the first row of the MyTable table…

In conclusion, the IDynamicObject interface opens a large amount of possibilities for improving our everyday work in a lot of aspects. It starts from accessing untyped datasets as if they were typed and ends where your imaginations does. This is what they mean when they say dynamic capabilities!

image

Downloads:
DynamicObject.cs
DynamicDataSet.cs

All the best,
Shay.

kick it on DotNetKicks.com
Shout it

Posted by shayf | with no comments
תגים:,

IronRuby Code Repository Changes

Starting from today, you will not get new updates from the IronRuby SVN code repository. The repository has been moved to github, and SubVersion has been replaced with Git.

If you want the source code, you’d need to adjust your code with the new changes.

If you don’t need the code, only the builds, you can now download the latest 0.2 version as a zip file (that contains the needed DLLs and batch files). Soon enough you’ll be able to download daily builds as well – so the need for the source code reduces or even disappears for those who only wish to work with IronRuby.

The 0.2 version, the daily builds (coming soon) and the links to the Git repository can be found on the download page at: http://www.ironruby.net/Download.

All the best,
Shay.

Posted by shayf | with no comments
תגים:,

IronRuby.net Was Recently Updated With a Brand New IronRuby Logo!

The IronRuby.net site (the official IronRuby site) has recently changed it layout from a kind of childish layout to a slicker one.  The new layout comes with a new IronRuby logo! here it is:

ironrubylogoIt’s a nice and simple logo – stays true to its roots :)

Some other updates to the site – the Roadmap page has been updated and it now contains the “must-have” and “nice-to-have” items for the first release of IronRuby. Quite an interesting list, worth a look.

 

All the best,
Shay.

Posted by shayf
תגים:,

IronRuby Tip: Ruby String and ClrString

When you use IronRuby to execute some C# code, for example, and the C# code returns a string, pay  IronRuby Tip: Ruby String and ClrStringattention that the string is not a Ruby string!
The type of the object you receive is ClrString. ClrString is the equivalent of System.String in IronRuby, all the System.String methods will work on ClrString objects, but Ruby’s string methods will not (and vice versa).

For example:

clr_string = MyCSharpNameSpace::MyClass.ReturnString()

clr_string.IndexOf("something") # This will work
clr_string.EndsWith("something") # This will work

clr_string[0..2] # This will NOT work
clr_string.index("something") # This will NOT work

As you can see, the System.String methods work but the Ruby string methods don’t.

What to do?

If you want to use a System.String as a Ruby string, all you have to do is call to_s! just like that:

clr_string = MyCSharpNameSpace::MyClass.ReturnString()

clr_string = clr_string.to_s # Converting the ClrString to a Ruby string

clr_string[0..2] # This will WORK!
clr_string.index("something") # This will WORK!

Just to make clear – you will not be able to use System.String methods after the conversion to a Ruby string… One language at a time, folks, one language at a time :)

All the best,
Shay.

Posted by shayf | 3 comment(s)
תגים:, ,

A New Name for a New Year!

Hi all!Happy new year!

I’ve decided to change the name of my blog and its layout – a refreshment for the new year.

From now the blog is named… … tam tam tam… … IronShay!

The new name also indicates the new main focus of my blog – dynamic languages in the .Net world. My target is to keep you up-to-date with the latest news, code snippets, tips and more!

So I wish you all a happy, peaceful, successful and great new year!
Shay.

Posted by shayf | with no comments
תגים: