Ironing code, geek t-shirts and even presentations!


Visual Studio Tip: Compilation Symbols

There are times when we need to use different code statements for different build configurations – this means that some code will not exist in assemblies that are built in certain build configurations.

Compilation symbols come to help in this case. You can set a symbol that will exist in  a specific build configuration and then use it inside your code files to write or exclude code when this project is built using this build configuration.

The most familiar case of this scenario is debug and release build configurations. Actually, the debug build configurations comes with a compilation symbol by default named DEBUG. By using it you can write code that will run only when you compile your project in debug mode (show extra message boxes, write more logs, etc.).

Creating Compilation Symbols

  1. In Visual Studio, go to Project-> <project name> Properties…
  2. The project properties view will open. Click on “Build” on the left.
  3. The Build settings will open on the right. The first field there, with the label “Conditional compilation symbols” is the one you need.
  4. Add there the name or names (semi-colon separated) of the compilation symbols you want to define. Pay attention that the naming convention for these symbols is all uppercase.
  5. Save

You’re done. You can start using the compilation symbols you have just  defined. The next screenshot contains a sample project with two symbols defined – SHAY and FRIEDMAN:

IronShay | Compilation Symbols

Using Compilation Symbols

In order to use the compilation symbols you have defined, you need to use the special compilation conditions. If these conditions are not met, the code within the condition will not be compiled at all.

The condition starts with #if <condition> and ends with #endif. For example, the next code will be compiled only when SHAY is defined (which is in debug build configuration):

#if SHAY

Console.WriteLine("SHAY is defined! woot!");


You can also write more complicated conditions like !SHAY for all build configuration without SHAY defined. You can add conditions too – SHAY && FRIEDMAN.

Well, that’s about it!
Hope it helps,

kick it on

My Presentation at the Nes Ziona User Group

Yesterday I did a presentation at the Nes Ziona user group. My session was about IronRuby and my main goal was to show the audience what they can do with IronRuby in their everyday .Net work.

First of all, thanks everyone for coming! I had a lot of fun!

I discussed the following subjects:

  • Creating internal tools and POCs with IronRuby – taking advantage of the Ruby language abilities and libraries to write code faster.
  • Using Ruby REPL abilities in .Net apps – can be used for polishing, debugging and extending .Net applications.
  • Cucumber – the amazing Ruby test framework that now can help test .Net code.
  • Gestalt – oh yea!

You can download all the demos from here: (4.82Mb)
I didn’t have any slides, so no ppt this time!

Some resources to get you started:

If you have any questions, suggestions, complaints, consulting needs or whatever, don’t hesitate to contact me (also via twitter)!

Thanks for attending!

Upcoming Session: IronRuby on the Nes Ziona User Group

It’s time for another session about IronRuby!


The Nes Ziona user group, HP Indigo Offices – Scientific Park – 20 Einstein St. Nes Ziona.

Nes Ziona!


Tuesday, 13-October-2009, 17:00 – 20:15


The session will be separated into two parts – the first one will be passed by Vitaly Kushner who works with Ruby everyday in the company Astrails. Vitaly will introduce Ruby to you – syntax, Ruby on Rails and general coolness. On the second part (starting from 19:00) I will take everything Vitaly has told you about and bring it to the .Net world. I will introduce you IronRuby (shortly) and then move forward to explain you how you can use it in your everyday work in order to enhance yours and your team development life.


Because IronRuby rocks and I really believe it can help any one of you in your everyday work.


Register at:
there’ll be food and drinks for free!!!

Hope to see you there!

.Net Developers Hear Me Out! IronRuby is IN DA HOUSE!

Everywhere I go and preach about IronRuby I come across .Net devs who don’t understand what’s in it for them. This time I’ve decided to take action and tell you all about what’s in it for you and why you should be as excited as I am about the upcoming IronRuby 1.0.

This post is written as a conversation between me and my imaginary .Net developer friend (don’t you have one too?). Enjoy!

Friend: Hey Shay, what is this IronRuby that you can’t stop talking about?

Me: Oh imaginary friend, finally you’re being productive! well, IronRuby is Microsoft’s implementation of the Ruby language which runs on top of the DLR. Its unique power, comparing to other Ruby implementations (MRI, JRuby…), is its ability to interop with .Net assemblies with ease.

Friend: So is it an entire new language?

Me: Ruby isn’t a new language, it’s been around since 1996. However, it is a new language for the .Net framework. It is the first time for Ruby to be a fully .Net language. As a result of IronRuby being a .Net language, just like you can run VB.Net from C# and C# from VB.Net, you can run C# from IronRuby and vice versa.

Friend: Why did Microsoft choose Ruby from all the languages out there?

