The Artima Developer Community
Sponsored Link

.NET Buzz Forum
Do you think .NET namespaces are good to go?

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Jonathan Crossland

Posts: 630
Nickname: jonathanc
Registered: Feb, 2004

Jonathan Crossland is a software architect for Lucid Ocean Ltd
Do you think .NET namespaces are good to go? Posted: Jan 13, 2009 3:17 PM
Reply to this message Reply

This post originated from an RSS feed registered with .NET Buzz by Jonathan Crossland.
Original Post: Do you think .NET namespaces are good to go?
Feed Title: Jonathan Crossland Weblog
Feed URL: http://www.jonathancrossland.com/syndication.axd
Feed Description: Design, Frameworks, Patterns and Idioms
Latest .NET Buzz Posts
Latest .NET Buzz Posts by Jonathan Crossland
Latest Posts From Jonathan Crossland Weblog

Advertisement

Namespaces offer categorization within your classes and assemblies. Two assemblies could be adding to 1 or more namespaces. But are you not increasing getting two problems.
More and more classes in more and more namespaces. After you look at the Enterprise Library or one of your own applications, or Object Models to give to a client, I bet you have many Types you wish you could hide from them.

Except for adding MyNamespace.Data or some other categorization, a namespace is pretty much useless. They cannot be made private, internal or anything else.

[code:c#]
Namespace MyNamespace
{
  //they are always public - no modifiers or accessors allowed.
}
[/code]


What I find confusing, is how we can get complex features like Generics, but not easier features like namespace control.

The problem

As the .NET Framework grows, and it is continuously, we need to be able to better facilitate visibility across our Assemblies.
If you add the number of Types within the number of Namespaces that you reference compared with Types within those Namespaces that you actually use, you will probably find a huge range from project to project.

ActualUsed(Namespaces) is a subset (⊂) of

Total (Namespaces).

How would you write it as an insignificant subset?

When you get your Intellisense window up, you are confronted with miles of Type Definitions, that not only do you not need, but the developer probably never wanted you to actually see it either.

I touched on visibility of classes and members in a previous post regarding Modifiers and InternalsVisibleTo which is not the answer. (although a lot of people seem to site it as a silver bullet, its actually limited.)

What we need is to be able to mark a Namespace with private and internal etc.
We can therefore hide classes within these from the client. Also the whole "x is less accessible than y" needs to be looked at.

Problems

If a Type X has a Property of Type Y. X is contained within Public Namespace, but Y was declared within an "Internal Namespace", it should compile and run without problem. The user should then only see TypeY when in the context of TypeX.

The above rule in psuedo code:
[code:c#]

public class client
{
  //from intellisense
  //visible 

  MyNamespace.TypeX
  MyNamespace.TypeX.TypeY.Name // TypeY creatable because its created by TypeX
  

  //NOT Visible - ie. Not creatable 
  MyNamespace.Data.TypeY - 
  
  //TypeY not creatable because it cannot be created outside of TypeX
}

public namespace MyNamespace
{
    public class TypeX
    {
        //Accessible and visible to this Assembly as TypeX.TypeY and 
        public TypeY Property
        {
            get 
            { 
                return _Property;
            }
            set 
            { 
              _Property = value;
            }
        }
    
    }
}

//Accessible and visible to this Assembly
internal namespace MyNamespace.Data
{
    //Accessible and visible to this Assembly as MyNamespace.Data.TypeX
    public class TypeY
    {
        public string Name
        {
            get 
            { 
                return _Name;
            }
            set 
            { 
              _Name = value;
            }
        }
    }
}
[/code]


Conclusion

None of this would change the way you currently do things, just enable you to better fine tune it. If we have the power (including the .NET Framework libraries to change what is visible in this way, we will be reducing the amount of types and namespaces presented to us within intellisense. We would be able to present a smaller amount of Types and namespaces to our clients (they do get confused or rather scared of something large). Microsoft would benefit from making the .NET Framework appear smaller that it is, programmers would not see namespaces they dont need to see.

Read: Do you think .NET namespaces are good to go?

Topic: Microsoft Tag Previous Topic   Next Topic Topic: CES 2009 Opening Keynote Address

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use