views:

2365

answers:

32

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?

+9  A: 

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

Darin Dimitrov
That is not really a part of dotNET, it's an external lib. By accident from microsoft and thus places in their namespace.
Dykam
MVC is just out-of-band right now. It'll be fully integrated into .NET 4.0
Bob King
+13  A: 

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. :)"

280Z28
"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
'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
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
I nominate "pointy", because you're probably using pointers, and you may stick a hole in your app if you arn't careful.
quillbreaker
+8  A: 

The all powerful Windows WorkFlow Foundation.

CodeToGlory
Still don't know what this is to be completely honest. :-/ What is it used for? :x
Zack
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
+23  A: 

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.

Andy_Vulhop
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
And, at the very least, Reflection is nice for displaying current assembly version number on a form/website.
Andy_Vulhop
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
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
+92  A: 

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.

John Saunders
Definitely under-valued.
280Z28
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
@spoulson I would upvote that more if I could!
corymathews
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
It's a shame some of the tools to use with it don't keep this consistancy. I'm looking at you DevExpress.
whybird
+19  A: 

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.

sigint
especially compared to trying to do the equivalent in Java... yeck
jle
+25  A: 

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.

Philippe Leybaert
The Compile option is especially nice when use right.
Dykam
Totally agree and I'd +2 this if I could!
Zack
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
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
@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
+23  A: 

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.)

Greg Beech
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
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
+36  A: 

Linq is truly amazing.

mgroves
Yeah, the whole idea, and hoe well it integrated with C#. Saves so much lines of code.
Dykam
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
I think it's often confused with Linq-to-SQL and dismissed.
mgroves
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
@codemonkey4hire, I met people who see it as some alien-like evil. I count that as under-valued.
Dykam
+5  A: 

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

tbreffni
+4  A: 

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.)

Matthew Whited
+14  A: 

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.

Chris Brandsma
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
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
+2  A: 
  1. The general feeling that since its JITed it will slower!
  2. API's as such. API's in general are designed beautifully!
  3. Activator Class
  4. Linq to Xml
Cherian
+1 for the Activator.
kenny
+22  A: 

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

o.k.w
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
+16  A: 
John Saunders
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
+3  A: 

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

Mark Bessey
Definitely. I've met .NET "developers" who thought Attribute was another name for Property. Probably because the terms are soemtimes interchangable in English.
nikie
+5  A: 

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

All kinds of gotchas with unmanaged code.

Dana Holt
+3  A: 

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.

Hardryv
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
+7  A: 

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.

Jorge Córdoba
+16  A: 

Mono on Mac OS X, Linux, ...

kenny
+8  A: 

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

Dan Diplo
+2  A: 

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

Stan R.
This is not part of the .Net Framework, it is just a feature of some languages.
Brian
+2  A: 

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...

Charles Prakash Dasari
From what I've seen, it looks very very powerful, but hard to understand and use :(
thecoop
+8  A: 

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.

Mike Two
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
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
+3  A: 

.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!

Pavel Minaev
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
+7  A: 

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?

Loki Stormbringer
A: 
  • If your language is VB.NET, then take a look at XML literals, 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.

Shimmy
+1  A: 

The element of least surprise.

Pretty much inline with what John Saunders said.

leppie
+1  A: 

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.

thecoop
+1  A: 

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 >:-}

FastAl
URL: http://www.bobpowell.net/faqmain.aspx
tomfanning
A: 

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.

Steve
A: 

The BCL documentation

mmsmatt