Me: First of all, Ruby rocks! secondly, along with the development of the Dynamic Language Runtime (DLR), Microsoft decided to develop .Net implementations of Ruby and Python. These languages appear in the top 10 of programming languages (look here) and with these .Net implementations, Microsoft will open its doors to thousands of developers worldwide, who until now had no reason to take a look at the .Net framework.

Friend: What’s in it for Ruby developers? Why would they want to use IronRuby?

Me: For Ruby devs, using IronRuby means that they can use .Net framework frameworks like WCF, WPF, ASP.Net MVC, Silverlight and others. Even though there are many libraries and frameworks available in Ruby, Microsoft does have some killer frameworks which are hard to find elsewhere like Silverlight. Another advantage is the possibility to use Microsoft infrastructure. For example, running Ruby on Rails on IIS.

Friend: Ok, so if I want to use IronRuby, I need to learn Ruby, right?

Me: Correct.

Friend: But I don’t know the language!

Me: Just like many other .Net developers, you will need to learn the Ruby language in order to write IronRuby code. Do NOT be afraid. Ruby is an easy language to learn and I promise you that learning it will open your eyes to a whole new world (which might amaze you, beware!). When I was learning Ruby I was surprised time after time about its syntax and the fun feeling you have while coding. Moreover, learning another programming language is a good practice to increase your knowledge of programming in general (read my other post about how to increase code quality).

Friend: Assuming I have learned Ruby, the company I work for will never abandon C#/VB.Net for IronRuby.

Me: I agree, I don’t believe companies will stop using C# and start coding in IronRuby. It isn’t gonna happen. However, when companies realize the benefits of using IronRuby in different scenarios, you will start seeing IronRuby code over there.

Friend: How can a company benefit from using IronRuby?

Me: A lot. As I said, I don’t expect companies to change their core code to IronRuby. There’s no reason to do that. But, there are several other areas where you can use IronRuby – tests, POCs, automation, internal tools and more.

Friend: How can IronRuby improve my tests?

Me: IronRuby has incredible test frameworks. For me, Cucumber is a killer test framework. It’s one of the most brilliant frameworks I’ve run into. To make it possible for QA and product managers to write specs in a human-readable syntax and run them as tests afterwards is just astonishing. Ruby has other great and widely-used test frameworks like RSpec and even web test frameworks like Watir.

Friend: Sounds pretty promising I must say. And why did you say it was good for POCs?

Me: Ruby is a language that enables you to write code fast. This is why writing a POC in IronRuby will take less time to develop. Remember that when you develop in IronRuby, everything is a CLR object so it is almost like writing C#/VB.Net code. Once the IronRuby POC is done and the feature goes into production development, transferring the IronRuby code to C#/VB.Net is very easy (SharpDeveloper even has a feature that does the conversion automatically). Same goes for internal tools – you write the tools faster and continue with your other tasks (look at my first ever IronRuby post where I was excited how easy and fast it was to write a tool I needed) . By the way, writing in a different language from time to time can also be a breeze of fresh air and a great routine breaker.

Friend: Great! and what about automation?

Me: Ruby has Rake which is similar to Nant in concept, just uses Ruby syntax. Once you know Ruby, there is not need to learn Nant as well… just use Rake.

Friend: You make faces like there is more. Is there?

Me: Yes! Except all the great Ruby stuff, you can also use IronRuby from your static language code. This is great because it lets you extend your application in a very easy way (take a look at my post about the subject). Another thing, the DLR along with Silverlight gives client scripting a whole new life and makes it bearable (which is not an easy task at all). Take a look at the amazing Gestalt project for more about that.

Friend: Now let’s say I write something in IronRuby. How do I deploy it? is it hard?

Me: The deployment is a matter of seconds. It is actually just copy and paste. All you need in order to run IronRuby on a different machine is to copy the Dlls there.

Friend: Nice! Well, I’ve waited till now and here is the million dollar question – can I write IronRuby inside Visual Studio?

Me: Well, in the meantime - no. There is a voting going on to convince Microsoft to do that ASAP. However, there are some great Ruby IDEs (like NetBeans, RubyMine, SciTE and more) that you can use. There is also the Ruby-in-Steel Visual Studio addin which makes it possible to work on Ruby files inside Visual Studio (it doesn’t work with IronRuby yet, but it is included in their plans). These IDEs do not have the intellisense that you are used to in VS and C#, but they are good for the job. I must say, once you get familiar with the language, you don’t need intellisense anymore. Really.

Friend: You got me convinced! I want to start IronRubying!!!

Me: Awesome! You can start with and download the latest IronRuby version from there. If you have any questions, make sure to check the IronRuby mailing list or contact me and I’ll do my best to help. By the way, IronRuby is currently in version 0.9.1 and will advance to version 1.0 in the next couple of months.

