Designing .NET Class Libraries chat on the Rich Type System (February 02, 2005)

Posted: February 16, 2005

Please note: Portions of this transcript have been edited for clarity

Introduction

Brad Abrams [MS] (Expert):
Hello! Welcome to the chat. I gave the session we are talking about today and I am interested in hearing your feedback and questions.. more about me on https://blogs.msdn.com/brada

frankred [MS] (Moderator):
Well, let’s get started by introducing our knowledgeable experts...

Krzysztof Cwalina (Expert):
Hi, This is Krzysztof Cwalina. I am a Program Manager on the .NET Framework Team responsible for the .NET Design Guidelines. I am looking forward to this chat session.

Brad Abrams [MS] (Expert):
Q: Do you envision any new intrinsic value types coming along?
A: You mean like at the level of In32 and Double... Sure. While there is nothing new there in WHidbey, I do expect to see some in the future... as long as programming evolves so will the set of base types. Anything you want to see us add?

Joe Duffy (Expert):
Howdy folks! My name's Joe Duffy, and I'm likewise a PM on the CLR team... a little blog plug: https://www.bluebytesoftware.com/blog/. Looking forward to your questions... Let the grilling begin! :)

Start of Chat

Krzysztof Cwalina (Expert):
Q: Do you envision any new intrinsic value types coming along?
A: Nullable has the potential to becomming such .NET Framework intrinsic type.

Jonathan Keljo [MS] (Expert):
I'm Jonathan Keljo, Program Manager for the CLR Debugging API, Profiling API, and Exception system.

Krzysztof Cwalina (Expert):
Q: To clarify the concept of immutability, you're refering to the actual value itself and not the container for the variable, yes? How do you square this in relation to stucts?
A: We define an immutable type as a type whose observable value cannot be changed using public APIs after the instance is created.

Brad Abrams [MS] (Expert):
Q: Should we expect change of behavior on some of the value types with the comming of 64bit machines, OSes and framework? If so, what should we pay attention now to avoid problems in the future?
A: Not exactly.. the goal for our 64bit work is to make apps you build today on 32bit .NET Framework work seamlessly as possible. So Int32, Double, etc all stay exactly the same. We do have the IntPtr type that changes size based on the WORD size of the machine. The interesting problems we have found come up with Interop… getting those PInvoke signatures right is very important. More information here: https://msdn2.microsoft.com/en-us/netframework/aa496329.aspx

Joe Duffy (Expert):
Q: Does the UE team over there have a policy about following the design guidelines by chance?
A: We strive to follow the Design Guidelines in all of our SDK content. In fact, we even use the FxCop toolset to enforce a lot of this... We regularly run through the content to ensure that we're following guidelines, and important FxCop rules report 0 violations.

Joe Duffy (Expert):
Q: Nullable is in 2.0?
A: It is! Including the new C# syntax, e.g. int? x = null; We expect most people to deal with nullable types at the language level, not necessarily working directly with Nullable, although that's obviously possible, too.

Krzysztof Cwalina (Expert):
Q: about the trade-offs of less-readable code and hidden dynamic assemblies, which are difficult to debug when things 'go wrong'.
A: We do have a guideline that basically says that things should be hidden only if they can be hidden completly (or pretty close to). I would say that for dynamically generated assemblies, it should be understood as saying that unless you can generate an assembly that does not need to be debugged by the user (in large majority of scenarios), you should not do it.

Brad Abrams [MS] (Expert):
Q: Have the team started to look at language changes in the Orcas version of vb.net. I'm sure you can't reveal much about it, how excited are you about the next 'next' version.
A: Well, i am not on the VB team, so I am not sure what they are thinking exactly. But the general goal is to make VB a more productive, more RAD tool. On the CLR side, we are looking a lot at scripting languages.. and how we can support them better on the CLR.

Jonathan Keljo [MS] (Expert):
Q: Will C#'s int continue to map to Int32 on 64bit Framework?
A: Yes--int will be Int32 on all platforms, long will be Int64 on all platforms. IntPtr will be 32 bits on 32-bit and 64 bits on 64-bit.

