“I'm not afraid of failing; that's the only way to reach success.” - Nuno Peralta

My Experience and Opinion of C#

I've been working in some projects using C#, because it is a pretty simple language to make Windows Forms tools, and has a lot of potential. It is a typed language, Object-Oriented, very similar to Java, easy to learn, and builds compiled EXE files. It was a novelty to me and I enjoyed learning it. Everything seemed perfect in the begin, until I decided to commercialize the tools I’ve been developing.

The first problem I found is that C# is not compiled into native code, like C++ is. This means that the variables, classes and methods names are preserved, meaning that if you disassemble the EXE file, you’ll be able to reproduce the code exactly as it was before the compilation, except that comments won’t be there. Anyone, even with no much programming skills, can understand the code (if it is clean), make some changes and recompile it again. However, there is a solution to this. There are several tools that can make changes directly to the EXE file, obfuscating your code completely. Some can also sign your executable file so that it may prevent cracking (not literally, nothing is perfect). If you try to decompile at this time, all the classes, instructions and everything will be completely messed up, so you can’t understand it at all yourself. But, the tool will still run perfectly, as it was running before. So, once you make it to automatically obfuscate and protect your code at this time of building, this won’t be a problem to you at all.

The second problem is, the tools you make in C# depend totally in the .NET Framework you target. C# code is compiled into CIL code which is a platform-independent instruction set, and runs in the CLR, virtual machine component of .NET Framework. If you target .NET Framework 4.5, the users will need that version of .NET Framework to run your program properly. This is bad, and will potentially decrease the amount of users running your tool, because no one likes to be required to download and install a big dependency, just to run a program of a few kilobytes that is commercial. This can be fixed, once you inject the whole Framework in your EXE file. If you do this, your program of just a few Kb becomes a very large file. It makes no sense to have a huge file just for a tool that doesn’t really do much. So, this is not the solution at all. A partial workaround is to target .NET Framework 2.0, so that you have the largest compatible population. This version of Framework works in Windows XP, Vista, 7 and 8. All, except XP, have this Framework installed by default. For XP users, you may tell them that if the tool doesn’t work, they should install .NET Framework 4.0. Note that you shouldn’t link them to 4.5, because .NET Framework 4.5 is not compatible with Windows XP. Another downside of this entire thing.

If you want a real solution to this, just develop in C++ and leave C#. However, be prepared to spend more time in fixing compilation errors than developing something new. It complicates what is easy and slows down any developer. Complains about everything. Even Facebook said this is one of the reasons they kept developing in PHP and developed HipHop for PHP, which compiles PHP into C++. Unfortunately, there are no compilers from C# to C++ or native code. Actually, I found and tried one, but, after the code migration, you need to make some changes to fix stuff. That is not really good, if you want to keep developing and improving the tool in the future. It is sad that we must develop in a hard and complex language if we want to make a client program without the issues I referred. This makes no sense to me... it seems computers aren't that improved as they should be. We are in 2013.


Article written by Nuno Peralta, 2013