Could you detail namespace declaration management ?

+2 votes
asked Oct 17, 2019 in Question / help by nvierge
I am disappointed by the management of the namespaces and don't really understand how it works.

For example, the following diagram is OK:

@startuml

namespace fr.site {
}

namespace net {
}

namespace net.entities {
}

namespace net.controllers {
}

namespace net.db {
}

@enduml

But this one is not for me:

@startuml

namespace net {
}

namespace net.entities {
}

namespace net.controllers {
}

namespace fr.site {
}

namespace net.db {
}

@enduml

I don't understand why fr.site is nested in net. I would have specify net.fr.site to do this...

Another example:

@startuml

namespace net {
}

namespace net.entities.sub {
}

namespace net.entities {
}

@enduml

net.entities.sub is not nested. Why ?

Generally, namespaces seems to be very sensitive to order. In my opinion, it is very annoying with large diagrams.

1 Answer

+1 vote
answered Oct 18, 2019 by plantuml (294,960 points)

This is partially solved in last beta.
http://beta.plantuml.net/plantuml.jar

All those bugs are caused by a bad design decision made 10 years ago :-(

Maybe it's time for us to move forward.
So here is our new proposal:

Merge the notion of package/namespace in PlantUML so that package/namespace will be synonymous and behave as in all regular programming languages.

If we take the actual result of example 0:

@startuml
'Example 0
namespace net {
  class foo1
}

namespace net.entities {
  class foo2
}

namespace net.entities.sub {
  class foo3
}
@enduml

Which image would you prefer ?
Image A
http://www.plantuml.com/plantuml/png/KtUjICmjo4bLCE3AIynDBIv8J4vLo4ijKQZcKb18paaiBbP8oyytvAhbGfNNIyqhoIp9J2r6LMY4Mw5USMaIgc9Zhbe0

Image B
http://www.plantuml.com/plantuml/png/SoWkIImgAStDuL9thKZCBSX9LJ3WAaXCpavCJrN8IorHgEPIK4ZEIImkLaZBppVaGfRJIyqhoIp9J2r6LMG4v00HDeLwnQL9OCL8oes1t5ekC57BvP2Qbm9q3000

Following this proposal, example 1, example 2 and example 3 will print the same result as example 0 (but you have to choose between Image A or Image B)

@startuml
'Example 1
package net {
  class foo1
}

package net.entities {
  class foo2
}

package net.entities.sub {
  class foo3
}
@enduml

or

@startuml
'Example 2
package net {
  class foo1
 
  package entities {
    class foo2
    
    package sub {
      class foo3
    }
  }
}
@enduml

or

@startuml
'Example 3
class net.foo1
class net.entities.foo2
class net.entities.sub.foo3
@enduml


Do you agree with our proposal ?

Which image (A or B) are your expecting ?

We probably are going to put a doodle in place for users about it, because it slightly changes the bebaviour of PlantUML.
But we think this is a good change :-)

commented Oct 18, 2019 by cprn (230 points)
I'm not the op but I absolutely agree and personally prefer image A.
commented Oct 18, 2019 by nvierge

In my opinion, it is a good proposal but it would be great to have one "option" to choose how they are displayed: flat (like current packages) or nested (like current namespaces). If nested, another option could let the user choose between full name (image B) or relative name (image A).

If i have to choose, nested representation with relative names would be my choice (ideally default options). -> Image A

The following example is stil "buggy" with the current beta:

@startuml
package net {
  class foo1

  foo1 --> net.entities.foo2
}

package net.entities {
  class foo2

  foo2 --> net.foo1
}

package net.entities.sub {
  class foo3
}
@enduml

if you replace package with namespace, i get an error.

It should also be insensitive to the order of declaration

@startuml
namespace net.entities {
  class foo2
}

namespace net {
  class foo1
}

namespace net.entities.sub {
  class foo3
}
@enduml

 In this example, it is easy to declare packages in the "good" order. For complex diagrams with included files, it is more difficult :-)

commented Oct 18, 2019 by plantuml (294,960 points)

About the remaining bugs in last beta, PlantUML internal code is now too complex so it's really difficult to solve. The workaround is to change the order of your package declarations. I understand that it may not that easy to do for complex diagram. The good news is that it's a temporary issue since we are going to change all this code. So we don't want to spend too much time on it. Really sorry about that.

About the "option" you are mentioning, I think the right way will be to have the option to change the character used for separation.

It's difficult to explain, but easy to understand :-)

So let's take an example :

If you consider the following :

@startuml
'Since there are no "dot" in packages names, there are displayed flat
package net {
  class foo1
}

package net_entities {
  class foo2
}

package net_entities_sub {
  class foo3
}
@enduml

This is the expected drawing.

The only issue is that you don't want to print "underscore" but "dot" (I guess).

I think the right option here is the capability to change the character used for separation so that PlantUML would not interpret "dot" as separator.

@startuml
set separator $
'Now that the seperator is not "dot" but dollar, packages are going to be printed flat.
'You may also have "set separator none"

package net {
  class foo1
}

package net.entities {
  class foo2
}

package net.entities.sub {
  class foo3
}
@enduml

I think this is really the right way of solving all this complex situation about package/namespace.

But we need users' validation to be sure. So your feedback is highly welcome !

...