fbpx
× Share your code snippets, screen shots etc. here

Naming Namespaces

More
2 years 3 months ago #1 by Frank Maraite
Naming Namespaces was created by Frank Maraite
This message is inspired by the global:: example Robert showed in his beta 7a announcement.

It adresses the confusion/trouble we get if our namespaces conflict with namespaces introdused by other people. In case of the System namespace it may be a fault by ourself. But where should we place classes, that indeed belong to our own 'System'? The answer is clear:

Put your name/your company name in front of your own namespace!

All my namespaces begin with (obvious) 'FrankMaraite.'. I have, for example

FrankMaraite.CadBase
FrankMaraite.ViewModels

or, to match the example

FrankMaraite.System

or

FrankMaraite.MyApp1.System

Doing this is much clearer to read then using global::System or something like this.

Frank

Please Log in or Create an account to join the conversation.

More
2 years 3 months ago #2 by Wolfgang Riedmann
Replied by Wolfgang Riedmann on topic Naming Namespaces
Hi Frank,

ideally the namespace prefix would be inspired by the inverted internet domain of the company, in my case

it.riedmann

but I have given up this idea - too much to write, and since the name of the library assemblies should reflect this also, I have opted for a shorted form

rdm

so one of my libraries is called rdm.BaseLib.dll, and is using the namespace rdm.BaseLib.

Wolfgang

Please Log in or Create an account to join the conversation.

More
2 years 3 months ago #3 by Otto Christiaanse
Replied by Otto Christiaanse on topic Naming Namespaces
https://msdn.microsoft.com/en-us/library/ms229026(v=vs.110).aspx we (try to) use the MS standard.
For example: Piramide.IVPA.CommunicationLayer

Please Log in or Create an account to join the conversation.

More
2 years 3 months ago #4 by Frank Maraite
Replied by Frank Maraite on topic Naming Namespaces
Hi Wolfgang,

I put the namespace in the app properties. One assembly, one namespace, nothing to type twice. The same with assembly name.

For the #using statements is the header.cfg useful.
In in case of very few dependencies, only a few #using's. This comes together with decoupling the code.

Frank

Please Log in or Create an account to join the conversation.

More
2 years 3 months ago #5 by Frank Maraite
Replied by Frank Maraite on topic Naming Namespaces
Otto,

good point!

Please Log in or Create an account to join the conversation.

More
2 years 3 months ago #6 by Chris Pyrgas
Replied by Chris Pyrgas on topic Naming Namespaces
Hi Frank,

Not saying that you should use this, but just in case you need it sometime, in XIDE, from the menu Application/Advanced you can find a "Add #using directives" option, this allows you to add a certain "using <namespace>" in all prg files automatically. "Remove #using directive" obviously removes the one you specify from all .prg files. There's also a "Add BEGIN NAMESPACE" option, which could be handy in some cases as well.

hth,
Chris

XSharp Development Team
chris(at)xsharp.eu

Please Log in or Create an account to join the conversation.