Joe Duffy (Expert):
Q: Will C#'s int continue to map to Int32 on 64bit Framework?
A: Yes--this is standardized as part of our ECMA specs. We will never change the mapping between our primitive data structures and storage capacity to be depoendent on the hardware... look for an Int128 just in time to support the new 128-bit processors... ;)

Krzysztof Cwalina (Expert):
Q: The trend, with ASP.NET 2.0 and ultimately with Avalon is the shift to 'declarative programming' (markup based), resulting in hidden compiled assemblies. Do you see this as an improvement or just a change in the way user interfaces are developed, and what
A: As I said, I think there needs to be a balance here. If the generated code needs to be understood/debugged/etc rarely, I see it as an improvement.

Jonathan Keljo [MS] (Expert):
Q: When they say you can do strongly typed code in yukon, TSQL is still an untyped language and only the .net assemblies that can be invoked from yukon are strongly typed right?
A: None of the experts in this chat are particularly closely involved with the Yukon effort, however I believe that is correct. TSQL is still TSQL; it's just you can call managed code from it now.

Brad Abrams [MS] (Expert):
Q: within the 2.0 framework, do you think the differences in c# and vb be more pronounced? Do you think it will be easier for development teams to make the call regarding language quickly?
A: I do think that each language will "come into its own" more... but I also think that we are not backing away from the single framework accessible to all languages... that is support important such that new innovations are available to all developers at the same time.

Joe Duffy (Expert):
Q: Joe: good deal. I find developers that copy and paste code from MSDN samples with very little tweaking...then they start writing code like they see in the samples...Unfortunately, you play how your practice. :-)
A: Oh yes... A surprising number of developers do copy&paste; snippets from the SDK. Which is great!--it just validates that the samples we ship are meaningful and help people get stuff done. This is actually one of the most compelling reasons to be FxCop clean on the samples. Of course, following your own guidelines is always a good thing, too. :)

Krzysztof Cwalina (Expert):
Q: Nullable is in 2.0?
A: Yes. It shipped in the Beta.

Brad Abrams [MS] (Expert):
In case you didn't see it you can read my comments on the spot here: https://blogs.msdn.com/brada/archive/2005/01/31/363837.aspx

Brad Abrams [MS] (Expert):
So I am surpriesed known one wants to talk about the K, V naming issues with generic types... Do folks think we made a good call here? https://blogs.msdn.com/kcwalina/archive/2004/11/04/252473.aspx

Krzysztof Cwalina (Expert):
Q: Older interfaces do not encourage strongly typed programming and generic classes/interfaces do. So are the non templated(non generic) interfaces going to be obsolete?
A: Generic interfaces will definatelly replace lots of scenarios where non generic interfaces were usied in the past. But they will not replace all scenarios. For example, non-generic interfaces are a very good mechanism to get common type across constructed generic types (generic instantiations). For example, we will be uisng IEnumerable as a common "top type" for all collections (including generic collections). Note that IEnumerable<Object> cannot be used as such top type because for example Collection<String> cannot be cast to IEnumerable<Object> (or Collection<Object> for that matter)

Joe Duffy (Expert):
Q: What are your thoughts on using Exceptions in n-tier apps as a means of a business rule check failing (like Duwamish books)? Does it make sense to have a XBusinessRuleException derived from Exception that gets caught on the UI level?
A: It seems that exceptions are the logical choice here--e.g. having some Invariant() method which throws if some state isn't right. It really depends on a number of things, like when you're performing validation, what granularity of the checks, and so on. But the alternatives don't seem as attractive, e.g. error codes. It'd be interesting to see what the MS Biz Framework (MBF) team does. I don't have a URL, but if you google a bit, you'd likely find something. Also check out the Patterns&Practices; articles on MSDN (https://msdn.microsoft.com/architecture/) -- I would imagine they cover this very topic.

Brad Abrams [MS] (Expert):
Q: Brad can you elaborate on "come into its own" a bit more... please.
A: Sure, what I mean is the that each language (and more importantly tool) will hit its target audience better... sorry, I can't name specific features at this time.

Krzysztof Cwalina (Expert):
Q: Nullable class and Nullable(Of T) struct can you explain?
A: Nullable class is just a static method holder with several helper methods that can manipulate Nullable objects. We could have put all the static members on Nullalbe and make then instance members, but that would add a bunch of rarely used methods to every instance of Nullable.

Krzysztof Cwalina (Expert):
Q: I agree with the call on using K,V and T naming issues with generic types.
A: I am glad to hear that. :-)

