C is Brittle D is Plastic

H. S. Teoh hsteoh at qfbox.info
Tue Mar 24 14:36:57 UTC 2026


On Tue, Mar 24, 2026 at 12:38:28PM +0000, user1234 via Digitalmars-d wrote:
> On Tuesday, 24 March 2026 at 10:36:19 UTC, Max Samukha wrote:
> > On Monday, 23 March 2026 at 23:48:27 UTC, Walter Bright wrote:
> > 
> > > So now we have a complicated 2-phase lookup that everybody likes.
> > 
> > Again, not everybody likes it.
> 
> I don't know what this "2-phases lookup system" is refering to (my
> interest in D started by 2014 let's say and I have the feeling that
> this is an older topic). What was the problem in first place ?

In the beginning, D's symbol lookup mechanism was very simple and
straightforward: whenever an import statement is encountered, symbols
from an imported module are loaded and injected into the symbol table at
the current scope.  This is straightforward to implement (you literally
translate "import xyz" as parsing xyz and adding its public symbols to
the current scope's symbol table).

However, that led to counterintuitive behaviours like:

	void main() {
		myFunc("abc");
	}
	void myFunc(string text) {
		writeln(text);	// prints "abc"
		import std.conv;
		writeln(text);	// prints ""
	}

Walter was very resistant to changing this behaviour, as all proposed
solutions involved "inelegant" complications in the semantics and
implementation of "import".  Eventually, however, the crowd prevailed
and Walter relented.


T

-- 
Why does a pound of hamburger have less energy than a pound of steak?  Because it is in the ground state.


More information about the Digitalmars-d mailing list