Friend: Thanks Shay! now I see what IronRuby gives me and I’m willing to give it a try!

Me: Glad I could help! see ya!

Readers, do you have any questions? post them as comments and I’ll address them as soon as I can.

Enjoy IronRubying!

kick it on Shout it

IronRuby Tip: Using Generic CLR Methods from IronRuby

A while ago I wrote a post about using Generic CLR classes from IronRuby. This time I’ll share with you its less intuitive friend – using generic CLR methods from IronRuby.

As a result of Ruby being a duck-typed language which works with types implicitly, generics is not really needed. The whole language is generic… This is why using generic CLR types might become a bit odd for the language. Nonetheless, this fact will not stop us. The price to pay in order to enjoy Ruby in the .Net framework is worth it! :)

Anyway, assuming we have the following C# class defined in file sample.dll:

namespace ClassLibrary1
    public class Class1
        public string Test<T>(T param)
                return param.ToString();

In order to use it with a specific type, you need to do two things – get the generic method object (by using the method method) and provide it with the type via the special of method. For example, the next code invokes Test with a string and pass it “Shay Friedman”:

require "sample.dll"

sample =
sample.method(:test).of(String).call("Shay Friedman") # returns "Shay Friedman"

And that’s all there is to know.

All the best,

Configuring SciTE to Run IronRuby

I talked with Ariel today and recommended him my favorite Ruby editor for small scripts and apps – SciTE.

The nice thing about SciTE is the ability to run your script file from the application via the F5 key. Since we were talking about IronRuby, SciTE gave us good syntax highlighting and auto-completion features, but we couldn’t execute our code on the IronRuby interpreter.

BUT… this is a problem of the past now! with a few simple steps, you can turn your SciTE environment to an IronRuby stupendous development environment! or at least make it use the IronRuby interpreter…

Now, to the job:

  1. Open SciTE.
  2. Go to Options->Open
    Running IronRuby via SciTE Step 1
  3. A file with a lot of settings will be opened inside the editor window. Look for the text “ruby $(FileNameExt)” (I have it on line  108 and  116).
  4. Change “ruby $(FileNameExt)” to “ir $(FileNameExt)” on both places (if you’re on Windows, changing the first one will be enough):
    Running IronRuby via SciTE Step 2
    Pay attention that there is the rbw line (look at line 110 on the image). I haven’t changed it because it’s not that common to use rbw files and also IronRuby doesn’t have the option as far as I know… I just left it there to use the regular MRI interpreter.
    If you want to make sure that every Ruby file on SciTE environment is run via IronRuby, change “rubyw $(FileNameExt)” to “ir $(FileNameExt)” as well.
  5. Note
    You must  have ir.exe defined in your PATH environment variable in order for this to work.  It is a good practice to do that, but if you don’t want to, just write the full path to ir.exe instead of just “ir”.
  6. Save the file.

That’s it, your’re done! now go and create an rb file and hit F5. IronRuby will run your script now.

Running IronRuby via SciTE Step 3


My Presentation at the AltNetCrossGroup in London

I had the honor to be the first speaker of the cross language talks in altnet London group.

I really had a great time – the people were great, the MRM office was awesome (even though Kevin might think otherwise :) ) and most of the demos worked smoothly. Microsoft organized Pizzas and beer and the atmosphere was just incredible. Special thanks for Seb, Neil and MRM for making this happen.

And there was a talk too! I talked about Ruby, IronRuby, Cucumber and Ruby on Rails. I really tried to bring some real-world demos that you can take with you and implement right away. Hopefully, you will.

If you have any questions, requests, comments, notes or whatever don’t hesitate to contact me.

So, to those who came and to those who didn’t make it, here are the slides and demo files:

Some pics from the event (click to open a higher resolution version):

Talking… pegs, cucumbers…
Starting with a story about clothes pegs Introducing the Cucumber framework

When you drink and present, you get huge exceptions…
Beers are NOT good for demos

Audience! Thanks  for coming!
The session attendants #1 The session attendants #1

At the end of the session with Neil:
End of the session with Neil Robbins

Hope you enjoyed it as much as I did,

Upcoming Session: IronRuby on the AltNetCrossGroup in London

Announcement!  Announcement!  Announcement! 

I’m coming to London this Friday and I’m going to do a session about IronRuby on the AltNetCrossGroup!

IronRuby Session on AltNetCrossGroup

The session will take place in MRM London (76 Southwark Street) on Friday, September 25th, between 18:30 and 20:30.
The agenda is:

  • Introduction to the Ruby language
  • IronRuby – using CLR objects from IronRuby and using IronRuby from C#
  • Cucumber – test your code with style
  • Ruby on Rails

