Click here to Skip to main content
15,867,330 members
Articles / Programming Languages / Java

Why to Use C# and When to Prefer Other Languages?!

Rate me:
Please Sign up or sign in to vote.
4.81/5 (27 votes)
23 Mar 2016CPOL12 min read 57.9K   15   35
This article describes the way many programming languages can be selected to find that one best language for your projects!

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:

  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 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:

  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 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.

chart

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:

  1. What sort of project is this?
    • Of course, you don’t want to use a 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 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.

visual-studio-2013-logo

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!

2013-12-27-csharp-for-systems-programming

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!

top201020programming20languages-100422646-orig

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:

  1. How flexible a framework is?
  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 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.

spectrum

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:

  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 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.

plb-lang

Figure 6: Mathematical calculations

plb-lib

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:

  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

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:

  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 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.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
Pakistan Pakistan
Afzaal Ahmad Zeeshan is a computer programmer from Rabwah, Pakistan, currently living in The Netherlands, likes .NET Core and Node.js for regular everyday development. Afzaal Ahmad works at Adyen as a Developer Advocate.

He is an expert with Cloud, Mobile, and API development. Afzaal has experience with the Azure platform and likes to build cross-platform libraries/software with .NET Core. Afzaal is an Alibaba Cloud MVP, twice he has been awarded Microsoft MVP status for his community leadership in software development, four times CodeProject MVP status for technical writing and mentoring, and 4 times C# Corner MVP status in the same field.

Comments and Discussions

 
QuestionHonest Rating - good job! Pin
Jan Zumwalt4-Apr-16 6:44
Jan Zumwalt4-Apr-16 6:44 
AnswerRe: Honest Rating - good job! Pin
Afzaal Ahmad Zeeshan4-Apr-16 7:30
professionalAfzaal Ahmad Zeeshan4-Apr-16 7:30 
QuestionJavascript stats needs a relook Pin
siva_mgr28-Mar-16 4:02
siva_mgr28-Mar-16 4:02 
AnswerRe: Javascript stats needs a relook Pin
Afzaal Ahmad Zeeshan28-Mar-16 8:43
professionalAfzaal Ahmad Zeeshan28-Mar-16 8:43 
Questionchoice of language from an EE perspective. Pin
rharding6425-Mar-16 17:18
rharding6425-Mar-16 17:18 
AnswerRe: choice of language from an EE perspective. Pin
Afzaal Ahmad Zeeshan26-Mar-16 1:13
professionalAfzaal Ahmad Zeeshan26-Mar-16 1:13 
GeneralRe: choice of language from an EE perspective. Pin
rharding6426-Mar-16 18:12
rharding6426-Mar-16 18:12 
Question[My vote of 1] What language to choose?? Pin
Thornik25-Mar-16 13:40
Thornik25-Mar-16 13:40 
AnswerRe: [My vote of 1] What language to choose?? Pin
royal-roi-leroy26-Mar-16 0:44
royal-roi-leroy26-Mar-16 0:44 
AnswerRe: [My vote of 1] What language to choose?? Pin
Afzaal Ahmad Zeeshan26-Mar-16 1:07
professionalAfzaal Ahmad Zeeshan26-Mar-16 1:07 
GeneralBiased post and no references for statistics (making it harder to pull out the useful data) Pin
JayneCobb25-Mar-16 12:09
JayneCobb25-Mar-16 12:09 
GeneralRe: Biased post and no references for statistics (making it harder to pull out the useful data) Pin
royal-roi-leroy26-Mar-16 0:06
royal-roi-leroy26-Mar-16 0:06 
PraiseRe: Biased post and no references for statistics (making it harder to pull out the useful data) Pin
Afzaal Ahmad Zeeshan26-Mar-16 1:24
professionalAfzaal Ahmad Zeeshan26-Mar-16 1:24 
GeneralMy vote of 1 Pin
JayneCobb25-Mar-16 11:33
JayneCobb25-Mar-16 11:33 
GeneralRe: My vote of 1 Pin
royal-roi-leroy26-Mar-16 0:14
royal-roi-leroy26-Mar-16 0:14 
GeneralRe: My vote of 1 Pin
royal-roi-leroy26-Mar-16 0:34
royal-roi-leroy26-Mar-16 0:34 
QuestionC# is the best programming language ever built Pin
Alexey KK25-Mar-16 8:14
professionalAlexey KK25-Mar-16 8:14 
AnswerRe: C# is the best programming language ever built Pin
Afzaal Ahmad Zeeshan26-Mar-16 1:02
professionalAfzaal Ahmad Zeeshan26-Mar-16 1:02 
GeneralRe: C# is the best programming language ever built Pin
Alexey KK26-Mar-16 2:15
professionalAlexey KK26-Mar-16 2:15 
QuestionIDE Pin
michaelbarb25-Mar-16 6:27
michaelbarb25-Mar-16 6:27 
AnswerRe: IDE Pin
Afzaal Ahmad Zeeshan25-Mar-16 6:52
professionalAfzaal Ahmad Zeeshan25-Mar-16 6:52 
GeneralRe: IDE Pin
michaelbarb25-Mar-16 8:22
michaelbarb25-Mar-16 8:22 
PraiseRe: IDE Pin
wknopf25-Mar-16 20:17
wknopf25-Mar-16 20:17 
QuestionYou forgot Visual Basic .NET ( so my vote of 1) Pin
georani25-Mar-16 6:12
georani25-Mar-16 6:12 
AnswerRe: You forgot Visual Basic .NET ( so my vote of 1) Pin
Afzaal Ahmad Zeeshan25-Mar-16 6:54
professionalAfzaal Ahmad Zeeshan25-Mar-16 6:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.