Naming Namespaces

Public forum to share code snippets, screen shorts, experiences, etc.
Post Reply
Frank Maraite
Posts: 178
Joined: Sat Dec 05, 2015 10:44 am
Location: Germany

Naming Namespaces

Post 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
User avatar
wriedmann
Posts: 3759
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

Naming Namespaces

Post 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
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
User avatar
Otto
Posts: 174
Joined: Wed Sep 30, 2015 6:22 pm

Naming Namespaces

Post 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
Frank Maraite
Posts: 178
Joined: Sat Dec 05, 2015 10:44 am
Location: Germany

Naming Namespaces

Post 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
Frank Maraite
Posts: 178
Joined: Sat Dec 05, 2015 10:44 am
Location: Germany

Naming Namespaces

Post by Frank Maraite »

Otto,

good point!
User avatar
Chris
Posts: 4926
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Naming Namespaces

Post 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
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
Post Reply