My object database lightning talk
August 6, 2009
I just found the video of my lightning talk on object databases for .NET. It was recorded during the February 2009 ALT.NET Unconference in Stockholm.
Thanks to Petter Wigle for recording, editing and putting it up on Viddler.
Edit: I’ve been told I’m looking back at the slides projection way too much during this presentation. I agree. It’s because someone changed the settings on the laptop just before my presentation, so that I couldn’t see what slide I was on on it’s screen.
A CHM viewer for OS X
March 16, 2008
I’m toying around with Spring.NET, and since I’m using MonoDevelop on my Mac I don’t have ReSharper to automatically set my using directives. That means I have to consult some documentation to find out what namespace a certain class belongs to in the Spring.NET framework before I can use it. I don’t remember life before ReSharper being this hard.
So I decided to open up the SDK documentation, which is conveniently placed in a .chm file. Conveniently if you’re running on Windows that is. I needed some application to view the .chm file on OS X and I found two open source alternatives:
- Chmox (version 0.3). It displayed the contents annoyingly close to the window borders, and more importantly had no search function. Since I don’t want to scroll through half of the documentation to find where a certain class belongs, I had to go the next option:
- xCHM (version 1.13). It has some GUI issues that aren’t too bad, and it has a search feature. Winner by no contest, and Bob’s your uncle. Too bad Mac builds are discontinued, that’s the reason I chose another version than the latest.
Problem solved, I’m back to exploring Aspect Oriented Programming in Spring.NET again.
My first Lunch & Learn
March 13, 2008
Today I was so bold as to cram all the developers on my current project (there are four of us) into a small conference room during the lunch break and show them a screencast about agile development from dnrTV while we enjoyed our food. It was a fun little experiment and I think they appreciated the initiative, but the dnrTV videos are usually one hour long which, it transpires, is a bit too much. We have short lunch breaks, okay?
Does anyone know of other good .NET related videos that we can showcase? I’m thinking of Channel 9 as well, but what more is there? I’m looking mainly for C#, ASP.NET and agile stuff like TDD and so on. And a length of 30 minutes would be soup-erb (food related pun intended).
Why I like NetBeans 6.0
December 10, 2007
Roughly a week ago, the NetBeans 6.0 IDE (originally created by Sun) was released. And boy is it amazing; it even downloaded and installed the new Ruby on Rails 2.0.1 for me when I opened it for the first time.
I’ve always felt that Visual Studio is superior to any other IDE, with Eclipse being a close runner-up. That has changed now, and the new NetBeans is my new favorite for coding in anything but .NET. Just look at the code completion for Ruby, which includes a documentation window that pops up when you highlight a class in the list.

