Why To Use C# And When To Prefer Other Languages

Introduction and Background

Either on Quora, C# Corner, or CodeProject, beginners and novice users are always asking questions like, “Which one to use, C++ or C#?”, and many more similar questions. It is harder to provide an answer to such questions on multiple platforms and to multiple questions. That is why, I thought, why not post a blog post to cover most of the aspects of the question?  In this post I am going to cover a few of the concepts that you may want to understand to choose either language from the most widely used languages:

  1. C or C++
  2. Java
  3. C# (or .NET framework itself)

Basically, my own preference in many cases is C#, but that depends on what I am going to build. I have been using C, C++, Java, and C # in many applications depending on their needs, depending on how they allow me to write the programs,  and depending on whether it is the suitable programming language for this type of project and application architecture.

The way I do that,is just a trick which I am going to share with you in this blog post. Among these a few of the very basic things to consider are:

  1. How simple and easy it would be to use this language in the program?
  2. What is the productivity of that language in your scenario!
  3. Difficulty level and how many people know the language!

I will be talking about these points in this post  to make it clear where to use which programming language. But my major concern in this post will be to cover the aspects of C# programming language.

Productivity of language

THE First thing to always consider about the language is the productivity that a programming language can provide your team with. Productivity of the language depends on many factors, such as:

  1. How programs are built in that language?
  2. How fast and reliable is it to build the project regularly?
  3. Is the program’s source code readable for other members on the team?
  4. Is the language itself suitable for the case that we are going to use it in.

Productivity of the language, in my opinion, is the first thing to consider as the valid candidate to always discuss in the team and not just talk about in a back room. You should manage to get your teams up in a conference room, and then talk about a language. There may be many aspects where one language may fall short and other may WORK well. There would be many factors that most of the programmers don’t know butIN  talking about them one of the geeKS WILL would stand up and raise another important point that may guide your team to walk on the correct path to build greater applications.

Let’s talk a bit about graphs.

Productivity graph
              Figure 1: Productivity graph of most widely used programming languages

In this chart we can see that C is the most productive programming language in which we are interested; C, C++, Java and C#. C++ and C# are competing with each other, whereas Java is a bit behind  C# and so on.

In the above graph, it is clear that C# is an average programming language. The average doesn’t mean it is below the requirement. But it means that it can be used in any case, and its performance won’t fall as the data increases. The successful run graph shows that C# programs are much successful in many cases. That is why, in many cases, C# proves to be the valid candidate in many cases, since it is a general purpose programming language.
Then the question arises, “Productive in which sense?

That is the most important part here. Now, this topic may take a bit more time to explain how productive a language is. For that, I have dedicated the topic, “Choosing the right language for the right task." The right programming language for the right task will always help you to elevate the speed of the programming of your team! But among other aspects, the most important ones are:

  1. What sort of project this is?

    • Of course you don’t want to use knife to unscrew a screw.
  2. What are the IDE and compilation tools present?

    • Even a program written in C can go wrong if compile is buggy or inefficient.

  3. How your team would like to manage the projects?

    • Does the language support good software engineering concepts?
    • Can it be used to generate good diagrams: Use-case, activity, class and other diagrams?

Thus, you should always consider thinking about the productivity of your development team while guessing which language to be used.

Choosing the right language for the right task

It is always stated to use the best tool for the best jobs! Then, why not use the best programming language for your projects, to get the best possible results? Before I continue any further, there is one thing I want to mention, “There is no best programming language ever built.” Every time a programming language is built for a purpose, another group of programmers jump in to create a new programming language, for the sake of fixing the errors in the previous language. What do you think motivated Bjarne to create C++ when there was C language and Scala already in the market?

In this section, there are many things to consider, from the performance and benefits to the clients, to the perk packages for the employees to the efficiencies of the project repositories and the tools provided for that programming languages.

C# was created by Microsoft and therefore, in my opinion, has, by far, the most efficient tools for programming. I mean, Visual Studio alone is the beast in this game.

Visual Studio logo
                        Figure 2: Visual Studio logo

I am a huge fan of Visual Studio, and I would doubtthere is  someone who isn’t a fan of Visual Studio. C# has a better support and benefit of using the best IDE out there. Java has also a number of IDE, so does C++ and many of the C programs are written in minimal environments, like a small program to manage and compile the C programs; no offence geeks!

Graph of performance to safety ratio
                                    Figure 3: Graph of performance to safety ratio"

Now, if you look at this graph, it’s pretty much clear as to what it is trying to guide you with. Of course, as I had mentioned in the starting paragraph here, there is no best programming language.

In many cases, C# and Java rule over C++ (and C) and in many cases, they rule over C# and Java. There are many factors, like the programming paradigms, performance of the code that is generated; Just-in-time compilation, memory-management delay and so on. While C# and Java may provide the best environment to build “managed” programs in, there are many cases where C# and java don’t work well, like writing a low-level program. Java developers wanted to build a Java OS, but they had to give up because some things aren’t meant to be done in Java.

Always consider searching before making the final call. There are many companies working in a similar field that you are going to work in. There will be many packages and languages built for your own field that may help you to get started in no time!

Top 10 programming languages
                              Figure 4: Top 10 programming languages

But, I think these are a bit backwards. I think, C is on the top because it causes a lot of trouble to beginners, so everyone is searching for “How to do {this} in C” on Google, raising the rankings.

Selecting the best framework

