Monday, November 17, 2014

How does an open source .NET effect Xojo developers

As most of you know, I live in two worlds as a developer.  Yes, I develop cross-platform application but that's not the two worlds I'm talking about. Specifically, I'm talking about languages.

For most of the last decade, I've been firmly planted in the .NET work, using C# to build new systems and web applications that ran on Windows and, for the last few years, to build embedded applications for a variety of different purposes by using the .NET Micro Framework.  But that only got me part of the way there. While Microsoft describes the .NET framework as 'cross-platform', it really means 'Windows and a few platforms we officially bless' (like the .NETCF stuff I mentioned above. It did not mean Mac. It did not mean Linux (not officially, at least). So that meant that, if I really wanted to go cross-platform, I needed to look elsewhere.

For me, that elsewhere was Xojo. Xojo is a programming language that is very similar to VB.NET and strongly delivers on the promise of cross-platform. Write our code onces on either Mac, Windows, or Linux, compile it for any of the other platforms and it will run unmodified. It's the promise of Java only better. It's like having the best of both worlds: the ease of .NET combined with the cross-platform nature of Java.

As you might imagine, reading news about Microsoft open sourcing .NET gave me a reason to reflect on the future of Xojo and if I really wanted to hitch my wagon to a technology made by a small company that very well could be obsoleted within a year or two if the .NET train delivers on its promises and actually goes fully and officially cross-platform. Does the promise of working in one. heavily supported, language and ecosystem provide everything a cross-platform developer needs? Does this mean that there is a looming end in the near future for Xojo?

Absolutely not.

There are roughly three places where ,NET technologies consume Xojo nearly wholely:

1. Visual Studio - While it's technically possible to write .NET code without Visual Studio, the IDE is so good that you're a fool if you do. Visual Studio has features that cater to the needs of just about every developer and it's amazingly stable. Add to that a rich plugin ecosystem that extends the IDE and you have one of the best development environments in the industry.

Xojo, by comparison, isn't even close to being there. The IDE has performance issues on some platforms, doesn't have a rich plugin environment, and can be slow even on supported platforms. And with the announcement of the Visual Studio Community Edition (which is Visual Studio Professional, free), the Xojo IDE being a paid product adds another challenge that the company needs to address. You can develop entire solutions in .NET, using Visual Studio without paying a penny. With Xojo, you're going to pay at least $99 just to write for one single platform.

2. Stability - I'm not going to pretend that Xojo apps don't have stability problems. Xojo developers learn to compensate for those issues with a variety of tricks but, the fact remains, I would never choose Xojo for a large scale project that required rock solid reliability. My choice would always be C# and the .NET framework. Thankfully, Xojo has been laser focused on this issue lately and it's getting much better so this might not be a problem for much longer. But, still, for the time being, .NET wins on this issue.

3. Documentation - I don't think anyone can deny that MSDN has some of the best developer documentation in the industry. Xojo, by contrast, has a wiki that provides decent doc but not full. There are still some methods and technologies that the developer is left to figure out on their own with very little guidance and no examples from Xojo. This, like item 3, is getting better but it's not there yet.

Out of the three items listed above, I think items one and two present the largest challenges to Xojo's future in the face of an open sourced .NET.  Thankfully, item one can be fixed pretty easily: rewrite the IDE, focus on stability and performance on all platforms.  Sure, that will take time but it's not insurmountable.

Item 2, on the other hand, presents a larger problem for Xojo. The company behind the language has a history of moving too fast and not fixing things in a timely fashon. For example, they're hard at work on giving Xojo users the ability to write iOS apps but there are several stability issues on the desktop that have never been addressed even after multiple releases. If the language is going to compete, the company needs to change this and start to take stability seriously.  I'd love to use Xojo in enterprise app development, but I'd have to be crazy to do that right now. That needs to get better (and it is) fast.

So my final conslusion is that Xojo can compete with open sourced .NET. It's going to be a bloody battle and one where Xojo Inc is going to have to be ready to make some changes to win, but it's a battle that can be won. Xojo users are fiercely loyal. We want to believe in the company and we're willing to fight for it. That's important. Xojo Inc just needs to saddle up and go kick some ass.

Sunday, November 16, 2014

The easy way to work with JSON data in C#

A few years ago, the dominant way to exchange data between systems online was XML. XML can be a complicated and convoluted format to work with and, as with most complicated and convoluted format, it quickly fell out of favor as soon as something better came alone. That something better was a new format that was made for the web called JSON (short for JavaScript Object Notation).

JSON provides a simple, human readable, intuitive way to exchange almost any kind of data. Unlike XML, JSON data is small, easy to understand, and infinitely flexible. Best of all, working with JSON in most programming languages is amazingly simple. It's the perfect format for a modern world, populated with modern programmers.