Also the way you can start your Rails site and surf around is great, it’s just like how you do it in Visual Studio. Just press F6 and a WEBrick server fires up and a browser window opens with your site in it. So smooth it makes your favorite milkshake blush.
It is open source, free, cross-platform, provides awesome tutorials (which Eclipse does too by the way) and the installer for the Ruby version is only 19 megabytes. 19 megabytes of love. It’s so good it almost makes me want to choose Java over C#. Almost.
It’s not very fast though… but then again, neither is Ruby. And no, I’ve never understood the Ruby community hype around TextMate, or vi and Emacs for that matter. To steep a learning curve for me…
The ”as” operator in C#
December 4, 2007
I don’t know if it’s just me, but I don’t see people using the “as” operator in C# a lot when I read code. It’s a shame, because it’s really nifty. For example, you can use it like this when you retrieve something from the cache:
string s = Cache[cacheKey] as string;
if(s != null) {
return s;
}
else {
// Set s to a new value
Cache[cacheKey] = s;
return s;
}
This way you don’t have to explicitly check the type of the cache contents. If it can’t be casted, s will just contain null instead.
Behavior-Driven Development
November 23, 2007
I’ve started looking at Behavior-Driven Development (BDD) and more specifically RSpec for Ruby. BDD is an evolution of Test-Driven Development (TDD) which aims to make developers look at it from another perspective and not regard it as testing in a sense. So it’s more of a new way of expressing your intent rather than an entirely new approach to tests (or specs as the BDD community calls it).
You divide your code into small pieces of behavior, rather than the more abstract term units and write what it should do.
Here are two examples of the difference:
| NUnit (C#) | RSpec |
| Assert.AreEqual(expected, actual) | actual.should equal expected |
| Assert.IsTrue(bool) | Bool.should be_true |
Edit: I tried pasting some code I’d written here, but the wordpress editor sucks when it comes to formatting code. But you can find great examples here and here.
I just watched a video where Dave Astels (one of the guys behind RSpec) explains why you should take a look at BDD if you’re into TDD. To quote him: “Behaviour Driven Development is what you were doing already if you were doing Test Driven Development very well”. You can also read his PDF A new look at test-driven development (8 pages) where he explains his views and why too few people “really understand what it’s really about. That means that many people who practice TDD are not getting the full benefit from it”.
Which programming language is the fastest?
June 15, 2007
I recently came across The Computer Language Benchmarks Game that compares the speed of different programming languages on the Gentoo and Debian linux distributions. It’s interesting (although not super serious), but what does it say?
Firstly C and C++ are the winners on both the platforms. Then you have a whole bunch of languages listed, of which I’m mostly interested in Java, C# and Ruby. The latter two are about half as fast as C/C++ and Ruby is in the bottom of the list. Not so strange since Ruby is an interpreted scripting language. It would be interesting to know if the JIT-languages are tested when compiling for the first time, or when the code is cached in the memory for subsequent calls, since there can be a huge difference. Also, the C# code is run with Mono in the tests, and I don’t know if that has any performance implications as compared to the Microsoft .NET platform.
But my primary argument against this speed comparison is optimality. I’m sure that this argument has been made a thousand times by others, but still. The tests must have been performed on optimal code in all the languages, or else the comparisons wouldn’t have any validity at all. Then the question really is: how difficult is it to write optimal code in any of the programming languages in the test. There is a reason why there’s been an increase in high level languages and the usage of them, it’s because C/C++ makes it very easy to write bad code. How often do you have problems with memory leaks in C#? That’s right.
What I mean is that you probably don’t have to be a super programmer to write decent performing code in the higher level languages, you’d have more of a challenge doing it in C or Assembler. And apparently most developers weren’t good enough since there’s been such a shift in focus towards C#/Java. Think about Ruby on Rails for example, the active record wrapper makes it easy to quickly write some code that interacts with a database without getting horrible performance, whereas if you write the stored procedures/SQL yourself, stuff can get really messy if you’re not very good. Abstraction has good and bad sides.
I’m not being a sore loser here, I’m know that you can write really good performance code with C/C++. Just don’t accept the benchmarking tests you see without considering the circumstances.
How popular Ruby really is
June 7, 2007
In my post “The future of web development“, I wrote about the company Thoughtworks and how 40 % of their new business this year is Ruby. That doesn’t really reflect how popular Ruby is generally, now does it? Well, via a colleague of mine I’ve found a more credible source of what languages are the biggest. TIOBE Software uses search engines and some magic to calculate a monthly index which shows that Java is number 1. C# scores a measly 7th place, with a 3,4 % rating, and Ruby is on the rise, jumping from the 19th to the 10th position since June 2006, with a 2,1 % rating.
Watch the facts and figures for yourself at the TIOBE website. Too bad I can’t find a similar rating for web applications only…
Allowing web editors to add javascript in EPiServer
March 13, 2007
I haven’t got much to do right now, except for some really small and easy EPiServer thingees. This is one of them:
The customer wanted to allow the web editors to add javascript in the Edit Mode that was then included in the <head> of the page. Easy to do.
1. Add the following code to the header.ascx file:
<%=GetJavaScript()%>
2. Then put the following method in the code-behind file:
protected string GetJavaScript()
{
if(CurrentPage.Property.Exists("Javascript"))
{
return CurrentPage.Property["Javascript"].ToString();
}
else
{
return String.Empty;
}
}
3. Add an XHTML property called “Javascript” to any pages where you wish to have javascript.
4. Write/paste the javascript in the text box for this property. However, make sure that you paste it in the HTML edit mode, not ordinary text mode. Otherwise EPiServer will just reformat your javascript to html, which isn’t pretty.
Sending an InfoPath 2003 form to people who don’t have the client
February 7, 2007
I needed to send the completed (ie approved) form, read-only, to the company who took care of the orders made in an InfoPath 2003 form. The form is stored in a SharePoint forms library, but the receiving company didn’t have access to this SharePoint site. 2007 would be sweet, but I can’t use that. Hmmm… how to do?
I created a web service, which the form, once approved, sent an email through (all stages in the workflow before approval used the ordinary data connection to the SharePoint forms library).
The web service receives the xml document from InfoPath, via the normal web service data connection available. The web service extracts the filename (stored as a secondary data source inside the form) and makes an html document out of the xml and xsl combined, which then can be viewed on any computer with an internet browser.
There’s one big-ass downside with this though. The xsl file has to be extracted from the infopath form and then edited a little to remove not-supported functions and so on, or else you’ll se some nasty error messages when opening the form in the browser. So if the form has undergone some major changes, you need to re-extract the xsl-file and put it somewhere where the web service can access it, which in my case is in the web service root directory.
Here’s the code:
Service.cs
[WebMethod]
public string InfoPathMailer(XmlDocument xmlDoc)
{
string filename = GetFileName(xmlDoc);Stream stream = new MemoryStream();
XslCompiledTransform xslTransform = new XslCompiledTransform();
xslTransform.Load(Server.MapPath("view1.xsl"));
xslTransform.Transform(xmlDoc, null, stream);
stream.Position = 0;MailSender m = new MailSender("yourmailserver.net", "formsrobot@yourdomain.com", "receiver@company.com", "New End User Request", "Do not reply to this address", filename, stream);
m.Send(); return "";
}private string GetFileName(XmlDocument xmlDoc)
{
string infoPathNamespacePrefix = "my";
string infoPathNamespaceURI = @"http://schemas.microsoft.com/office/infopath/2003/myXSD/2006-11-13T10:36:39";
XmlNamespaceManager namespaceMngr = new XmlNamespaceManager(xmlDoc.NameTable);
namespaceMngr.AddNamespace(infoPathNamespacePrefix, infoPathNamespaceURI); XmlNode node = xmlDoc.SelectSingleNode("//my:Filename", namespaceMngr);
string s = node.InnerText;
s = s.Replace("xml", "html");
return s;
}
And here’s the code for the class MailSender:
using System;
using System.Data;
using System.Configuration;
using System.Net;
using System.Net.Mail;
using System.Net.Mime;
using System.IO;public class MailSender
{
MailMessage mail;
String smtpServer; //Constructor for attachment as stream
public MailSender(string server, string sender, string receiver, string subject, string body, string filename, Stream stream)
{
smtpServer = server;
mail = new MailMessage(sender, receiver, subject, body);
Attachment attachment = new Attachment(stream, filename, MediaTypeNames.Text.Html);
mail.Attachments.Add(attachment);
}public void Send()
{
SmtpClient client = new SmtpClient(smtpServer);
client.Credentials = CredentialCache.DefaultNetworkCredentials;
client.Send(mail);
}
}
Hopefully this can help someone out there. Good luck!