xsharp.eu • Naming Namespaces
Page 1 of 1

Naming Namespaces

Posted: Thu Oct 06, 2016 7:57 am
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

Naming Namespaces

Posted: Thu Oct 06, 2016 9:01 am
by wriedmann
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

Naming Namespaces

Posted: Thu Oct 06, 2016 10:04 am
by Otto
https://msdn.microsoft.com/en-us/library/ms229026(v=vs.110).aspx we (try to) use the MS standard.
For example: Piramide.IVPA.CommunicationLayer

Naming Namespaces

Posted: Thu Oct 06, 2016 10:40 am
by Frank Maraite
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

Naming Namespaces

Posted: Thu Oct 06, 2016 10:41 am
by Frank Maraite
Otto,

good point!

Naming Namespaces

Posted: Thu Oct 06, 2016 2:29 pm
by Chris
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