5 ms·
I was wondering how many of these points are answered in C# (and in which version they were "fixed")
by andybak 9y ago
I was wondering how many of these points are answered in C# (and in which version they were "fixed")
- alkonaut 9y ago> * unsigned ints. Even Java's 8 bit byte is signed??! > * operator overloading, mostly for math like matrices, vectors, complex numbers > * ability to write a "swap" function (pass by reference) These were in from the beginning > * containers of primitives Generics (in the proper sense, not the Java sense) came in C# 2.0/.NET 2.0 in 2006. With those you can make a List<T> and have it backed by an array of primitives that is consecutive in memory. That is, if you make a List<int> it's not a list of some boxed Integer type. > * compiler that turns readable code into good assembly (no verbose code needed due to simpler A bit subjective, but I'll argue that the JIT is getting better and is still nowhere near as good as an ahead-of-time compiler that can spend time optimizing the code. The JIT has to be FAST first and foremost since it produces its assembly WHILE the code is already running. > * destructors that reliably do something at end of scope There are no destructors and the only deterministic destruction is disposal (via IDisposable). Objects are not freed at that point however. You only use it to free resources, such as deterministically closing a file. The managed object representing the file will sit in memory until the next GC. The very bleeding edge version of C# yet to be finished will contain a lot more low level C++ like features which will make it more ergonommical to use stack memory (Google "Span<T>"). That will approach some of the C++ use cases. > no need to write typename twice to create an object Locals can be implicitly typed. So var pet = new Dog(); Is an allowed statement inside a method. This came in C#3 in 2007.
- scarface74 9y agoMy favorite feature of .Net is probably expressions trees. (https://blogs.msdn.microsoft.com/charlie/2008/01/31/expression-tree-basics/ https://blogs.msdn.microsoft.com/charlie/2008/01/31/expressi...). They have been around since 2008. A lot of non .Net people think that expression trees are just lambdas, but they are so much more powerful. If you have a method that has a signature: Find(Expression<Func<Employee,bool>> query) {…} And you call it by foo.Find(e => e.id == 5); That expression is treated as “data” not code. Meaning if your Find command is searching for Employees in SQL Server using Entity Framework, it will be translated to sql that runs on the server. If you’re using Mongo, it will be translated into MongoQuery. When you are unit testing you can mock it out, and process any given query against an in memory List<People>. If you are crazy enough, you can even move it out into a micro service and parse the expression tree yourself into a query object that you send to an API.
- alkonaut 9y agoCode quotations is similar in F#, but if you add F#'s type providers you can reach an entirely new level of crazy.