Today, we're going to look at a topic I seem to get a lot of questions about: using JSON data in C#. Technically, JSON formatted data is called serialized and the process of turning into something you can easily work with is called deserialization. Today, we're going to look at how to deserialize JSON data. In the next article, I'll cover serializing data so that you can easily create your own web services.

First things first, C#'s native JSON parser sucks!

If you've done any research into working with JSON data in .NET, you've probably seen the built in .NET solution you know it's definitely not up to the task of everyday use. So we're going to use the open source JSON.NET library from James  King. It's an excellent library that's well supported and constantly updated. It's widely agreed that it's the best solution for working with JSON data. You can get it here.

How to deserialize JSON data in C# with JSON.NET

While there are a few ways to deserialize JSON data with JSON.NET, we're going to look specifically at what I consider the easiest way: modeling the data in a class then accessing class members as regular properties.

Let's say you have the following JSON string you want to process and you've stored it in a string variable called response:

{
    "Name" : "Tom Jones",
    "Age" : 26,
    "Spouse": "Jane Jones"
}

First, let's create a class that models the JSON data we want to process. It's amazingly easy:

public class JSONData{
    string Name {get; set;}
    int Age{get; set;}
    string Spouse{get; set;}
}

That's it. Just a getter and a setter for each JSON field we want to process. Nothing more needed. Now, let's access that data from our main class:

JSONData jData = Newtonsoft.Json.JsonConvert.DeserializeObject<JSONData> (response);

From there, we can access the different fields like this:

Console.WriteLine(JData.Name);
Console.WriteLine(JData.Age);
Console.WriteLine(JData.Spouse);

It's really that simple. Using JSON with the power of the JSON.NET library and C# makes a developers life amazingly simple! Now, there's nothing stopping you from going and grabbing data from any API on the planet.

Have fun!



Friday, November 14, 2014

Microsoft is setting .NET free and it's going to be awesome!

As most of you know, I'm a huge fan of the C# programming language.  C# is a language that retains everything that's good about C++ and Java but modernizes
things and makes actually doing things much simpler.  Unfortunately, while C# can be used on multiple platforms via the Mono project, it's not officially supported by Microsoft on any platform other than Windows.  Not only that but, in terms of features, Mono tends to lag a bit behind the "official" C# implementation because the Mono project is basically reverse engineering what Microsoft is doing and coming up with their own implementation of things.

That all changed yesterday.

Yesterday, at its annual Connect conference, Microsoft announced that it was moving forward with its plans to nearly fully open source the entirety of the .NET framework and work to enable it to run (in parity with the Windows version) on other platforms including Linux, Unix, and Mac. In addition, the company included a patent promise that says it explicitly agrees not to sue anyone using, changing, or marketing, the code. The patent promise is a huge step in promoting the adoption of .NET in the open source world since many people have been afraid to use it for fear of being sued by Microsoft. Thus, while we've had the ability to write software in .NET for years on other platforms, the promise that the technology offers has never been fully realized in the open source world because of the general distrust most people have of all things Microsoft.

Personally, I'm estatic about this move. When I was a Windows developer, my language of choice was C# and I truly came to miss it when I went full-time to Linux. With this move by Microsoft, I, and many developers like me, will once again have access to their favorite languges on whatever platform we decide to work on. This isn't just a win for developers though, it's a win for Microsoft who will, I hope, see .NET and C# simply take over the world. For the first time in over a decade, C# is a serious competitor to Java. It's always been a better language but Java has always beaten it in cross-platform. Now, the game is afoot, and Microsoft seems ready to become the tiger of development again and take on Java everywhere. I think we're about to see a bloodbath with developers, users, and Microsoft coming out the clear winners.

One of the things I'm particularly excited about is that open sourcing .NET could resolve some long standing security fears developers have had around the technology. Take the cryptography API, for example. Sure, you can easily do encryption using .NET but how secure is it? Might there be back doors that we don't know about? Open sourcing the code will close the door once and for all on those questions and could go a long way in restoring developer trust in Microsoft technology. It's certainly a bold move and I think it shows that the company is serious about competing across the spectrum.

Lastly, it should be pointed out that we won't see many of the benefits of yesterdays moves for a while. Microsoft is a big company and .NET is a huge technology with a lot of moving parts. It's going to take a few months to get everything planned out and deployed. But the company has already made moves by putting the source to the C# compiler and a lot of other parts of the .NET framework in a Github repository for anyone who wants it. That's right, you can go and download one of Microsoft's crown jewels right now and change the code or compile your own version.

Honestly, I like the new Microsoft. I think they're making all the right moves and have finally realized that the world doesn't have to revolve around Windows for them to survive, thrive. and kick ass, as a company. Now, we just need to talk about getting Visual Studio on Mac and Linux.  Too soon?