8 ms·
Actually, the new features introduced in C# increases developer productivity quite a bit. More importantly they increase the readability of code by cutting down
by web_chops 14y ago
Actually, the new features introduced in C# increases developer productivity quite a bit. More importantly they increase the readability of code by cutting down on the repetitive stuff. Once some one uses LINQ, lambdas and dynamics its hard to go back.
- edwinnathaniel 14y agoCan you explain how they can cut down lots of repetitive stuff? Not to knock you down but my experience with Java is that libraries typically help a lot as opposed to syntax.
- mquander 14y agoGo look at any documentation or discussion of any non-Java language, and see their examples of using their sequence abstractions, or generators (yield), or first-class functions. Those are not ideas which are unique to C#. If you just want to see a piece of code in C# that would have to be written totally differently in Java to be readable (unless you use some quite abstract third-party libraries like Guava to help) I picked one of my Stack Overflow answers at random: http://stackoverflow.com/questions/2966592/how-to-refactor-this-duplicated-linq-code/2966726#2966726 http://stackoverflow.com/questions/2966592/how-to-refactor-t...
- edwinnathaniel 14y agoThat example is definitely looks great. ... and yes, as a Java developer, I use Guava once in a while and I do JavaScript as part of my job as well and I do appreciate first-class function. Typically the problems that functional features solve are filtering and transformation and yet most often than not I happen to solve them at the SQL layer (be it JPQL or straight up SQL).
- macca321 14y agoOnce you start thinking of your object model as data, you can do amazing things. Want to find all the types in your system that implement an interface and spin them up? var rules = AppDomain.CurrentDomain.GetAssemblies .SelectMany(a => a.GetTypes()) .Where(t => typeof(ISecurityRule).IsAssignableFrom(t)) .Select(t => Activator.CreateInstance() as ISecurityRule) .OrderBy(r => r.Priority); You can then run a chain of responsibility by writing var allowed = rules.First(r => r.Check(someObject) != null); //Check returns null when a rule isn't relevant to the object being checked it's pretty sweet for metaprogramming when you can run queries against your codebase
- edwinnathaniel 14y agoThat is definitely sweet. Java has AOP and extensively use Annotations (Attributes in .NET) and the approach there is definitely heavier than what you wrote above.
- matthewschrager 14y agoLINQ + lambdas are great at this. Simple example: say you have a list of Car objects, and you want to get a new list comprising only the cars whose engines have greater than 300 horsepower, sort them in order of increasing price/horsepower ratio, and then take the top 20. In most languages, this requires a bunch of loops. In C#, it looks like this: cars.Where(x => x.Horsepower > 300).OrderBy(x => x.Price / x.Horsepower).Take(20); This results in a lazy-evaluated evaluated expression that works exactly the same whether cars is an in-memory list, a SQL table, a RavenDB collection, or anything else that implements the right interface (IEnumerable). It's not only concise, but also self-documenting. The syntax implies the semantics.