Brad Abrams [MS] (Expert):
Q: Will I be able to do the same thing in .net 2.0 to gain access to the 'MY' namespace???
A: I am a big "My" fan... and I do want to see it more generally accessible across the languages. There are really two parts of My... there is the set of libraries and the set of language\IDE features. The Libraries are just managed code so you can access them form any .NET language. The language\IDE features require updates to the compilers and tools, so those will have to wait until a future version.

Joe Duffy (Expert):
Q: Do you think that the implementation of generics will be heavily misused in mainstream development and create the same kind of problems in projects that variant types produced pre .NET?
A: I don't, for a number of reasons. First, I don't believe most mainstream developers will actually write their own generic types. They'll likely stay at a surface level, and simply consume the generic types we provide. In some circumstances, after someone has been working with these framework types for a while, the chance that they'd jump to writing their own generic types would increase substantially. But, second, and more importantly, the key difference is that generic types are fully type safe. Variant types are different--they're late bound and enable you to compile code that can fail at runtime. Generics don't comprimise type safety, and therefore you get a lot of benefits of static typing.

Brad Abrams [MS] (Expert):
Q: Brad, I appreciate that, but the worrying trend is vb.net more for the hobbiest c# for the professional, take code snippets V refactoring. Can i have some assurance this is not the case and as a MCSd.NET in vb.net i shouldn't have to be looking at c# as it
A: make not mistake -- VB is a first class language on the platform -- it is NOT just for hobbiest.

Brad Abrams [MS] (Expert):
Q: What is the target audience of C# and should advanced VB.NET Developers consider moving to C#?
A: I am not the right guy for the C# vs. VB debate... what I can tell you is that we design the platform to work very well for each... and that the breadth of the platform is designed such that it works very well for you if you are a C# or a VB developers..

Joe Duffy (Expert):
Q: Joe: Yeah, I've gone around and around about the "error codes vs. exception performance" issues and I agree with you. I guess much like error codes, either way the consumer of the "API" has to know either what error code to check or what exceptions to...
A: Agreed. There are some fancy-shmancy designs you can think up... For really rich business objects where a call to Invariant() or CheckInvariants() could fail due to a number of conditions, for instance, you could create a custom exception type which had a List property containing all of the failures. Then you have to worry about handling a single exception, and can extract the failure information to report back to the UI or whatever interface you're using (web svc, etc.). Lots of cool things you can do, but whatever it is, I'd tend to rely on our exceptions to implement it. Hope this helps.

Krzysztof Cwalina (Expert):
Q: What is the target audience of C# and should advanced VB.NET Developers consider moving to C#?
A: Unfortunatelly, I have to run to a meeting. Thanks for all the questions and I am sure Joe, Brad, and Jonathan will be able to pick my threads.

Brad Abrams [MS] (Expert):
Q: Yes, we keep hearing that VB.NET is a first class language. But how do you define it's target audience?
A: Sorry, I am not the right guy to define the target audience for VB vs. C#.... what do you think it should be?

Brad Abrams [MS] (Expert):
Q: Brad. Thanks - heres to refactoring in Orcas...
A: Ahmen!

Brad Abrams [MS] (Expert):
Q: DIm i As Integer
A: I am not sure I get the question...

Jonathan Keljo [MS] (Expert):
Q: I understand you don't want to list the specific JIT optimizations. Can you elaborate (or is there some place that talks about) the general optimizations?
A: As you guessed, we can't really list everything. Also, the JITs for various platforms and NGEN all have different capabilities. The JIT does do many of the common optimizations you'd expect--inlining, dead code elimination, common subexpression, hoisting, etc. Here are some links that talk about it a bit more: https://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/highperfmanagedapps.asphttps://blogs.msdn.com/davidnotario/

