source code bean

I have been hacking on a project in Node.js/Express.js for some time now. I am really impressed by how fast it is to code and prototype in Node, not much gets in your way. However, there is one thing I am still struggling with, the callback model of Node.js applications. It is not that it is conceptually hard to understand or use, but i feel that it keeps me from writing clean code.

Read the rest of this entry »

11 Jan, 2012

MongoDB, C# and Mono

Posted by: Peter In: C#|Mono|NoSQL

MongoDB is one of the many free open source NoSQL databases that exist today. I wanted to try out how well the official drivers for C# worked when using Mono.

On the MongoDB web site they have pre built binaries of MongoDB for almost every platform, i grabbed the 64 bit binary for OSX. No installation is required, just unzip the file and run the “mongod” binary from the directory. There is also a binary called “mongo”, this is the mongo interactive shell which is very useful.

The C# drivers are available, both in binary form and as source, from the C# language center. To get started I fired up MonoDevelop 2.8 running on Mono 2.10.8:



MonoDevelop has matured a lot since I used it the first time. It is still not as good as Visual Studio, but it is getting there. What takes most time to get used to is the totally different set of shortcuts, and the lack of all ReSharper magic.

Let me break down a simple console application example on how to use MongoDB using the official driver from 10gen: Read the rest of this entry »

This week I attended a tech talk about cloud computing and more in general about Microsoft Azure. It got me thinking a bit regarding PaaS vs IaaS (= virtual servers). Let me give you my thoughts.

PaaS – The good

No servers

You do not have to deal with servers, virtual or physical. You work with resources.

No software upgrades

No OS of software upgrades.

Easy scaling

Scaling your infrastructure is already taken care of for you. You just need to make sure you follow the guide lines for developing scaleable applications on that platform.

PaaS – The bad

Limits your software stack

You might not be able to pick the best suited application server/web server/caching solution/database/other great software for your application. You are often limited in some way to what is provided by the PaaS.

Portability and lock in

Several of the PaaS solutions today require you to develop for that platform, for example Microsoft Azure and Google AppEngine. If you want to move your application anywhere else, you are out of luck. There is only one provider – so then you will have to rewrite your application (or at least parts of it), to be able to run it somewhere else. If you are using services provided by the PaaS that is not available somewhere else, for example Azure SQL Server or Googles Bigtable database, it might get even harder.

Pricing can be confusing

Can be hard to estimate how much running your application will cost. Microsoft Azure is a good example of a confusing price model.

IaaS – The good

Flexibility

Full control over your software stack, if you want to switch to a more cutting edge web server or cashing solution, go ahead.

Portability

If you need, it is easy to move to another provider of IaaS, to a private cloud or even to physical servers.

Easier to estimate your cost

Most PaaS you pay per computing hour of each virtual server, per GB of stored and transfered data.

IaaS – The bad

Administration

You will need sysadmins to manage your servers, just like normal physical servers

Scaling

You will have to build a scaling infrastructure on your own.

 

Conclusion

The PaaS idea is great, but it means giving up too much control and flexibility over your application, and what is worst - it locks you into a provider. I know that Microsoft is working towards enabling private Azure hosting, this would allow you to host your Azure application in your private company Azure cloud, or with Microsoft, or other providers. I hope other providers move in this direction as well. Private PaaS hosting would allow us to develop our application and run it anywhere, but with IaaS we can already do this today!

To conclude things, I might be old school, but I still prefer IaaS to PaaS.

07 Dec, 2011

String interning in C#

Posted by: Peter In: .NET|C#

Last week a coworker sent me an interesting piece of code:

  1.  
  2. const string a = "";
  3. const string b = "";
  4. const string c = "hello";
  5. const string d = "hello";
  6.  
  7. Console.WriteLine(ReferenceEquals(string.Empty, string.Empty)
  8.   ? "Not so surprising…"
  9.   : "Oh, the humanity!");
  10.  
  11. Console.WriteLine(ReferenceEquals(a, string.Empty)
  12.   ? "But I thought string was a reference type!"
  13.   : "Seems fair…");
  14.  
  15. Console.WriteLine(ReferenceEquals(a, b)
  16.   ? " But I thought string was a reference type!"
  17.   : " Seems fair…");
  18.  
  19. Console.WriteLine(ReferenceEquals(c, d)
  20.   ? " But I thought string was a reference type!"
  21.   : " Seems fair…");
  22.  

