Friday, May 17, 2019

C# kingdom

https://www.nuget.org/

https://www.nuget.org/packages

& C# Benefits

1. LINQ. There's a reason more or less everyone brought this up in their answers. A common set of generic operations over arbitrary sequences of data is a feature that should be in every language. I cringe whenever I find myself writing a loop in some language when I know I could do it in 1 line with LINQ.

2. Visual Studio. In my experience, it's simply the best IDE around, especially if you add in productivity tools like ReSharper. Debugging is powerful and intuitive. If you get the Ultimate edition, performance profiling is extraordinarily useful and very easy to use. Many extensions/plugins are available that enhance the IDE even further. It's really a joy to use, though it can be a little slow at times.

3. Lambdas. Functional programming can be exceptionally powerful, and lambdas allow you to write functional-style code in C# succinctly and clearly. Check out LINQ for an example of lambdas put to great use.

4. Strong typing. There are obviously trade-offs regarding strongly-typed vs. weakly-typed languages, but I prefer strong typing for two reasons. First, I want as many errors as possible to be found at compile-time as opposed to run-time. Second, Intellisense is an incredibly valuable tool for code correctness and discovery. Being able to pull up a list of member properties/functions allows me to understand, at a glance, what an object is and what it is basically capable of doing. This kind of functionality isn't available in weakly-typed languages, and without it I tend to feel somewhat "lost" in the code, less sure of what everything is and does.

5. Anonymous types. These, in combination with LINQ, can be incredibly powerful. They allow you to come up with new types on the fly, without first declaring them, and yet still get all the benefits of compile-time type checking. I'll often use these to create some intermediate step in a complex series of LINQ-based data manipulations.

6. Simple async/concurrent code. Writing parallel code is as simple as Parallel.ForEach (or, depending on what you're trying to do, myList.AsParallel()). Starting up a new thread is as simple as Task.Factory.StartNew(). This, of course, doesn't eliminate the inherent challenges of using concurrent code, but it makes it dead simple in the easy cases, and there's concurrent versions of many data structures to help avoid some of the more common pitfalls. And in C# 4.5, there's also the new async/await keyword keywords, which are supposed to make concurrent programming even easier.

7. ASP.NET MVC/Web API. Microsoft's web stack is really nice to use. MVC gives you a solid framework for writing MVC-style websites, and Web API makes writing REST APIs very easy. Razor syntax, which allows you to write server-side C#, is also really well-done and powerful. 

8. WCF. Though I've recently found myself preferring REST APIs written with Web API, WCF-based services are still powerful and easy to set up. The main advantage to using WCF over Web API is that Visual Studio will automatically create client code for any service you reference if it publishes the appropriate metadata (which is very simple to do). If you're creating service-oriented systems, this can save you from having to duplicate data structures between different service layers.

9. NuGet. C#'s package manager. Many libraries available, easy to use, integrated into Visual Studio.

10. Extension methods. These are pretty neat. They allow you to add methods to a class without actually changing (or even having access to) its definition. This allows you to write OO-style code in situations you normally couldn't (you can, for example, add utility functions to any standard .NET class, instead of globbing them into static helper classes or other such inelegant solutions). 

11. Type inference. This is important, especially in the presence of LINQ functions and anonymous types. Instead of writing the type of a variable before its name (like MyClass obj = new MyClass()), you can simply write var, and the compiler will infer the type of the variable from its context. This is not only more concise and DRY-compliant, but it also allows you to declare variables that reference instances of anonymous types (or generic collections thereof), which would otherwise be impossible.

12. Properties. These provide a concise way to declare variables and their associated getter/setter functions. In the trivial case (getters/setters with no additional functionality), you can use automatic properties to reduce the entire property declaration to a single line.

13. MSDN Library. This isn't part of the language, exactly, but the MSDN library (Microsoft's online documentation repository) is extensive and thorough. Every .NET class is documented there, and it contains a ton of articles and walkthroughs that show you how to do almost anything you want. If you Google the name of a .NET class, a MSDN page will likely be the top result, and it will likely (not always, but most of the time) contain enough information to at least get you started.


Lighter version of Visual Studio:

-||-


No comments:

Post a Comment

Коментар: