www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Does selective imports have an effect on the resulting executable?

reply "Gary Willoughby" <dev nomad.so> writes:
Does selective imports have an effect on the resulting 
executable? For example if i included the following at the top of 
my source to only include one function from a library:

import std.algorithm : reduce;

Would it have any impact on the resulting executable? i.e. only 
include compiled code for the selected functions?

If i imported the whole library like this:

import std.algorithm;

Is it more wasteful? Not as optimised? Any draw backs? Bigger 
executable?
Nov 28 2013
next sibling parent "Adam D. Ruppe" <destructionator gmail.com> writes:
On Thursday, 28 November 2013 at 12:31:11 UTC, Gary Willoughby 
wrote:
 Does selective imports have an effect on the resulting 
 executable?
No, I don't think so. The compiler still reads the module and the linker still sees the whole object file to do its thing, it just doesn't bring all the names into scope.
Nov 28 2013
prev sibling parent "Dicebot" <public dicebot.lv> writes:
On Thursday, 28 November 2013 at 12:31:11 UTC, Gary Willoughby 
wrote:
 Does selective imports have an effect on the resulting 
 executable? For example if i included the following at the top 
 of my source to only include one function from a library:

 import std.algorithm : reduce;

 Would it have any impact on the resulting executable? i.e. only 
 include compiled code for the selected functions?

 If i imported the whole library like this:

 import std.algorithm;

 Is it more wasteful? Not as optimised? Any draw backs? Bigger 
 executable?
No, selective imports are just matter of namespace hygiene and code readability. Scope-local imports , however, can impact resulting executable a lot if used inside templated scopes (nothing will be imported at all if it is not instantiated)
Nov 28 2013