full path to source file __FILE__

Jonathan M Davis via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Jul 22 17:48:35 PDT 2016


On Friday, July 22, 2016 19:28:05 Jonathan Marler via Digitalmars-d-learn 
wrote:
> Actually I realized if __FILE__ was always absolute, then all
> your exception messages would contain the full path of the file
> it was thrown from on the machine it was compiled on. This would
> be quite odd.

In some cases, it could also be viewed as a security risk. For instance, on
*nix systems, it would almost certainly give away the username of the user
that built it.

Also, it would result in needlessly long error messages when exceptions were
thrown, which could impact performance as well as making log files that much
more annoying.

I'm definietly inclined to think that making __FILE__ absolute would be a
mistake. Maybe something else like __FILE_ABSOLUTE__ would be okay, but in
this particular case, I'd argue that you should just not make it a script if
you need additional files that are next to it rather than in a known place.
And as far as your example of build files goes, it's normal to have to run
stuff like that in the directory where it lives (e.g. that's what happens
with make), so while I understand that it may be annoying, I don't think
that it's a compelling use case for changing what __FILE__ does.

- Jonathan M Davis



More information about the Digitalmars-d-learn mailing list