Advantages and disadvantes of implementing include/import/use in a compiler? -


a little of background: develop processors architectures @ university , implementing compiler. language have peculiar characteristics, in general other language: functions/methods, if else, variables, etc.

now, i've seen common in many languages use of include/import/use constructs. in language, there global namespace , thought: need implement kind of include construct in language? can't let compiler smart enough , figure out definitions are?

for instance, if compile code with

./mycompiler file1 file2 file3

and suppose file1 uses defined in file3. compiler has enough information figure out file1 needs found @ file3 (my compiler mult pass compiler). ask you: if compiler smart enough figure out definitions are, there advantage in typing explicitly include/import/use statement?

yes, works, assuming have single global namespace , okay compiler invocation listing files of entire program.

however, extremely undesirable state of affairs programs of nontrivial size. decomposing programs libraries , modules invaluable tool software development, , essential part of isolating these modules each other unless programmer intentionally , explicitly integrates them each other. having single global namespace dent in ideal, can't name things in 1 module independently how (or else) named things in module.

furthermore requiring list of files on command line silly. whoever builds program has know all files everywhere. includes files of third party libraries used, , libraries used those, , on. granted, list stashed away in build system file, because transitively includes files make final executable, still maintenance burden. gains absolutely nothing (it's net negative) on listing information in source files.

what sensible module systems (i.e., not #include) this: segregate program libraries , furthermore each library modules or (sub-)namespaces, , source code , directory structure describes, in decentralized fashion, how files on disk aggregated namespaces, modules, libraries. jane doe's third party library describes own structure , has own namespace, project can state "i use library foo" , it.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -