share
Stack OverflowWhat is the most under-valued part of .NET?
[+66] [33] Jan Bannister
[2009-07-17 16:50:03]
[ .net frameworks tips-and-tricks ]
[ http://stackoverflow.com/questions/1144480/what-is-the-most-under-valued-part-of-net ]

The .NET framework is massive. I've used it for years and I've still not used most of it.

I'd like to expand my knowledge of the Framework's backwaters but just reading thought it seems daunting. So I thought I'd tap up the Stack Overflow community first.

What part have you found to be the most surprisingly useful? What's your favourite obscure namespace? And conversely are there any shiny bits that are best avoided?

(33) Of course, the more an answer is voted up in this question, the more it is actually wrong, because it means that other people agree and thus value it. Truly under-valued areas of .NET should have a score around zero... - Greg Beech
(14) Not really. It just means that those people find the answer to be true. Of they vote it up becasue they didn't even realize it was in the framework. - Matthew Whited
(1) LOL, an interesting thought, but I'm voting up the items that I believe are useful and I've personally observed people ignoring or discrediting them. - 280Z28
[+148] [2009-07-17 16:55:59] John Saunders [ACCEPTED]

The degree of consistency across this huge framework.

Whenever I need to use a new part of the Framework, I'm able to pick it up quickly, because of the fact that it mostly all follows the same rules.

With .NET, it's not that the whole huge thing is right in your face, but rather that, when you need something, it's within reach.


(4) Definitely under-valued. - 280Z28
(107) And if you don't what what he's talking about, try learning PHP. - spoulson
Not quote the answer I was expecting but I have to agree - Jan Bannister
(2) @spoulson I would upvote that more if I could! - corymathews
(3) Unfortunately, they didn't have "CLS Compliance" from the get-go, and it shows in the little nooks and crannies of the framework. However, compared to other frameworks, .NET is a shining star. - John Gietzen
(2) It's a shame some of the tools to use with it don't keep this consistancy. I'm looking at you DevExpress. - whybird
1
[+56] [2009-07-17 17:07:30] mgroves

Linq is truly amazing.


(1) Yeah, the whole idea, and hoe well it integrated with C#. Saves so much lines of code. - Dykam
(31) yes, but the question is "under-valued" and I have yet to met a .NET developer who dismisses Linq as not worth it. - Andy_Vulhop
(11) I think it's often confused with Linq-to-SQL and dismissed. - mgroves
(2) Yea, I used to be anti-Linq (because I didn't understand it -- got it confused with "Linq-to-SQL") but I watched a few videos on it and I really liked it. Before then, the only "benefit" I found was extension methods which when first learning 3.x were confusing to me. - Zack
(1) @codemonkey4hire, I met people who see it as some alien-like evil. I count that as under-valued. - Dykam
With a simple extension method and one LINQ statement, it is possible to populate a quadtree from a dataset with 4000 points in about 300ms. Also using a single LINQ expression, I can query the quadtree and clip to displayrect in about 10ms. These performance figures are for code running on a Windows Phone not on a workstation. - Peter Wone
2
[+32] [2009-07-17 16:55:25] Andy_Vulhop

In general, I think Reflection is glazed over by a LOT of .NET developers. True, it is not usually the best tool for the job, but there are plenty of times it can help solve a really tricky issue.


(17) I think it should be glazed over more often. Misuse is rampant, and like multithreading the hazards usually far outweigh the benefits. - MusiGenesis
I have yet to use Reflection in production code myself, but I answered as such because a vast amount of .NET developers I know don't even know how to use Reflection, and many don't even know what it is. - Andy_Vulhop
(4) And, at the very least, Reflection is nice for displaying current assembly version number on a form/website. - Andy_Vulhop
(1) I've seen some frighteningly bad uses of reflection myself. I'm pretty sure you could get through your whole career without missing it. I did write my own unit testing suite with reflection back before they were all over the place, though. - quillbreaker
(1) The ONLY time I EVER user reflection is dynamic plugin loading. Every other use is abuse in my eyes. - John Gietzen
It's also not terrible if you have to roll your own code generation/ORM because your place of employment is too cheap to buy one or has a case of the "not invented here" syndrome. Not ideal, obviously, but at least you have an option rather than kicking dirt and whining. - Andy_Vulhop
(2) Reflection underlies nearly everything in the framework. Without reflection, Enum.GetNames or Enum.GetValues would not work, and so on. For programmers, it is not as useful. For library developers, it is essential. - AMissico
Very useful for diagnostics logging too. John needs to open his eyes some more :) - Stephen Kennedy
3
[+30] [2009-07-17 17:02:46] Philippe Leybaert

The regular expression engine in .NET is far more powerful than most people think. It's one of the best and most robust regex implementations around.

Although some people misuse it, in specific situations it can save you lots of time and effort.


(1) The Compile option is especially nice when use right. - Dykam
Totally agree and I'd +2 this if I could! - Zack
(2) Erik Naggum kind-of-quote; "A novice once had a problem. He said I know I'll just use Regular Expressions. The novice now had TWO problems"... - Thomas Hansen
(38) I'm so sick of that quote. You can't mention Regular Expressions without someone dropping it. It is annoying, overused and honestly I think it reflects badly on the people who use it. - KingNestor
Very true. I especially like the facility that lets you match nested brackets (and other constructs) - this actually makes .NET regexps powerful enough to parse many programming languages. Is there any other regex library that offers this, even? - Pavel Minaev
(1) @Paval: Most of the major regex engines (i.e. Perl, Java and a few others) can parse nested brackets, IIRC. Jeffrey Friedl's Regex book has a separate chapter about non-standard extensions, if you want look it up. - nikie
@Dykam...or anyone...can you give a link? Why is it especially nice? How is it used right? How is it used wrong and why is it bad then? Thanks! - Stomp
The regular expression constructor runtime generates code for checking the regular expression. You can see it as without the Compiled option, it interprets the regex live, and executes it on the string to check, while when using Compile, it runtime generated code for doing so. Basically interprenter vs. JIT. The Compile option has quite some overhead, so should only be used when checking like loads of strings. - Dykam
@KingNestor, you are right if your talking about using Regex with html or xml, but it's purpose is text searching and if you use it for that purpose alone, it's simply the best tool in lots of cases (but text searching is not something you may encounter very often) - Pop Catalin
The Regex replace needs a little more power though. I've asked for a feature to be added, but it was declined. - Yuriy Faktorovich
4
[+28] [2009-07-17 17:04:51] Greg Beech

All of the encoding related stuff in System.Text. I won't get into a rant about how most developers don't understand anything about encodings even though they really, really should, and just express my gratitude that so many encodings are implemented in .NET, along with quite obscure and specialist things like different Unicode normalization forms etc.

(And if you want an example of why you should know this stuff, have a think about how you'd strip non spacing marks (e.g. ñ -> n, é -> e) to make SEO and browser-friendly URLs. A huge lookup table? Nah. Try 5 lines of code [1].)

[1] http://blogs.msdn.com/michkap/archive/2007/05/14/2629747.aspx

Even if you don't count brace-only lines or the method sig, I get 7 LOC there. And it seems a lot less impressive when you realize that it is simply a big lookup table that's published by the Unicode standard and included in .NET, and which many other languages/platforms have interfaces to, too. - Ken
(6) 5? 7? Whatever. It's not the most concise way to write the code. The point is that it's not many. In any case, the question wasn't "what does .NET have that other platforms don't" it was "which parts of .NET are under-valued by developers". If you have this type of facility in your platform and you value it then good on you - one less person that needs convincing. - Greg Beech
5
[+26] [2009-07-17 18:09:58] o.k.w

For me, the first thing that comes to mind is Generics. Easy to understand, use, makes sense and most of all, improves performance.


(4) Yeah, CLI support of generics is really powerfull. - Dykam
Some of the things you can do with generics are really neat. I've got a function that looks for a parent control of a specific T type, a function that returns a list of all of the type T controls in a page, and a function that unboxes an object into a T or throws an exception. All very handy. - quillbreaker
Yes generics save lot of work. Love them - George Statis
Generics are neat, but their performance is perhaps their least interesting feature. I'd sacrifice quite a bit of runtime performance to make my programs simpler. - Ken
6
[+22] [2009-07-17 16:56:40] sigint

One man's backwater is often another man's metropolis, but still -- System.Globalization gets my vote. The amount of work it saves me (especially with different calendar systems) makes it my favorite underrated namespace.


especially compared to trying to do the equivalent in Java... yeck - jle
The System.Globalization.TextInfo.ToTitleCase is an example of the gems you may find deep in the framework even after years of usage. It will turn "hello world" into "Hello World". Read about it on MSDN, and make sure you also read the comment "We reserve the right to make this API slower in the future." :-) msdn.microsoft.com/en-us/library/… - michielvoo
7
[+22] [2009-07-17 19:34:38] kenny

Mono [1] on Mac OS X, Linux, ...

[1] http://en.wikipedia.org/wiki/Mono%5F%28software%29

8
[+20] [2009-07-17 18:17:14] John Saunders

I'll add a second choice: the entire XML API in System.Xml.*

It took me a long time to get comfortable with it. XmlReader scared me away completely! I had to get my feet wet with XmlDocument, then slowly added a little XPath for selection (I needed to stop and learn about XML namespaces at that point). I learned a bit of XPathNavigator (which has some really underutilized features, like AppendChild()), XslCompiledTransform, all the XML Schema stuff, and then, finally, XmlReader and XmlWriter.

XmlReader and XmlWriter aren't that bad if you take your time, understand what the different kinds of node are, and allow four times as much time as you thought it would take you to debug!

But I've been able to do some fairly neat things with this stuff:

  • Process a 10GB XML document by

    • using XmlReader.ReadSubTree for each element under the root, then
    • using XslCompiledTransform on the subtree

    This was very helpful with SSIS, wihch otherwise wanted to read the entire 10GB into memory.

  • Create sample data based on a set of XML Schemas, using the System.Xml.Schema.XmlSchemaValidator class [1]

    This class is a hidden gem. It really needs to be in a different namespace. Almost everything else in the System.Xml.Schema namespace [2] is named "XmlSchema*something* and represents part of the object model of an XML Schema. The one class that fits that naming pattern but is not part of the SOM is xmlschemavalidator:

The XmlSchemaValidator class provides an efficient, high-performance mechanism to validate XML data against XML schemas in a push-based manner.

Long story short, this thing will tell you, at any point in the logical processing of an XML document, what is valid at the current point. You then tell it which of the valid choices you made, and it will tell you what's valid at that point, etc. So, if you write one of the valid choices when it says they've valid, you'll wind up producing a valid output document.

Enough's been said about LINQ to XML, so I won't say more. I will finally just mention the System.Runtime.Serialization.XmlDictionaryReader and XmlDictionaryWriter classes, just so I can say "binary XML" in a sentence.

[1] http://msdn.microsoft.com/en-us/library/system.xml.schema.xmlschemavalidator.aspx
[2] http://msdn.microsoft.com/en-us/library/system.xml.schema.aspx

wow. I'm going to learn some more about XML now. :) - Zack
Downvoter, please explain. - John Saunders
What about System.Xml.Linq? Isn't that the new bling? - DanM
It's a nice API for constructing and querying XML. It doesn't have the full generality of the rest of the XML API. But then, you don't always need the full generatlity. - John Saunders
I would add one exception to the System.Xml API, and that's the XSLCompiled transforms, and the huge amounts of memory it can eat in ASP.NET environments from my experience. Fortunately from what I've read Microsoft are not writing a XSLT 2.0 processor but pushing towards Linq to XML - Chris S
The high memory usage you saw must be specific to your environment and/or transforms. Like I said, I processed 10GB XML files, with no problem. BTW, this was on my 2GB laptop. - John Saunders
9
[+19] [2009-07-17 17:46:40] Chris Brandsma

The Delegate. Hard to really call it under-appreciated since it is the underpinnings for LINQ, Lambda, Anonymous Delegates, and Events. But the code is often written in such a way that you don't even know you are using a Delegate. Many developers use them every day without even knowing what they are.


(1) Very true. On the other side Delegates can be stupid, as you can't assign a delegate from type ADelegate to a delegate with the type BDelegate, while they both expose the same prototype. - Dykam
(8) Saying that makes those stupid would be like saying that type checking is stupid because ClassA and ClassB can have the same exact fields/properties/methods but aren't interchangeable. Delegates aren't duck-typed. - scwagner
10
[+18] [2009-07-17 16:53:03] 280Z28

Memory management and underlying CLI design

The bump pointer memory allocator combined with user-defined value types and a fallback ability to use unsafe code. A great step forward where the JIT is the only thing keeping us from passing C++ performance nearly across the board. That and the fact that it's already improved to the point that it's not far off. This is undervalued because there remain a large group of people who do not see the current state of things or the potential that lies before us in this respect.

Phenomenal inter-language coding support. Every system should be designed for such - allows comfort now and flexibility in the future.

General thought on the framework

There are "tricks" everywhere. Since I've been working on implementing a test CLI VM, I've picked up a great number of them and I try to answer them wherever I see them asked in specific questions. In general, if something seems awkwardly verbose, there's an easier way that you just haven't identified yet. And when you do, you'll think "yeah, that does make sense. :)"


(11) "unsafe" is a beautiful keyword, but it deserves a better-sounding name, since it sounds like only a crazy person would want to write unsafe code. I nominate "oldschool" as an alternative. - MusiGenesis
(8) 'Unsafe' is precise though. A managed machine (CLI) that allows verifiable code means we can have extremely fast, extremely safe code for both reliability and computing in untrusted environments. Code that breaks these rules may or may not be faster - its only guaranteed ability is removing provable safety. - 280Z28
unsafe can break running app completely, where non-unsafed code can't without a bug in the JIT or libs. I find unsafe quite well chosen. - Dykam
"oldschool" isn't accurate, because it implies that unsafe code is something that's not used commonly anymore, and it most certainly is. I think "unmanaged" is better. - mgroves
(3) It's still managed code. Unsafe code in C# compiles to the same IL bytecode, it just uses abilities like passing unmanaged (raw) pointers to instructions like stind (store indirect/to a pointer) and ldind (load indirect). There are many "unsafe" instructions documented in ECMA-335. - 280Z28
(3) I nominate "pointy", because you're probably using pointers, and you may stick a hole in your app if you arn't careful. - quillbreaker
Unsafe is a good catch-all. There are several ways in which code may be unsafe, and it captures them all. I concur that the word is not as instructive as it might be, but unsafe code is not for the faint of heart, and if you aren't intimately familiar with the risks inherent in taking off your metaphorical seat-belt, you probably shouldn't do so. - Peter Wone
11
[+13] [2009-07-17 16:52:15] Darin Dimitrov

Ever since the introduction of System.Web.Mvc namespace I am a happier man.


(1) That is not really a part of dotNET, it's an external lib. By accident from microsoft and thus places in their namespace. - Dykam
(5) MVC is just out-of-band right now. It'll be fully integrated into .NET 4.0 - Bob King
12
[+11] [2009-09-29 20:28:44] Mike Two

The System.Linq.Expressions namespace. The ability to treat code as data so that you can manipulate it is a very powerful thing. You can also use it to dynamically build up simple methods.


(1) I agree. I've recently read John Skeet's very solid 'C# in Depth' and it's amazing how almost every new feature in .net 3.0 is there to support Linq. It is a game changer! - Jan Bannister
(1) The new expression tree stuff in .NET 4 just underlines this point. In .NET 4 it is possible to build complex methods as well. - JohannesH
13
[+11] [2009-09-29 20:50:55] HitLikeAHammer

I really like the System.Diagnostics namespace. There is a lot of cool stuff in there. Have you ever used the Stopwatch, PerformanceCounter or StackTrace classes?


14
[+9] [2009-07-17 16:54:12] CodeToGlory

The all powerful Windows WorkFlow Foundation.


(8) Still don't know what this is to be completely honest. :-/ What is it used for? :x - Zack
(1) This is by far the most underutilized component. Sadly, until they build better IDE support for it, it's not going to go anywhere. Why do something with 15 WF classes when you could do it with 3 regular ones? - womp
WWF is not good, IMHO. Stateless or Simple State Machine are much better implementations of workflow and rules engines - jolySoft
15
[+8] [2009-07-18 00:20:15] Dan Diplo

LINQ to XML [1] is pretty damn cool and often overlooked. Oh, and I guess Expression Trees [2] form the basis of a lot of that coolness.

[1] http://msdn.microsoft.com/en-us/library/bb387061.aspx
[2] http://msdn.microsoft.com/en-us/library/bb397951.aspx

16
[+7] [2009-07-17 18:48:46] Jorge Córdoba

The fact that it follows a public spec and is JITTED so that:

  • You can use the same program in any supported architecture (i.e. X86, x64)
  • You can run it in a lot of OS with mono. More operating systems will probably be supported in the future...
  • Anyone can develop a .NET language

With any luck you'll have one program that will be able to run in any machine, programmed in any language you like, running on any operating system there is.


17
[+6] [2009-07-17 18:17:31] Mark Bessey

My favorite underutilized features are probably Attributes and Reflection. Of course, those two go together a lot of the time.


Definitely. I've met .NET "developers" who thought Attribute was another name for Property. Probably because the terms are soemtimes interchangable in English. - nikie
18
[+6] [2009-07-17 18:21:39] Dana Holt

I must say the same code running on 32 and 64 bit platforms is very nice.

All kinds of gotchas with unmanaged code.


19
[+5] [2009-07-17 17:10:54] tbreffni

I found reading about the Common Intermediate Language [1] to be very interesting, if you want to see how things work under the hood in .Net. Here is a useful tutorial [2] if you want to learn how to write it.

[1] http://en.wikipedia.org/wiki/Common%5FIntermediate%5FLanguage
[2] http://weblogs.asp.net/kennykerr/archive/2004/09/07/introduction-to-msil-part-1-hello-world.aspx

20
[+5] [2009-07-17 17:39:24] Matthew Whited

The .NET Framework... I have seen many people not take the time to see if the framework has built-in support for something they want to do and they just go ahead and and roll their own. There is also a large group of people that think their custom code is faster than the classes that Microsoft (or Mono) has in the framework only to complain and having problems with performance and maintenance later. (And of course this is Microsoft’s fault because the bug would never be in custom code.)


21
[+4] [2009-09-29 20:37:35] Pavel Minaev

.NET 2.0+ XSLT implementation (XslCompiledTransform). Not many people realize this, but it's a full-featured solution with complete VS integration - you also get debugging with step-through and breakpoints, the complete functionality of Watch window with XPath expressions, and so on. Combined with the ability to create custom functions in C#/VB with <msxsl:script> blocks (not many people know that when you precompile your XSLT, this does not require FullTrust - MSDN omits this important piece of information), it is a very powerful tool for many XML processing tasks, and overall one of the fastest and most convenient XSLT 1.0 implementations out there.

Oh, and don't forget to turn on the hidden XSLT IntelliSense feature [1]!

[1] http://www.tkachenko.com/blog/archives/000740.html

I had to give this comment a bump, because just 2 days ago this exact class saved me having to reformat a web server. We were using an old VB6 COM object that somebody hacked together years ago to do our XSLT stuff.. it started to misbehave and (as it had done before) caused irreprable damage to one of the web servers (I don't know how, but better developers here haven't been able to figure it out).. instead of going with the old hack, I just used .NET 2.0's built in XSLT functionality and achieved a very successful result. The bosses were delighted! - DaveDev
22
[+4] [2009-12-26 21:07:46] thecoop

Attributes, along with the ability to define your own (there are a couple of oddities in the BCL for things that should be interfaces though). When I've used them, they've been invaluable, and solve problems that would be very difficult or hacky to solve any other way.


23
[+3] [2009-07-17 18:01:04] Cherian
  1. The general feeling that since its JIT [1]ed it will slower!
  2. API's as such. API's in general are designed beautifully!
  3. Activator [2] Class
  4. Linq to Xml [3]
[1] http://en.wikipedia.org/wiki/Just-in-time%5Fcompilation
[2] http://msdn.microsoft.com/en-us/library/system.activator.aspx
[3] http://msdn.microsoft.com/en-us/library/bb387098.aspx

+1 for the Activator. - kenny
24
[+3] [2009-07-17 18:42:03] Hardryv

I have to give my highest props to the CLR (Common Language Runtime). .NET simply couldn't be .NET without it.

It single-handedly allowed resurrection of the very broken, prior implementations of Visual Basic, continuously showers new life into custom SQL library development, and continually / automatically enhances cross-language execution-time efficiency.

An enterprising, dual-platform developeer buddy of mine is already researching how to get appropriate dev-tooling into VS2k8 so he can code iPhone apps using the Studio tool-set.


Is he getting anywhere? - SLaks
not yet, he's actually in the process of moving his flag back to the US from Europe atm -- once he's settled in I know this will become a topic of conversation... I'll post an update if any relevant info develops - Hardryv
(1) Any progress? - Viktor Dahl
No, he did SharePoint architecture for a good long time and then got a real development job with real pay. I think he's put down his iPhone development hopes for now. If that changes I will update this ;). - Hardryv
25
[+3] [2009-07-18 00:26:48] Stan R.

Closures with LAMBDA expressions, saves a lot of headache...but can be just as evil if used in the wrong hands.


This is not part of the .Net Framework, it is just a feature of some languages. - Brian
26
[+3] [2009-07-18 20:45:37] Charles Prakash Dasari

I guess the whole component model is heavily under utilized. This provides a great tool to write plugins into the OS and other huge products. Yet I find it little understood (at least by me) and little documented...


From what I've seen, it looks very very powerful, but hard to understand and use :( - thecoop
27
[+3] [2010-05-03 22:10:58] FastAl

I can't believe nobody commented on GDI+! Talk about doing anything you ever wanted with graphics. Before .NET I just avoided graphics unless I needd to because it was such a pain. I knew what I treasure it was when I noticed on the computer I bought 2 years ago, I have not had to install ImageMajick.

If you want to use spot-generated graphics in a website, put cool animation in your thickclient splashscreen, or print just about anything, any way, do yourself a favor. Visit Bob Powell's GDI Plus FAQ and learn GDI+ today!!!

If you don't think you'll ever use it... you're probably wrong >:-}


URL: bobpowell.net/faqmain.aspx - tomfanning
28
[+2] [2009-12-22 09:01:30] leppie

The element of least surprise.

Pretty much inline with what John Saunders said.


29
[+2] [2010-05-03 22:24:25] Steve

The CLR Hosting model and strong assembly naming. A couple of those important things that you generally don't think about but when you need them you thank god for their existence.


30
[+2] [2011-02-20 05:24:46] Darkhydro

Delegates. By far the coolest thing i've encountered in any programming language. The ability to throw around methods like variables without pointer issues or massive anonymous classes (sorry Java) always makes me feel warm inside. And yet I never see anyone talking about how awesome they are... they just use em and forget about em.


31
[+1] [2009-12-22 08:38:56] Shimmy
  • If your language is VB.NET, then take a look at XML literals [1], you will be amazed if you still donno it!
  • I also think that .NET is the only environment that supports Generic types.
  • Linq rocks too.
  • WPF is gorgeous.
  • .NET's documentation is really really explained with snippets and snapshots online, and its method names are very descriptive and simple to understand.

I don't think I could manage without .NET, my best dream is that .NET's main language would become python; or it should at least be fully supported out-the-box.

[1] http://blogs.msdn.com/jimoneil/archive/2009/06/15/x-is-for-xml-literal.aspx

32
[+1] [2010-05-24 14:37:35] mmsmatt

The BCL documentation [1]

[1] http://msdn.microsoft.com/en-us/library/ms229335%28v=VS.90%29.aspx

33