Rambling about programming and life as a programmer

Archive for the ‘windows’ Category

Culture shock

Posted by webmat on November 16, 2007

Update: This article has has a new home on Go to the article.
Comments are closed here but still open there :-)

I had a bit of a culture shock a couple of days ago. I saw a video of the visual designer for IronRuby, named SapphireSteel. The tool looks very nice and polished.

Something unsettled me, however, when I saw it. It has nothing to do with the team or what the narrator says. In the demo, he shows us a couple of features of the designer, and inevitably we end up seeing snippets of code. That’s when the culture shock, uhh, shocked me.

I’ve seen plenty of verbose code in my time. I even work in C# right now, which I find errs on the side of verbosity. So I’m used to seeing verbose code, and I’m certainly used to see WinForms code.

But seeing this WinForms code in Ruby felt very weird.

WinForms in Ruby is Still WinForms

WinForms code in Ruby is still exactly as verbose as in C#. Only the semicolons are missing.

C# colleagues might tell me that this code just satisfies what the API wants to hear, in the way it wants to hear it. But I’m getting used really fast of the Ruby way of doing things. Which consists “sane defaults” for a start, and using DSLs to solve complex problems in a declarative manner rather than in an imperative manner.

WinForms development with Ruby screams for a Rubyish wrapper. Anybody up for that? If it can be done for Java’s Swing (with Profligacy, the Swing reducer), it can certainly be done for WinForms.

For my part, however, I’d be much more interested in exploring XAML with Ruby, but that’s another story.


Posted in programming, ruby-rails, windows | Tagged: | Leave a Comment »

JRuby, not in its setting (or configuring jirb under Windows)

Posted by webmat on October 18, 2007

Update: This article has has a new home on Go to the article.
Comments are closed here but still open there :-)

For a good while now, I’ve been using Ubuntu on my main home machine. Working with Ruby and JRuby on Linux is a charm.

Tonight, as I tried to set myself up to work with JRuby on Windows*, I bumped into an annoying problem. When I tried to configure jirb, the JRuby version of IRB, it didn’t always seem to find the .irbrc config file in my home directory. I looked a bit on the ‘net and found nothing that helped me solve my problem. I’ve worked out a fix, you can follow along in this wonderful adventure.

So to configure irb, I create the .irbrc file in my home directory.

C:\Documents and Settings\Mat\.irbrc

Note: Windows will yell at you if you try to make a new file starting with a “.” in windows explorer. Just use any good text editor to create it directly.

In it I put some configs for auto-completion and auto indent, as suggested on the Tips and Tricks page on the Rails wiki:

IRB.conf[:AUTO_INDENT] = true
IRB.conf[:USE_READLINE] = true
require 'irb/completion'
puts "Yay! Completion's loaded!" #Uhh, that's my special debugging code :-)

Now I fire up a console and start the interactive Ruby shell with

C:\Documents and Settings\Mat>jirb
Yay! Completion's loaded!

Hmmm, it works. What am I yelling about? :-) Let’s say we fire it up in an actual project directory instead.


Oops! My “special” debugging code isn’t executing now :-)

If you care to see what’s the code that hints at how to solve the problem, you can open


Or check it out a snippet of IRB.rc_file_generators online.

As we can see, if the HOME environment variable is set, the method looks for .irbrc in the directory, otherwise it looks for it in the pwd (present working directory).

Nice! That explains why it works in my home and not elsewhere :-)

So now I just have to set a HOME variable and I’m all set:


Now after restarting my console (to have the updated environment variables):

Yay! Completion's loaded!

Note that even though Windows variables are not case sensitive, you must name your HOME variable in capital letters. Ruby expects the ENV hash to contain the HOME variable in caps.

* Q: Why would I want to set this up on Windows, if I’ve got a perfectly good Linux setup at home?

A: I’ll be giving a talk about JRuby at the next Montreal on Rails, and since I haven’t really needed a laptop in at least two years, well, I only have 3 years old laptop. This old geezer can run equally old versions of Linux, but I wouldn’t like my audience to have to suffer the visually challenged distro I currently have on there.

Posted in garbage out, programming, ruby-rails, windows | Tagged: , , , | 2 Comments »

Using Windows? Try Powershell!

Posted by webmat on October 16, 2007

Update: This article has has a new home on Go to the article.
Comments are closed here but still open there :-)

Recently, at work I’ve had to implement a couple of simple scripts. They were yet again not simple enough to be captured completely in a batch file. For example I needed to have an arbitrary precision and format date/time that I could use in a file name. date /t and time /t weren’t cutting it.

I thought about implementing a small command-line tool just to give me the functionality I was missing, but it felt too patchy for my taste, this time. I had to use it on other test machines so I wanted to be able to just copy the script without having to update some executable utilities as well.

Sadly I could not use Ruby because my company doesn’t use it, and I don’t want to sneak it in the wrong way. And as I said it was to be used on another machine, so it was not like creating a personal script on my own machine. In fact it even had to be documented in a manual testing procedure.

So I decided that it was time to try Powershell. I’ve been hearing about it for quite a while now, and I heard it’s pretty powerful. Since it’s the future of Windows console/scripting anyway, I figured nobody sane at a Windows shop would yell at me for introducing this particular technology.

Now that I’ve been dabbling with it for the past few weeks, my opinion is starting to form and it goes a little bit like this. If you’re a Windows power user (especially an admin or a developer) and you don’t know Powershell, you’re at a disadvantage :-) The “Power” in Powershell is very well deserved. If you’re still flopping along using batch files, you’re using a weak, error-prone tool where a new, very powerful tool is available. It’s free and it’s by Microsoft, so there’s no reason it wouldn’t be well received in most Windows shops :-)

I decided to capture my understanding of Powershell in an introductory article. In it I explain some of the basics of the language and introduce you to all that’s necessary to get started with Powershell. In the reference section at the end I also mention other good sources of information if you want to learn more. Depending on the amount of fiddling around you do while following along, I guess it’s a 30 minutes to 2h read tops.

So without further ado, Discover Powershell (it’s an order!)

Posted in garbage out, programming, windows | Tagged: | Leave a Comment »