Running the program will, maybe a bit surprising, produce:

Not so surprising…
But I thought string was a reference type!
But I thought string was a reference type!
But I thought string was a reference type!

The reason to this is what is called String interning. The CLR basically holds a hashmap of all the strings in the program (edit: string literals), one entry per unique string. So two identical strings will always have the same reference even though they are defined in different places. String interning is mainly used to speed up string comparisons (no need to check char by char if they are identical, if they have the same reference they are equal), but also to reduce the memory footprint of the application.

Read more about string interning:
http://aspadvice.com/blogs/from_net_geeks_desk/archive/2008/12/25/String-Interning-in-C_2300_.aspx
http://en.wikipedia.org/wiki/String_interning

27 Nov, 2011

Migrating from WordPress to Orchard CMS

Posted by: Peter In: ASP.NET

I have been working on migrating one of my WordPress sites to a .NET CMS called Orchard. WordPress is great for blogging, but when it comes to extending the functionality, i much rather work with a .NET based CMS then WordPress. Orchard CMS is based on ASP.NET MVC3, Razor, NHibernate and a lot of other .NET goodies.

Read the rest of this entry »

I have been playing around a little with Reactive Extensions for javascript and must say that I am really impressed. RxJS a port of the .NET based version which is, as they describe it on their site, “a library to compose asynchronous and event-based programs using observable collections and LINQ-style query operators.“. So what does this mean? Let me give you an example.

Read the rest of this entry »

07 Oct, 2011

Updated version of SignalRChat

Posted by: Peter In: Uncategorized

Yesterday I uploaded a slightly updated version of the test application I have built using SignalR. Besides from looking much better, it now uses the high level Hubs API (instead of the connection API) that SignalR provides.

You find it here: http://signalrchat.apphb.com/

And you can find the source on GitHub: http://github.com/moberg/SignalRChat

26 Sep, 2011

SignalR – Real time web for .NET

Posted by: Peter In: .NET|Web

SignalR is a library for .NET to help build real time web applications, in a way it is quite similar to Socket.IO on Node.js. It consists of three main parts:

  • SignalR.Server – .NET code running on IIS
  • SignalR.Js – A SignalR client in javascript
  • SignalR.Client – A SignalR client in .NET. Useful for communicating with a SignalR server from, for example, a Windows Phone application.

SignalR is using long polling as a method to keep its http connections open. In the future support for WebSockets is going to be added as well (a guess would be when .NET 4.5/IIS8 is released, it will have support for WebSockets).

Let me show you how simple it is to create a chat server. First start Visual Studio and create a ASP.NET MVC3 application. When you have created your project you want to add SignalR from NuGet, so open up the NuGet manager and search for SignalR. You need the SignalR.Server and SignalR.Js packages.

Read the rest of this entry »

02 Aug, 2011

My first Google Chrome Extension – E24.se cleanup

Posted by: Peter In: Web

Occasionally i read the swedish news site e24.se. One thing that really annoys me about the site is the fixed banner they have on top of all the article pages. I decided to do something about it so i created a Google Chrome Extension that removes the banner, and as a bonus it also removes all the ads on the page. Enjoy:

https://chrome.google.com/webstore/detail/lffoakndkbfaoglgbnaagjglhhlapdnk?hl=sv&hc=search&hcp=main

In the early days of the web, web pages were very static in content, once the page was loaded nothing on the page would change until you reloaded it. Then came Ajax and allowed us to do partial reloads of the page. During the last few years the web has evolved even more. Today you see a lot of web applications, such as Facebook and Google+, where content is updated as you are watching the page. This has been made possible by using different techniques to keep a connection to the web server open and be able to push content from the web server to the connected clients. The main technique to allow this in web browsers today is what is called Comet.

Read the rest of this entry »


  • Joe: I think we haven't seen true PaaS offering yet in Azure. If you use a webrole you're still running on your own VM. This is still not true multi-tena
  • Joe: Great post, my sentiments exactly. Given Microsoft's involvement with node.js recently I wouldn't be surprised if Glenn Block & co are busy worki
  • Daniel Kullmann: Peter, I absolutely agree with your post. In my opinion, asynchronous method calls should be supported by the language internally, just as C# does thi

About

Welcome to source code bean! On this site I post stuff that I encounter in my job and spare time. The content is mostly related to .NET development, but my interest in techonology is very broad, so often you will find posts on totally different subjects!