I don’t totally agree with people when it comes to talking about frameworks like, Java, Qt (which I do like in many cases; like Ubuntu programming), and other programming frameworks available for programming applications to be run despite the architecture of the machine. In this case, my recommendation and personal views for .NET framework are very positive. As already mentioned, I have programmed on Qt framework for Android, Ubuntu and Linux itself. It was a really very powerful framework to build applications on. But the downside was it was tough to learn, their compilers were modified, and their C++ was tinkered.

While selecting the best framework for application development my choices are below:

  1. How flexible is a framework?
  2. What language does it support?

    • Some frameworks support multiple languages, like .NET framework, it supports C#, VB.NET, Visual C++, JavaScript applications.

  3. Is it cross-platform?
  4. If not cross-platform, then does it support multiple architectures, at least?

Java framework is cross-platform, and entirely framework oriented. You simply have to target the framework despite the operating system or architecture being used. .NET framework on the other hand is a very beautiful framework to write applications on. It uses C#, VB.NET and C++ (no Java!) to write the applications, and then the compiled binaries can be executed on many machines that can support .NET framework. This provides an excellent cross-architecture support.

C# however, does not support Mac OS X, at the moment. Microsoft has started to roll out cross-platform binaries for C# programs. .NET Core has been a great success and once it gets released to a public version, I am sure most of the companies will start to target it. That is not going to happen in the near future, in which case, Java and C++ are better than C#.

If you are interested in C# programming on multiple platforms, consider using Mono Project instead. You can read about that, on my blog here: Using C# for cross-platform development.

Top languages and their platforms of usage
                              Figure 5: Top languages and their platforms of usage

Java may be supported 100% in the rankings, but C# is also supporting multiple platforms and is rapidly growing making the language better than the rest. With the release of C# 6, Microsoft has proved that the language is much better than the rest in the race. There are many features that I like in C# 6:

  1. String interpolation
  2. Getter-only auto-properties as lambdas
  3. Improvements to lambdas

There are a few things Java still doesn’t have. For example, one statement code to write the data to the files and to extract the data. You have to get messy in the streams, or you have to write an entirely non-intuitive code with Files object and then to get the data from there… Yuk!

Performance of the compiled code

Writing the source code may be different in many ways:

  1. Syntax of the programming language.
  2. The way their objects and procedures are imported in the source code.
  3. How clean the source code looks. Many programming languages are just nightmares.

But the major concern comes to mind when we are going to execute the programs. In many cases, or should I say in all the cases, the language which are byte coded languages lag behind than the languages that are compiled to native codes or Assembly codes. For example, C or C++ codes are faster, because they are not compiled to a bytecode, instead they are generated as machine codes for a platform or architecture. C# or Java programs are compiled down to a bytecode which causes a JIT to occur when the programs are executed. This takes time.

However, you can see the following charts and see for yourself, the way byte coded languages are similar and how much compiled languages are different, see for yourself.

Mathematical calculations
                                                Figure 6: Mathematical calculations

Pattern matching and machine learning
                                       Figure 7: Pattern matching and machine learning

This makes it pretty much clear how much compiled languages are faster than byte coded ones, and then come the ones that are interpreted, like Ruby.

In many cases, there are other factors too, which cause bad performance:

  1. Bad compiler.
  2. A lot of resources being allocated.
  3. Slow hardware resources; bad combination of CPU, RAM and other peripherals.
  4. Bad programmer and bad code being used.
  5. Bad practices of programming.
  6. Keeping CPU halted for most of the times.

There are more valid candidates for the halting processes.

Finally… Final words

As I have already mentioned, there is no best programming language out there. One language is best in one case, other is best in another case and so on and so forth. In such cases, it is always better to communicate with your development team and then ask those questions and ask for their feedback. Choosing good tools for your projects is always a good approach and good step in the process of programming.

If your software engineers or software architects are trying to find a good solution, ask them to work on the following questions:

  1. What are the teams and developers qualified for?

    • Asking a team of C++ programmers to leave C++ and join Java or C# programming teams is not a good idea!
    • Always consider the best approach.
    • Time is money — manage it with care.
    • Recruit more programmers with skills.

  2. Is the programming language long lived, or a minor one?

  3. Is programming language capable of making your application work?

    • I have used many programming languages, and thus I can decide which language to use. This is the job of your software architect to decide which languages to select.

If you follow these rules, you will save yourself from many of the future questions that cause a lot of problems. Many times developers ask questions like, “I have an application in Java, how to migrate it to C#?” Many web developers ask questions like, “I have a PHP application, how to convert PHP code to ASP.NET?” These questions have only one answer: “Re-write the applications.” C# won’t allow you to just convert other programs to it. C# is a powerful and easy language, learning C# won’t take much of your time. Then you can implement those programs in C# itself, Java and C# are similar in many cases. In the similar sense, you can re-write the PHP applications in ASP.NET web applications in no time at all. ASP.NET web applications are provided with templates that provide the starter code in the IDE itself, which you can use to get started.

There are many things that you should consider before designing the applications. Facebook is stuck with PHP, because it was written in PHP. Even if they wanted to migrate to ASP.NET, they won’t. Instead, they have found a work around  for the PHP bugs and downsides.

This is why, you should always consider using a conference or meeting to decide how to start the project, which programming language to use, what frameworks to target, who would lead the team and much more. These few days of discussion and designing would save you a lot of money and time in future.

Read more articles on C#:
 

Up Next
    Ebook Download
    View all
    Learn
    View all