Brad Abrams [MS] (Expert):
Q: I am not sure this is the right question for this chat...
A: For me, it is generics... I think it has the biggest impact on API design....

Brad Abrams [MS] (Expert):
Q: Whats the most exciting thing in 2.0 for each of you?
A: For me it is generics... It has the most impact on API design...

Joe Duffy (Expert):
Q: (continued) .. handle. It would be nice if there was some easy way to figure out what method throws what exception without looking at the code or the docs specifically. Maybe I'm missing something. :-) Also, I'll check out the architecture site. Thx
A: Agreed. We've discussed among the team how to best determine and tell developers what exceptions a method can throw (and enable developers to do similar things for their own code)... I'm a Java guy and relly miss checked exceptions. *duck for cover! ;)* It's likely we could do something better in our docs to cover this at some point in the future. It's tricky due to late-bound calls and infrastructure-generated exceptions. I have a brief blog entry about a tool I wrote that generates an HTML report of the exceptions a target method could throw: https://www.bluebytesoftware.com/blog/PermaLink.aspx?guid=0687c3a0-0fbf-4970-8cbf-c0a15f93bd1e. I intend to wrap up work on it and release it at some point.

frankred [MS] (Moderator):
Q: The sessions seem to be in the seminar/en/20040929.... path, are all the sessions available already or do we need to wait months to get all the goods? ;)
A: You'll have to wait to get the goods! ;-)

Jonathan Keljo [MS] (Expert):
Q: Whats the most exciting thing in 2.0 for each of you?
A: I'm also a big fan of generics, but I'm going to have to go with the new features in the debugging space...Edit and Continue, intercepting exceptions, hiding non-user code, visualizers, that sort of thing. Some of those are things my team worked on directly by providing support in the CLR Debugging API, and others are new whiz-bang VS features.

Joe Duffy (Expert):
Q: FXCop indicates that my exceptions should not be derived off ApplicationException, but that isn't what is being taught. Is FXCop incorrect, or should we be SystemException? (TypesShouldNotExtendCertainBaseTypes)
A: We don't recommend that people inherit from AppException mostly because it adds little (no?) value, and just inserts yet another type in your hierarchy. You would never (or shouldn't at least) want to catch (AppException) and do something meaningful. If you want to factor your exception hierarchy so a grouping of exceptions can be caught by their basetype, you should do that through another mechanism. Some minimal additional info here: https://blogs.msdn.com/brada/archive/2004/03/25/96251.aspx. Where are you hearing guidance that indicates otherwise?

Joe Duffy (Expert):
Q: Joe: yeah it does help, thx. BTW - I like your blog. :-)
A: Thanks! Glad it helped!

Brad Abrams [MS] (Expert):
Q: In the above code when l=i is allowed implicitly why is the nullable conversion not allowed implicitly? Dim i As Integer
Dim l As Long
l = i
Dim x As Nullable(Of Long)
x = Nullable.FromObject(Of Integer)(23)
A: So you are asking why we don't have an implicit converstion from Nullable to Nullable? It seems to work well with C#, I will follow up with the VB folks and ask...

Brad Abrams [MS] (Expert):
int? i = 10 ;
long? l;
l = i;

Brad Abrams [MS] (Expert):
Q: As a question regarding this whole series, as a UK developer i've gotten an awful lot from this whole series of presentations and the subsequent chats, are there any plans to give these talks in the UK or Ireland? I'd certainly be in attendance.
A: Hey, thanks for the invite! We will keep that in mind...

Joe Duffy (Expert):
Q: Joe Duffy, the question was correct in stating that guidelines in the beginning dictated that custom exception be inherited from ApplicationException. I've seen it in many places, but of course know now that isn't the case.
A: Ahh, I see. Minsunderstood. We do tend to change our guidelines as we "get smarter" from release to release... Hopefully we're going in the right direction (and don't flip flop back and forth too much ;))!