This is the current plan. If you have ideas or requests, please let me know (via the contact page or twitter)!

Register here:
If you’re interested, make sure to register ASAP since the amount of seats is limited.

I am very excited to be the first speaker on the AltNetGroup series of cross language talks and I hope to see you there!

IronRuby Tip: Data Binding Silverlight Elements to IronRuby Objects

When I was playing around with Silverlight and IronRuby, I ran into a problem with data binding and IronRuby objects. This post is to let you know about it and hand you the workaround as well.

The Problem

You have an IronRuby class. You fill it with data and set it as the data context of your Silverlight element.
The result: the values are not presented on the Silverlight page.

Detailed steps to reproduce:

1. Create an IronRuby class. For example:

class Person
  attr_accessor :full_name
  def initialize(full_name)
    self.full_name = full_name

2. Create an instance of that class and set it as the data_context of an element:

shay = "Shay Friedman"
@root.data_context = shay

3. Set the element to present the data:

  <TextBlock>You name  is </TextBlock>
  <TextBlock Text="{Binding full_name}"/>

4. Run the page – nothing is shown.


The Reason

With the help of Jimmy Schementi I’ve figured out what the problem was. Silverlight 3.0 elements can only do reflection-based data binding. IronRuby objects are based on ICustomTypeDesciptor, which means that the attributes cannot be read using reflection. Bummer.

The Workaround

Instead of using an IronRuby class, use a CLR class. This means that in order to make it work, the work flow should be as follows:

1. Create a C#/VB.Net class. For example (assume this appears in “person.dll”):

class Person
  public string FullName { get; set; }
  public Person(string fullName)
    FullName = fullName;

2. Create an instance of that class in IronRuby and set it as the data_context of an element:

require "person.dll"
shay ="Shay Friedman")
@root.data_context = shay

3. Set the element to present the data:

  <TextBlock>You name  is </TextBlock>
  <TextBlock Text="{Binding FullName}"/>

4. Run the page – everything works as expected.

All the best,

How to Increase Code Quality

A while ago we decided on my team that we needed to increase our code quality. We were excited about that and thrilled to get it started with.
Then we looked at each other eyes, saw the passion to write better code but… something was missing!

How to Increase Code Quality -

When you think about it – how do you write better code? how do you increase your code quality?

With the help of the great people on StackOverflow, I managed to gather a list of principles that can take your code to the next level:


Learn how and write write write tests! you don’t have to go for TDD, but remember to test your code  and make sure it runs as  it is expected to before it leaves the dev environment. Tests include unit and regression tests.
You can use NUnit, TypeMock  for .Net languages or other testing frameworks (every language has some).

Code Reviews

Allow other developers to go through your code before you’re done with it; You and them will learn from that.
There are tools to help you with the code review process like Crucible.
I must say it’s magic! we implemented that on our team immediately (no tools currently, we just sit with each other) and several bugs have already been prevented because of that in only a few weeks!


Agree on coding standards and stick with them. This will help you understand other developers' code, reduce different code blocks that handle for the same issues and prevent bugs eventually.
Standards include:

  • Coding standards – naming conventions for example.
  • Exception handling standards – how to handle exceptions throughout the application.
  • Logging standards - how and when to write log entries.
  • Whatever you and your team decides on.

You can enforce standards with third party tools like: FxCop, StyleCop or Code Style Enforcer.

Use Tools to Help you Code Better

Like Resharper.

Design Reviews

Design before you start coding and get your design reviewed before implementing it.

Read Related Books

Like Code Complete: A Practical Handbook of Software Construction or other books.

Talk and Meet with your Team

Talking makes wonders. Talk with your colleagues frequently and schedule a weekly meeting where every developer presents one interesting or important piece of code he/she have written during the week.


  • Try to simplify the problem as much as you can.
  • Try to break the code into small and well defined functional units (folders, files, namespaces, classes, methods) to keep the codebase logically organized and well structured.
  • Document the code. Document it so your colleagues will understand it without your help.

Source Control

Work with a source control system like SubVersion, CVS, Git, Team System or others.

Learn Other Languages

Even if those languages are not appropriate for your production code, you can find ideas in them and you can build your own internal tools with those languages.
My recommendation - learn IronRuby!

Own a Build Machine

A continous integration machine which automates the build process is a life saver. It can automatically build the application after every commit (or whenever you tell it to), run unit tests and create a setup project that people can immidiately go and install. It saves so much time! it also saves you from hitting your head against the wall when doing these repeating tasks youself.
Look here for a list of continuos integration applications.

I liked what Mark has written so I'm going to finish with that: "Quality is Free -- quality is conformance to specification and is built-in, not bolted on".

All the best,

kick it on

Shout it