On Wednesday, 20 January 2016 at 23:35:31 UTC, Manu wrote:
On 21 January 2016 at 01:32, Simen Kjaeraas via Digitalmars-d <[email protected]> wrote:
On Wednesday, 20 January 2016 at 12:47:44 UTC, Manu wrote:

2. Multiple modules cannot have the same name in D.



I'm not sure what situation you're imagining where modules would be created with the same names...?


How do you plan to map C++'s standard lib ? One giant hundred of thousands of line C++ file ?


Surely it would map by file.

#include <vector> -> import stl.vector;
#include <map> -> import stl.map;
#include <string> -> import stl.string;

Perhaps 'stl' may be something else, 'std' is an unfortunate conflict with phobos, but this is unique to this case.


I believe deadalnix here meant something like this:

  import stl.vector;
  import mylib.vector;

  Vector a; // Ambiguous: could be from mylib or stl
  stl.Vector b; // Error: no such class stl.Vector
  stl.vector.Vector c; // Works, but requires extra typing

Okay let me tweak your code:

   import stl.vector;
   import stl.string;   // one more thing; when do you ever only
import a single module?
   import mylib.vector;

   Vector a; // Ambiguous: could be from mylib or stl
stl.Vector b; // Error: this wouldn't work, becase stl could be stl.vector.stl or stl.map.stl
   stl.vector.Vector c; // This is what a D programmer expects,
exactly like every other conflict resolution in D ever, but it doesn't work either

[snip]

Which with working namespaces might allow case b to work.

I hope I've shown how it almost never does, and only makes the situation worse.

I'm playing devil's advocate here, since I fully agree with you
that there is absolutely no need for C++ namespaces in D, and
that the cost in language complexity is too high.

Suppose that case b above worked, though - instead of a conflict,
lookup would basically merge namespaces with the same name, and
only conflict if there are multiple definitions that are not
namespaces.

On the one hand, I hope that's how it's supposed to work,
otherwise it's just silly. On the other hand, that's a clear break
with D's current lookup rules, and for what I consider very, very
little benefit.

--
  Simen

Reply via email to