Brad Abrams [MS] (Expert):
Q: errr, i dunno if i should ask here. I haven't touched the .net framework properly yet, should i wait and start fiddling with .net 2.0 and the Express products or dig in now?
A: Why wait? do both! Go dig in right now and play with the Beta or CTP drops of the Express skus for 2.0... They are very productive even in beta.. you can find a download link from https://www.msdn.com

Joe Duffy (Expert):
Q: Will types ever be extended to include XML oriented types? i.e., Will a DateTime ever completely map to xs:dateTime ... ?
A: You might be interested in checking out the COmega project, which brings first class XML support into the type system. https://research.microsoft.com/Comega/. Truthfully, I'm not terribly familiar with mapping DateTime instances onto xsd:dateTime elements... Where does our support break down?

Brad Abrams [MS] (Expert):
Q: Brad you might not want to touch this question with a 10ft pole, but...any thoughts on naming ASP.NET controls. I realize a page isn't the same as an API, but I have this debate as you can imagine. I know hungarian notation is out, but I seem to prefer...
A: Well, you are right in that this gets us into the internal coding guidelines discussion we had last week. https://blogs.msdn.com/brada/archive/2005/01/26/361369.aspx so I have no official answer, but I will say I have personally written some "textBoxFirstName" code in my day ;-)

Jonathan Keljo [MS] (Expert):
Q: Jonathan when will you start blogging?
A: For the most part the defaults ought to make sense. If an exception goes unhandled, the IDE will stop. If you want to stop at the time the exception is thrown, you can usually use the dialog to flip a bunch of types at once. Also, the exceptions dialog has been one of the areas the VS guys have been tweaking heavily throughout 2.0; I think there's a quick menu option now to do what you describe. It's worth checking out the latest VS Community Technology Preview and posting some suggestions on the MSDN Feedback Center.

Jonathan Keljo [MS] (Expert):
Q: toggle catching or not all exceptions or a user define list that could be toggled... Opening the Exceptions is just to mutch work... Maby something in code could toggle it
A: Whoops...silly tool. Meant the response to go here: For the most part the defaults ought to make sense. If an exception goes unhandled, the IDE will stop. If you want to stop at the time the exception is thrown, you can usually use the dialog to flip a bunch of types at once. Also, the exceptions dialog has been one of the areas the VS guys have been tweaking heavily throughout 2.0; I think there's a quick menu option now to do what you describe. It's worth checking out the latest VS Community Technology Preview and posting some suggestions on the MSDN Feedback Center.

Joe Duffy (Expert):
Q: Can delegates be handled asynchronously for Observer/Observable behaviour that doesn't stop the main thread?
A: By handled do you mean invoked? In general, yes, if you take a look at the delegates the C# compiler emits, they will have a Begin/End invoke method. This follows the pattern for async method calls and implicitly uses the thread pool to complete the work. This avoids using the main thread for the actual work, although it is responsible for handing off the initial delegate invoke (very minimal work required).

Jonathan Keljo [MS] (Expert):
Q: Jonathan when will you start blogging?
A: As soon as my boss hires another PM to help me with the Debugging API! If you're interested feel free to send me a resume...

Brad Abrams [MS] (Expert):
Q: Brad - well, since they are protected I figured I'd at least TRY to draw you into the debate. :D
A: ;-)

Jonathan Keljo [MS] (Expert):
Q: When some method throws an exception there is no way to tell what state the object is left in. Does MSFT have any guidelines for this? Would it be sensible for exceptions to contain a flag specifying guaranteed state?
A: We don't have any guidelines on that per se, yet. However I think a flag specifying guaranteed state of the object can be useful.

Brad Abrams [MS] (Expert):
Q: Yes the following c# code works fine. But the intellisense in VC# when I type long? and hit space it starts giving me all the typenames but I want to write a variable name. So I had to hit escape and then type the variable name x int he following example. int i = 23;
long l;
l = i;
long? x;
x = Nullable.FromObject(23);
A: Well, at least that seems to be fixed i the lastest drop...

