Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why there is a convention of declaring default namespace/libraries in any programming language?

Why don't any programming language load the default libraries like stdio.h, iostream.h or using Systemso that there declaration is avoided?

As these namespace/libraries are required in any program, why the compilers expect it to be declared by the user.

Do any programs exist without using namespace/headers? even if yes, whats wrong in loading a harmless default libraries?

I don't mean that .. I am lazy to write a line of code but it makes less sense (as per me) for a compiler to cry for declaration of so called default thingummies ending up in a compilation error.

like image 846
InfantPro'Aravind' Avatar asked Nov 17 '10 10:11

InfantPro'Aravind'


4 Answers

It's because there are programs which are written without the standard libraries. For example, there are plenty of C programs running on embedded systems that don't provide stdio.h, since it doesn't make any sense on those platforms (in C, such environments are referred to as "freestanding", as opposed to the more usual "hosted").

like image 178
caf Avatar answered Oct 05 '22 23:10

caf


The “default” libraries are not “required in any program”, and indeed there are many cases where they are not even available (operating system kernel/drivers, microcontrollers, etc). And more in the mainstream, many high-level graphical programs use system-specific GUI/graphics libraries instead of standard I/O.

like image 38
Arkku Avatar answered Oct 05 '22 23:10

Arkku


For stdio.h/iostream(.h): the quick answer is that in the biggest part of your software, they are not needed (definitively not both). Headless devices/servers should having a logging module instead and GUI's don't always have a console to interface with.

like image 24
stefaanv Avatar answered Oct 05 '22 23:10

stefaanv


Many languages (especially scripting languages, and languages that carry a standard runtime as part of the language spec) do do this.

The trade-off is convenience versus software-engineering goodness. The problem with opening namespaces by default is you end up with a lot of names being available immediately at the top level, which can cause name clashes and confusion, pollute Intellisense/autocompletion lists, etc.

like image 27
Brian Avatar answered Oct 05 '22 23:10

Brian