C# vs TypeScript
When comparing C# vs TypeScript, the Slant community recommends TypeScript for most people. In the question“What is the best programming language to learn first?” TypeScript is ranked 6th while C# is ranked 7th. The most important reason people chose TypeScript is:
Typescript has optional static typing with support for interfaces and generics, and intelligent type inference. It makes refactoring large codebases a breeze, and provides many more safeguards for creating stable code.
Specs
Ranked in these QuestionsQuestion Ranking
Pros
Pro .NET is a great toolbox
C# runs on top of the .NET framework, which provides many libraries containing classes used for common tasks such as connecting to the Internet, displaying a window or editing files. Unlike many other languages, you don't have to pick between a handful of libraries for every small task you want to do.
Pro Incredibly Well-Engineered Language
Where other languages invoke the feeling of being a product of organic growth over time, C# just feels like an incredibly well-designed language where everything has its purpose and almost nothing is non-essential.
Pro Awesome IDE for Windows
On Windows, Visual Studio is the recommended C# IDE. It provides a very flexible GUI that you can rearrange the way you want and many useful features such as refactorings (rename a variable, extract some code into a method, ...) and code formatting (you can pick exactly how you want the code to be formatted).
Visual Studio also highlights your errors when you compile, making your debug sessions more efficient since you don't have to run the code to see the mistakes. There's also a powerful debugger that allows you to execute the code step-by-step and even change what part of the code will be executed next. In addition to giving you all the line-by-line information you'll need in a hassle-free manner, Visual Studio has stuff you can click on in the errors window that will take you to the documentation for that error, saving you several minutes of web searching.
In addition to all of this, Visual Studio has an intuitive, intelligent, and helpful graphical user interface designer that generates code for you (the best of WYSIWYG, in my opinion), which is helpful for new programmers. Being able to create a fantastic-looking UI with one's mouse and then optionally tweak with code helps make programming fun for beginner developers.
Visual Studio also has the best code completion --Intellisense is every bit as intelligent as the name says it is. It, as well as VS's parameter hinting, is context-, type-, user-, and position-sensitive, and displays relevant completions in a perfectly convenient yet understandable order. This feature allows a new programmer to answer the questions "What does this do?" and "How do I use it?" right then and there rather than having to switch to a browser to read through extensive documentation. This allows the programmer to satisfy their curiosity before it is snuffed out by several minutes of struggling through exhaustive documentation.
And for the more adventurous and text-ready developer, Microsoft does the best job of ensuring that everything, from interfaces and wildcard types down to Console.WriteLine("") and the + operator, is well-documented and easy to understand, with relevant and well-explained usage examples that manage to be bite-size yet complete, simple yet truly helpful. The reference site is easy to navigate, well-organized, clean and uncluttered, up-to-date, and fresh and enjoyable to look at, and every page is well-written with consideration for readers who are not C# experts yet want to read about changing the console background color.
The best part? It's free! Visual C# Express contains all of the features described above, at zero cost. If you are a student, you can probably get Visual Studio Professional from your university, which also includes tools for unit testing and supports plugins.
Pro Supports some functional features
C# is primarily object-oriented, but it also supports some features typically found in functional languages such as lambdas, delegates and anonymous classes. Methods can be treated like any other object, and the Linq query system operates on monads with lazy evaluation (though it hides this with a lot of syntactic sugar).
You don't need to use these features to code in C#, though, so you can start with OOP and then learn about them.
Pro Great introduction to object-oriented programming
Object-oriented programming is the most widely-used paradigm. C# offers support for common OOP features such as classes, methods and fields, plus some features not found in competing languages like properties, events and static classes.
C# code is much more readable thanks to the syntactic sugar it offers. You can truly concentrate on your code, not on the way it's implemented.
Pro Best language for Windows programs
C# is clearly the best choice for Windows programs. The .NET framework contains everything you need to build great-looking apps, without having to learn the confusing Win32 API or download a ton of external libraries. C# can also be used to build Windows 8's "modern" apps.
Pro Very high demand in the industry
C#'s been around for just the right amount of time, is regularly updated with useful additions, is versatile, easy to write & read, & has excellent tooling support. This means it is a top choice for many organizations & will remain so for the foreseeable future.
Pro Can mix high and low level programming
You can code at the high level without worrying about pointers and memory management, but if you so choose you can switch to lower level programming with direct memory management and pointer manipulation (though you need to compile to specifically allow this).
Pro Awesome IDE for cross-platform development
Visual studio has embraced cross platform development over the past 3 years. With Visual Studio Code, you now have a light, and quick IDE variant available for free as well.
Pro With ASP CORE a good language to learn
With CORE you are no longer just limited to Windows, so a language worth learning.
Pro Supported on many platforms
C# can be used for Windows apps, Linux apps, OS X apps, Windows 8 "modern" apps, websites, games, iPhone apps, Android apps, Windows Phone apps, and more.
If you want to create a cross-platform application, you can share most of the code and write one GUI for each platform.
Pro .NET truly universal
With .NET core it is a truly universal programming language which support desktop apps (Windows), Mobile apps (Xamarin), Web Apps (ASP.Core MVC). Also is perfectly fit to serverless programming for micro services. Soon it will be also support Web assembly (Blazor).
Pro Great language for Unity game engine
Unity provides a selection of programming languages depending on preference or knowledge - C#, JS, Boo and UnityScript. C# is arguably the most powerful with better syntax and stronger language structure. It allows using script files without attaching them to any game object (classes, methods inside unattached scripts that can be used at any time). There are more tutorials and information for C# than UnityScript and Visual Studio can be used to code for unity in C#. Additionally, learning C# allows using it outside of Unity as well unlike UnityScript.
Pro Optional static typing
Typescript has optional static typing with support for interfaces and generics, and intelligent type inference.
It makes refactoring large codebases a breeze, and provides many more safeguards for creating stable code.
Pro Strong typed language
Lot of benefits of it, you can read this.
Pro Strict superset of Javascript
Every existing Javascript program is already a valid TypeScript program giving it the best support for existing libraries, which is particularly useful if you need to integrate with an existing Javascript code base.
Pro First party Visual Studio support
As a Microsoft developed project, it has first party Visual Studio support that's on par with its C# support with features like syntax sensitive statement completion.
Pro Has a repository of high quality TypeScript type definitions for popular libraries
There are many ready to use and high quality TypeScript definitions for popular libraries including jquery, angular, bootstrap, d3, lodash and many-many more.
Pro Adds support for object-oriented programming
Typescript enables familiar object-oriented programming patterns: classes, inheritance, public/private methods and properties, et cetera.
Pro Polyfill for ES6 fat-arrow syntax
Typescript implements the fat arrow syntax, which always maintains the current context for this
and is a shorter/more convenient syntax than traditional function definition.
Pro Great support for React, integrated typed JSX parsing
Strongly typed react components, so UI "templating" automatically gains type safety.
Pro Great support for editors (Sublime, Code, Vim, IntelliJ...)
Pro Works well with existing Javascript code
Both can call Javascript code and be called by Javascript code. Making transitioning to the language very easy.
Pro Compiles to very native looking code
Compiles to simple looking Javascript making it easy to understand what is happening and learn the language (if you already know Javascript).
Pro Built and supported by Microsoft
Being built by Microsoft, TypeScript is much more likely than most other similar open-source projects to receive continued long-term support, good documentation, and a steady stream of development.
Pro Ability to do functional programming
Pro Clear roadmap
TypeScript has a clear and defined roadmap with rapid and constant releases.
Pro Low number of logical errors brought in by built-in type annotations
TypeScript's built-in type signatures allow developers to fully document interfaces and make sure that they will be correctly compiled. Therefore, cutting down on logical errors.
Pro Works well with Angular 2
Angular 2 is built using TypeScript and applications built using it can make use of that (or not).
Cons
Con Older versions lacks standard-library support for immutable data structures
Con Complex syntax
Too many syntactic constructs to learn before it becomes usable.
Con .NET is a mess
Continual drama with standards, updates, Microsoft, and being really cross-platform.
Con Excessively class based OOP oriented
Limits users into overly using awkward paradigm and creating another kind of spaghetti code.
Con A pale imitation of Java
C# is a Java-like language, but Microsoft failed to imitate Java's consistency. For instance, C# has types that cannot be passed by address (e.g. DateTime), forcing the developer to use ugly workarounds.
Con Too easy to write multithreading apps that are buggy
Many web frameworks or GUI libraries will push novice users to writing multithreaded code, which leads to frustrating race condition bugs.
Other languages with multithreading push users towards safe constructs, like passing messages and immutable or synchronized containers. But in C# the data structures aren't synchronized by default, and it's too easy to just set a field and observe the result from another thread (until you compile with Release, and now you have a heisenbug).
Con Often-used products in most C# development environments get expensive
The majority of the C# development community uses Microsoft products which are not all free and open-source. As you get into the enterprise level of some of these products and subscriptions, the expense is multiple factors of 10 greater.
While you can use a fully open-source and free C# environment, the community around that is much smaller. While this can be said for other languages as well, the majority of C# falls into the for-pay Microsoft realm.
Con Popularly used on Visual Studio (proprietary)
Most people learn and depend on Visual Studio (proprietary) to write C#. The result is people learn how to use an IDE and not the concepts or fundamentals of good programming. However, you don't need VS to develop in C#, all you need is the dotnet CLI and a text editor that supports OmniSharp like VSCodium, Vim and Emacs.
Con Large Library and eco system makes it unsuitable for beginers
yes, all the information about the .net framework is in one place, but it is so extense that it introduces a steep learning curve for newcomers to the field of programming languages.
Con Too similar to Javascript
Presents some advantages compared to Javascript, but because it is designed to be a superset of Javascript, it means all the bad parts of Javascript are still present.
Con Type checking not enforced by default
You have to use compiler flags to make sure it catches flaws like usage of implicit any, etc.
Con Type inference coverage is incomplete
The default type when declaring and using a variable is any
. For example, the following should break but does not:
function add(a:number) { return a + 1 }
function addAB(a, b) {return add(a) + b}
addAB("this should break but doesn't :(", 100)
In order to avoid this, you have to declare type signatures for every variable or parameter or set the flag --noImplicityAny
when running the compiler.
Con Requires "this" for field access
Even in cases were there is no ambiguity, you still have to use "this.fieldName" instead of just "fieldName".
Con Syntax is too verbose
Con No support for dead code elimination
Typescript compiler does not remove dead code from generated file(s), you have to use external tools to remove unused code after compilation. This is harder to achieve, because Typescript compiler eliminated all type information.
Con No support for conditional compilation
There is no clean way to have debug and release builds compiled from the same source, where the release version removes all debugging tools and outputs from the generated file(s).
Con Awful error messages
Comparing to Elm or Rust for example, TypeScript's error messages won't say you very much. For example if you change method of interface which your class implements it won't say your class have incorrect implementation. Instead it'll show error in usage of instances of class. In some cases it can spoil hours of your work trying to figure out why your parameters are incorrect.
Con Technical debt
As consequence of not enforcing type checking.
Con No Java-like package structure
If you prefer a Java-like approach of partitioning your code into different packages, the module system of typescript will confuse you.