Introduction and Background
Either it is Quora, or it is C# Corner or it is 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 have 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 one of the languages from the most widely used languages:
- C or C++
- Java
- 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:
- How simple and easy it would be to use this language in the program?
- What is the productivity of that language in your scenario!
- 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 would be to cover the aspects of C# programming language.
Productivity of Language
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:
- How programs are built in that language?
- How fast and reliable is it to build the project regularly?
- Is the program’s source code readable for other members on the team?
- 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 black 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 another may get well. There would be many factors that most of the programmers don’t know but talking about them, one of the geeks would stand up and raise another important point that may guide your team to walk on the correct paths to build greater applications.
Let’s talk a bit 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, of which we are interested in; C, C++, Java and C#. C++ and C# are competing with each other, whereas Java is a bit behind than C# and so on.
In the above graph, it is clear that C# is an average programming language. 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 very successful in many cases. That is why, in many cases, C# proves to be the valid candidate 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 of the 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 would always help you to elevate the speed of the programming of your team! But among other aspects, the most important ones are:
- What sort of project is this?
- Of course, you don’t want to use a knife to unscrew a screw.
- What are the IDE and compilation tools present?
- Even a program written in C can go wrong if compile is buggy or inefficient.
- How would your team 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.
Figure 2: Visual Studio logo
I am a huge fan of Visual Studio, and I doubt 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 IDEs, 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!
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 the similar field that you are going to work in. There would be many packages and languages built for your own field that may help you to get started in no time!
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 talk 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 really a very powerful framework to build applications on. But the downside was it was tough to learn, their compilers were modified, their C++ was tinkered.
While selecting the best framework for application development by choices are below:
- How flexible a framework is?
- What language does it support?
- Some frameworks support multiple languages, like .NET Framework, it supports C#, VB.NET, Visual C++, JavaScript applications.
- Is it cross-platform?
- 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 would 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.
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 C# 6:
- String interpolation
- Getter-only auto-properties as lambdas
- 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:
- Syntax of the programming language
- The way their objects and procedures are imported in the source code
- 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 bytecoded 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 from https://attractivechaos.github.io/plb/ and see for yourself, the way bytecoded languages are similar and how much compiled languages are different, see for yourself.
Figure 6: Mathematical calculations
Figure 7: Pattern matching and machine learning
Which makes it pretty clear how much compiled languages are faster than bytecoded, and then come the ones that are interpreted, like Ruby.
In many cases, there are other factors too, which cause bad performance:
- Bad compiler
- A lot of resources being allocated
- Slow hardware resources; bad combination of CPU, RAM and other peripherals
- Bad programmer and bad code being used
- Bad practices of programming
- Keeping CPU halted for most of the times
Much more are valid candidates for the halting processes.
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 them questions and ask for their feedback. Choosing the good tools for your projects is always a good approach and a good step in the process of programming.
If your software engineer or software architect is trying to find a good solution, ask them to work on the following questions:
- 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.
- Is the programming language long lived, or a minor one?
- Is the 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 answer. “Re-write the applications”.
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 workaround 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.