Joe Duffy (Expert):
Q: Support breaks down when you get into the massive number of types and their formats that the schema definition language supports. Mapping all of them is impossible, coming up with something thats reasonable is arbitrary. i dont think its doable
A: I agree--the type system XSD uses is awesomely composable. A lot of the COmega work (used to be Xen, and then X#) is intending to solve this problem. Don't look for anything in the Whidbey timeframe, but lots of folks are actively researching this very problem.

Brad Abrams [MS] (Expert):
Q: have either of you looked at the enterprise library? just curious :)
A: Not deeply... what do you think of it?

Joe Duffy (Expert):
Q: When creating part of an object model, should DataSet be avoided and collections be preferred for better typing? What about Typed-DataSets?
A: This is very rocky ground. :) I would recommend reading the Patterns & Practice information available at https://msdn.microsoft.com/architecture/. IMHO, I would avoid DataSets in the biz tier to as much an extent as possible. They're powerful and flexible enough for marshalling data, but I am a patterns wonk... therefore, I never want those things to surface. With that said, the data folks have done a great job on their types, and would probably recommend differently.

Jonathan Keljo [MS] (Expert):
Q: Will users still get the annoying "exception has occured..choose an app to debug the application in" if you have event handlers for those nasty exceptions, in 2.0 ? I guess this is a CLR issue...
A: In 2.0 you'll get a prettier dialog, much like the one that pops up in Windows XP when a native app crashes. It will have a debug button that will launch a debugger (if one is installed), a send button that will send an error report, and a "don't send" button that will dismiss the dialog. You can see this in the latest previews if you just install the SDK (and not VS). Check out https://www.microsoft.com/en-us/default.aspx for information on how to get ahold of those error reports.

frankred [MS] (Moderator):
It looks like we're about out of time. I hope everyone had a good time and got answers to all of their questions. If you have more questions please visit the CLR team blogs https://msdn2.microsoft.com/en-us/netframework/aa569259.aspx section on the .NET Framework developer center. Please join us again next Wednesday for the next chat in the Designing .NET Class Libraries https://msdn2.microsoft.com/en-us/netframework/aa497250.aspx series.

Jonathan Keljo [MS] (Expert):
Q: Why is it that in structs with ExplicitLayout, value and reference types can't overlap?
A: If the value type and the reference type could share the same spot in the struct, you'd be able to corrupt the pointer to the reference type, which would really confuse the garbage collector.

Joe Duffy (Expert):
Q: Is there any easy way to validate an xsd structre to the result of a sql query?
A: Not sure what you mean by validate to a result... You can certainly (even better support in Yukon, SQL Server 2005) marshal XML across the wire as a result of either XML update-grams or SQL. Further, you can define custom datatypes using XSD in Yukon. So given that, I would imagine there are many interesting things you can do here marrying the database with XSD... I'd recommend googling for some information on Yukon and XSD support. Also, check out https://msdn.microsoft.com/data/.

Brad Abrams [MS] (Expert):
Q: Why is it that in structs with ExplicitLayout, value and reference types can't overlap?
A: Well, it has been fun folks, thanks! See you next week... I will be logging in from Dallas, see you then!

Jonathan Keljo [MS] (Expert):
Thanks everyone, it's been fun!

Joe Duffy (Expert):
Awesome chat session. Thanks for stopping by... See you next time!

frankred [MS] (Moderator):
Q: is there time to ask off topic questions or is there somewhere we could e-mail the experts from here?
A: Feel free to send me mail at franked@microsoft.com and I'll forward to the appropriate folks for a response.

frankred [MS] (Moderator):
Q: is that franked@ or frankred@ ??
A: Sorry, that's frankred@microsoft.com

frankred [MS] (Moderator):
Q: Great session, thanks for your time guys
A: Thanks for joining us!

frankred [MS] (Moderator):
Q: Thanks guys, keep blogging
A: Thanks for joining us!

frankred [MS] (Moderator):
Q: and thanks for the awesome feedback. this exchange rocks! :)
A: Thank you! Hopefully, you'll join us again next week.

Top of PageTop of Page