Why are standard libraries not programming language primitives?
I was thinking why are there (in all programming languages I have learned, such as C++, Java, Python) standard libraries like stdlib, instead of having similar "functions" being a primitive of the language itself.
programming-languages standard-library
New contributor
|
show 3 more comments
I was thinking why are there (in all programming languages I have learned, such as C++, Java, Python) standard libraries like stdlib, instead of having similar "functions" being a primitive of the language itself.
programming-languages standard-library
New contributor
1
What do you mean "why couldn't the compiler simply translate a function call into a set of instructions"? That's roughly what the compiler does, standard library or not (Ok, Python only partway and Java to JVM bytecode; similar concept). Standard libraries really don't have anything to do with the compilation of code -> instructions.
– Delioth
8 hours ago
12
@Delioth I think Simone is asking why isn't everything in the standard library of language $LANG a primitive construct/function of that language instead. I'd say it's a reasonable question for anyone who is very new to programming languages :)
– Andres F.
8 hours ago
@Andres Yes that's exactly what I mean :D
– Simone Broili
8 hours ago
12
The standard library generally fills the gap between a working programming language and a useful one that people will use.
– Telastyn
5 hours ago
2
A significant part of Python's standard library is actually written in C and already compiled.
– ElmoVanKielmo
4 hours ago
|
show 3 more comments
I was thinking why are there (in all programming languages I have learned, such as C++, Java, Python) standard libraries like stdlib, instead of having similar "functions" being a primitive of the language itself.
programming-languages standard-library
New contributor
I was thinking why are there (in all programming languages I have learned, such as C++, Java, Python) standard libraries like stdlib, instead of having similar "functions" being a primitive of the language itself.
programming-languages standard-library
programming-languages standard-library
New contributor
New contributor
edited 1 hour ago
Nicol Bolas
9,59742737
9,59742737
New contributor
asked 8 hours ago
Simone BroiliSimone Broili
596
596
New contributor
New contributor
1
What do you mean "why couldn't the compiler simply translate a function call into a set of instructions"? That's roughly what the compiler does, standard library or not (Ok, Python only partway and Java to JVM bytecode; similar concept). Standard libraries really don't have anything to do with the compilation of code -> instructions.
– Delioth
8 hours ago
12
@Delioth I think Simone is asking why isn't everything in the standard library of language $LANG a primitive construct/function of that language instead. I'd say it's a reasonable question for anyone who is very new to programming languages :)
– Andres F.
8 hours ago
@Andres Yes that's exactly what I mean :D
– Simone Broili
8 hours ago
12
The standard library generally fills the gap between a working programming language and a useful one that people will use.
– Telastyn
5 hours ago
2
A significant part of Python's standard library is actually written in C and already compiled.
– ElmoVanKielmo
4 hours ago
|
show 3 more comments
1
What do you mean "why couldn't the compiler simply translate a function call into a set of instructions"? That's roughly what the compiler does, standard library or not (Ok, Python only partway and Java to JVM bytecode; similar concept). Standard libraries really don't have anything to do with the compilation of code -> instructions.
– Delioth
8 hours ago
12
@Delioth I think Simone is asking why isn't everything in the standard library of language $LANG a primitive construct/function of that language instead. I'd say it's a reasonable question for anyone who is very new to programming languages :)
– Andres F.
8 hours ago
@Andres Yes that's exactly what I mean :D
– Simone Broili
8 hours ago
12
The standard library generally fills the gap between a working programming language and a useful one that people will use.
– Telastyn
5 hours ago
2
A significant part of Python's standard library is actually written in C and already compiled.
– ElmoVanKielmo
4 hours ago
1
1
What do you mean "why couldn't the compiler simply translate a function call into a set of instructions"? That's roughly what the compiler does, standard library or not (Ok, Python only partway and Java to JVM bytecode; similar concept). Standard libraries really don't have anything to do with the compilation of code -> instructions.
– Delioth
8 hours ago
What do you mean "why couldn't the compiler simply translate a function call into a set of instructions"? That's roughly what the compiler does, standard library or not (Ok, Python only partway and Java to JVM bytecode; similar concept). Standard libraries really don't have anything to do with the compilation of code -> instructions.
– Delioth
8 hours ago
12
12
@Delioth I think Simone is asking why isn't everything in the standard library of language $LANG a primitive construct/function of that language instead. I'd say it's a reasonable question for anyone who is very new to programming languages :)
– Andres F.
8 hours ago
@Delioth I think Simone is asking why isn't everything in the standard library of language $LANG a primitive construct/function of that language instead. I'd say it's a reasonable question for anyone who is very new to programming languages :)
– Andres F.
8 hours ago
@Andres Yes that's exactly what I mean :D
– Simone Broili
8 hours ago
@Andres Yes that's exactly what I mean :D
– Simone Broili
8 hours ago
12
12
The standard library generally fills the gap between a working programming language and a useful one that people will use.
– Telastyn
5 hours ago
The standard library generally fills the gap between a working programming language and a useful one that people will use.
– Telastyn
5 hours ago
2
2
A significant part of Python's standard library is actually written in C and already compiled.
– ElmoVanKielmo
4 hours ago
A significant part of Python's standard library is actually written in C and already compiled.
– ElmoVanKielmo
4 hours ago
|
show 3 more comments
7 Answers
7
active
oldest
votes
Allow me to expand somewhat on @Vincent's (+1) good answer:
Why couldn't the compiler simply translate a function call into a set of instructions?
It can, and does so via at least two mechanisms:
inlining a function call — during translation, the compiler can replace a source code call with its implementation directly inline instead of making an actual call to the function. Still the function needs to have an implementation defined somewhere and that can be in the standard library.
intrinsic function — intrinsics are functions that the compiler has been informed of without necessarily finding the function in a library. These are usually reserved for hardware features that are not practically accessible in any other way, being so simple that even the overhead of a call to assembly language library function is considered high. (The compiler can generally only automatically inline source code in its language, but not assembly functions, which is where intrinsic mechanism comes in.)
Still these being said, the best option sometimes is for the compiler to translate a function call in the source language into a function call in the machine code. Recursion, virtual methods, and sheer size are some reasons that inlining is not always possible/practical. (Another reason is intent of the build, such as separate compilation (object modules), separate load units (e.g. DLLs)).
There's no real advantage to making most standard library functions intrisics either (that would hard code a lot more knowledge into the compiler for no real advantage), so a machine code call again is often most appropriate.
C is a notable language that arguably omitted other explicit language statements in favor standard library functions. Though libraries pre-existed, this language made a shift to doing more work from standard library functions and less as explicit statements in the grammar of the language. IO in other languages, for example, was frequently given its own syntax in the form of various statements, whereas the C grammar does not define any IO statements, simply instead deferring to its standard library to provide that, all accessible via function calls, which the compiler already knows how to do.
1
Nice answer. One should add some words why this decision in C was made: if I remember correctly, the main reason was actually because it made it way easier to create C compilers for many different hardware architectures.
– Doc Brown
5 hours ago
2
@DocBrown By 1975, there were enough examples in the area of the programming language development (ALGOL-68, anyone?) which showed that attempts to bake-in everything into the language directly led to considerable slow downs in both finsihing the language specifications and in producing language implementations.
– Joker_vD
5 hours ago
A similar example is what Python did withprint
: In 2.x, it was a statement, with its own special grammar, but in 3.x, it became just another function call. See PEP 3105 for the official explanation.
– dan04
3 hours ago
@DocBrown, portability was almost certainly not a reason. When Unix and C were created, they were designed and built for exactly one machine, a spare PDP-7, as Ken Thompson wondered what concepts could be salvaged from the failed Multics project. C was also created for one reason: to have a high level language in which to (re)implement Unix. They we’re basically an experiment in software design, not a serious attempt at a commercial multi-platform OS and language. See bell-labs.com/usr/dmr/www/chist.html for example.
– Euro Micelli
2 hours ago
add a comment |
This is simply to keep the language itself as simple as possible. You need to distinguish between a feature of the language, such as a type of loop or ways to pass parameters to functions and so on, and common functionality that most applications need.
Libraries are functions that may be useful to many programmers so they are created as reusable code that can be shared. The standard libraries are designed to be very common functions that programmers typically need. This way the programming language is immediately useful to a wider range of programmers. The libraries can be updated and extended without changing the core features of the language itself.
+1, that is the exact reason why it could but shouldn't be done. Imagine having to create a new release of the compiler and having everyone in the world reinstall it just because some standard function changed!
– Kilian Foth
5 hours ago
add a comment |
In addition to what the other answers have already said, putting standard functions into a library is separation of concerns:
It's the compiler's job to parse the language and generate code for it. It's not the compiler's job to contain anything that can already be written in that language and provided as a library.
It's the standard libraries (the one that's always implicitly available) job to provide core functionality that's needed by virtually all programs. It's not the standard libraries job to contain all the functions that might be useful.
It's the job of optional standard libraries to provide auxiliary functionality that many programs can do without, but which are still quite basic and also essential for many applications to warrant shipping with standard environments. It's not the job of those optional libraries to contain all reusable code that's ever been written.
It's the job of user libraries to provide collections of useful reusable functions. It's not the job of user libraries to contain all the code that's ever been written.
It's the job of an application's source code to provide the remaining bits of code that's really only relevant to that one application.
If you want a one-size-fits-all software, you get something insanely complex. You need to modularize to get the complexity down to manageable levels. And you need to modularize to allow partial implementations:
The threading library is worthless on the single-core embedded controller. Allowing the language implementation for this embedded controller to just not include the
pthread
library is just the right thing to do.The math library is worthless on the micro-controller that doesn't even have an FPU. Again, not being forced to provide functions like
sin()
makes life a whole lot easier for the implementators of your language for that micro-controller.Even the core standard library is worthless when you are programming a kernel. You cannot implement
write()
without a syscall into the kernel, and you cannot implementprintf()
withoutwrite()
. As a kernel programmer, it's your job to provide thewrite()
syscall, you cannot just expect it to be there.
A language that does not allow for such omissions from the standard libraries is simply no suited for many tasks. If you want your language to be flexibly usable in uncommon environments, it must be flexible in what standard libraries are included. The more your language relies on standard libraries, the more assumptions it makes on its execution environment, and thus restricts its use to environment that provide these prerequisites.
Of course, high level languages like python and java can make a lot of assumptions on their environment. And they tend to include many, many things into their standard libraries. Lower level languages like C provide much less in their standard libraries, and keep the core standard library much smaller. That's why you find a working C compiler for virtually any architecture, but may not be able to run any python scripts on it.
add a comment |
One big reason compilers and standard libraries are separate are because they serve two different purposes (even if they're both defined by the same language spec): the compiler translates higher-level code into machine instructions, and the standard library provides pre-tested implementations of commonly-needed functionality. Compiler writers value modularity just like other software developers do. In fact, some of the early C compilers further split the compiler into separate programs for pre-processing, compiling, and linking.
This modularity gives you a bunch of advantages:
- It minimizes the amount of work needed when supporting a new hardware platform, since most of the standard library code is hardware-agnostic can be re-used.
- A standard library implementation can be optimized in different ways (for speed, for space, for resource usage, etc). Many early computing systems only had one compiler available, and having a separate standard library meant developers could swap implementations to suit their needs.
- The standard library functionality doesn't even have to exist. When writing bare-metal C code for instance, you have a full-featured compiler but most of the standard library functionality isn't there and some things like file I/O aren't even possible. If the compiler was required to implement this functionality, then you couldn't have a standards-conforming C compiler on some of the platforms where you need it the most.
- On early systems, compilers were frequently developed by the company that designed the hardware. Standard libraries were frequently provided by the OS vendor, since they often required access to functionality (like system calls) specific to that software platform. It was impractical for a compiler writer to have to support all of the different combinations of hardware and software (there used to be a whole lot more variety in both hardware architecture and software platform).
- In high-level languages, a standard library can be implemented as a dynamically-loaded library. One standard library implementation can then be used by multiple compilers and/or programming languages.
Historically speaking (at least from C's perspective), the original, pre-standardization versions of the language didn't have a standard library at all. OS vendors and third parties would often provide libraries full of commonly-used functionality, but different implementations included different things and they were largely incompatible with each other. When C was standardized, they defined a "standard library" in an attempt to harmonize these disparate implementations and improve portability. The C standard library developed separate from the language, like the Boost libraries have for C++, but were later integrated into the language spec.
add a comment |
Additional corner-case answer: Intellectual property management
Notable example is implementation of Math.Pow(double, double) in .NET Framework which was purchased by Microsoft from Intel and remains undisclosed even if the framework went open-source. (To be precise, in the above case it is an internal call rather than a library but the idea holds.) A library separated from the language itself (theoretically also a subset of standard libraries) can give the language backers more flexibility in drawing the line between what to keep transparent and what has to remain undisclosed (due to their contracts with 3rd parties or other IP-related reasons).
add a comment |
This is meant as an addition to the existing answers (and is too long for a comment).
There are at least two other reasons for a standard library:
Barrier to Entry
If a particular language feature is in a library function and I want to know how it works, I can just read the source for that function. If I want to submit a bug report/patch/pull request, it's not generally too difficult to code a fix and test case(s). If it's in the compiler, I have to be able to dig into the internals. Even if it's in the same language (and it should be, any self-respecting compiler should be self-hosted) compiler code is nothing like application code. It may take forever to even find the correct files.
You're cutting yourself off from a lot of potential contributors if you go that route.
Hot code loading
Many languages offer this feature to one degree or another, but it would be enormously complicated to hot reload the code that's doing the hot reloading. If the SL is separate from the runtime it can be reloaded.
1
"any self-respecting compiler should be self-hosted" - not at all. It would be pointless to have versions of say LLVM written in C, C++, Objective-C, Swift, Fortran and so on to compile all these languages.
– gnasher729
3 hours ago
@gnasher729 isn't that a bit of a special case (along with other multilanguage targets like the CLR)?
– Jared Smith
2 hours ago
@JaredSmith I would say it is now the general case, not special at all. Nobody writes "a compiler" as a monolithic application any more. They produce compiler systems instead. Most of the functionality of complete compiler is completely independent of the particular language that is being compiled, and much of the language-dependent part can be done by supplying different data defining the grammar of the language, not by writing different code for each language you want to compile.
– alephzero
1 hour ago
add a comment |
Bugs and debugging.
Bugs:
All software has bugs, your standard library has bugs and your compiler has bugs. As a user of the language it is much easier to find and workaround such bugs when they're in the standard library as opposed to in the compiler.
Debugging:
It's much easier for me to see a stack trace of a standard library and give me some sense of what might be going wrong. Because that stack trace has code I understand. Ofcourse you can do dig deeper and you can also trace your intrinsic functions, but it's a lot easier if it's in a language you use all the time from day to day.
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "131"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: false,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Simone Broili is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsoftwareengineering.stackexchange.com%2fquestions%2f386296%2fwhy-are-standard-libraries-not-programming-language-primitives%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
StackExchange.ready(function () {
$("#show-editor-button input, #show-editor-button button").click(function () {
var showEditor = function() {
$("#show-editor-button").hide();
$("#post-form").removeClass("dno");
StackExchange.editor.finallyInit();
};
var useFancy = $(this).data('confirm-use-fancy');
if(useFancy == 'True') {
var popupTitle = $(this).data('confirm-fancy-title');
var popupBody = $(this).data('confirm-fancy-body');
var popupAccept = $(this).data('confirm-fancy-accept-button');
$(this).loadPopup({
url: '/post/self-answer-popup',
loaded: function(popup) {
var pTitle = $(popup).find('h2');
var pBody = $(popup).find('.popup-body');
var pSubmit = $(popup).find('.popup-submit');
pTitle.text(popupTitle);
pBody.html(popupBody);
pSubmit.val(popupAccept).click(showEditor);
}
})
} else{
var confirmText = $(this).data('confirm-text');
if (confirmText ? confirm(confirmText) : true) {
showEditor();
}
}
});
});
7 Answers
7
active
oldest
votes
7 Answers
7
active
oldest
votes
active
oldest
votes
active
oldest
votes
Allow me to expand somewhat on @Vincent's (+1) good answer:
Why couldn't the compiler simply translate a function call into a set of instructions?
It can, and does so via at least two mechanisms:
inlining a function call — during translation, the compiler can replace a source code call with its implementation directly inline instead of making an actual call to the function. Still the function needs to have an implementation defined somewhere and that can be in the standard library.
intrinsic function — intrinsics are functions that the compiler has been informed of without necessarily finding the function in a library. These are usually reserved for hardware features that are not practically accessible in any other way, being so simple that even the overhead of a call to assembly language library function is considered high. (The compiler can generally only automatically inline source code in its language, but not assembly functions, which is where intrinsic mechanism comes in.)
Still these being said, the best option sometimes is for the compiler to translate a function call in the source language into a function call in the machine code. Recursion, virtual methods, and sheer size are some reasons that inlining is not always possible/practical. (Another reason is intent of the build, such as separate compilation (object modules), separate load units (e.g. DLLs)).
There's no real advantage to making most standard library functions intrisics either (that would hard code a lot more knowledge into the compiler for no real advantage), so a machine code call again is often most appropriate.
C is a notable language that arguably omitted other explicit language statements in favor standard library functions. Though libraries pre-existed, this language made a shift to doing more work from standard library functions and less as explicit statements in the grammar of the language. IO in other languages, for example, was frequently given its own syntax in the form of various statements, whereas the C grammar does not define any IO statements, simply instead deferring to its standard library to provide that, all accessible via function calls, which the compiler already knows how to do.
1
Nice answer. One should add some words why this decision in C was made: if I remember correctly, the main reason was actually because it made it way easier to create C compilers for many different hardware architectures.
– Doc Brown
5 hours ago
2
@DocBrown By 1975, there were enough examples in the area of the programming language development (ALGOL-68, anyone?) which showed that attempts to bake-in everything into the language directly led to considerable slow downs in both finsihing the language specifications and in producing language implementations.
– Joker_vD
5 hours ago
A similar example is what Python did withprint
: In 2.x, it was a statement, with its own special grammar, but in 3.x, it became just another function call. See PEP 3105 for the official explanation.
– dan04
3 hours ago
@DocBrown, portability was almost certainly not a reason. When Unix and C were created, they were designed and built for exactly one machine, a spare PDP-7, as Ken Thompson wondered what concepts could be salvaged from the failed Multics project. C was also created for one reason: to have a high level language in which to (re)implement Unix. They we’re basically an experiment in software design, not a serious attempt at a commercial multi-platform OS and language. See bell-labs.com/usr/dmr/www/chist.html for example.
– Euro Micelli
2 hours ago
add a comment |
Allow me to expand somewhat on @Vincent's (+1) good answer:
Why couldn't the compiler simply translate a function call into a set of instructions?
It can, and does so via at least two mechanisms:
inlining a function call — during translation, the compiler can replace a source code call with its implementation directly inline instead of making an actual call to the function. Still the function needs to have an implementation defined somewhere and that can be in the standard library.
intrinsic function — intrinsics are functions that the compiler has been informed of without necessarily finding the function in a library. These are usually reserved for hardware features that are not practically accessible in any other way, being so simple that even the overhead of a call to assembly language library function is considered high. (The compiler can generally only automatically inline source code in its language, but not assembly functions, which is where intrinsic mechanism comes in.)
Still these being said, the best option sometimes is for the compiler to translate a function call in the source language into a function call in the machine code. Recursion, virtual methods, and sheer size are some reasons that inlining is not always possible/practical. (Another reason is intent of the build, such as separate compilation (object modules), separate load units (e.g. DLLs)).
There's no real advantage to making most standard library functions intrisics either (that would hard code a lot more knowledge into the compiler for no real advantage), so a machine code call again is often most appropriate.
C is a notable language that arguably omitted other explicit language statements in favor standard library functions. Though libraries pre-existed, this language made a shift to doing more work from standard library functions and less as explicit statements in the grammar of the language. IO in other languages, for example, was frequently given its own syntax in the form of various statements, whereas the C grammar does not define any IO statements, simply instead deferring to its standard library to provide that, all accessible via function calls, which the compiler already knows how to do.
1
Nice answer. One should add some words why this decision in C was made: if I remember correctly, the main reason was actually because it made it way easier to create C compilers for many different hardware architectures.
– Doc Brown
5 hours ago
2
@DocBrown By 1975, there were enough examples in the area of the programming language development (ALGOL-68, anyone?) which showed that attempts to bake-in everything into the language directly led to considerable slow downs in both finsihing the language specifications and in producing language implementations.
– Joker_vD
5 hours ago
A similar example is what Python did withprint
: In 2.x, it was a statement, with its own special grammar, but in 3.x, it became just another function call. See PEP 3105 for the official explanation.
– dan04
3 hours ago
@DocBrown, portability was almost certainly not a reason. When Unix and C were created, they were designed and built for exactly one machine, a spare PDP-7, as Ken Thompson wondered what concepts could be salvaged from the failed Multics project. C was also created for one reason: to have a high level language in which to (re)implement Unix. They we’re basically an experiment in software design, not a serious attempt at a commercial multi-platform OS and language. See bell-labs.com/usr/dmr/www/chist.html for example.
– Euro Micelli
2 hours ago
add a comment |
Allow me to expand somewhat on @Vincent's (+1) good answer:
Why couldn't the compiler simply translate a function call into a set of instructions?
It can, and does so via at least two mechanisms:
inlining a function call — during translation, the compiler can replace a source code call with its implementation directly inline instead of making an actual call to the function. Still the function needs to have an implementation defined somewhere and that can be in the standard library.
intrinsic function — intrinsics are functions that the compiler has been informed of without necessarily finding the function in a library. These are usually reserved for hardware features that are not practically accessible in any other way, being so simple that even the overhead of a call to assembly language library function is considered high. (The compiler can generally only automatically inline source code in its language, but not assembly functions, which is where intrinsic mechanism comes in.)
Still these being said, the best option sometimes is for the compiler to translate a function call in the source language into a function call in the machine code. Recursion, virtual methods, and sheer size are some reasons that inlining is not always possible/practical. (Another reason is intent of the build, such as separate compilation (object modules), separate load units (e.g. DLLs)).
There's no real advantage to making most standard library functions intrisics either (that would hard code a lot more knowledge into the compiler for no real advantage), so a machine code call again is often most appropriate.
C is a notable language that arguably omitted other explicit language statements in favor standard library functions. Though libraries pre-existed, this language made a shift to doing more work from standard library functions and less as explicit statements in the grammar of the language. IO in other languages, for example, was frequently given its own syntax in the form of various statements, whereas the C grammar does not define any IO statements, simply instead deferring to its standard library to provide that, all accessible via function calls, which the compiler already knows how to do.
Allow me to expand somewhat on @Vincent's (+1) good answer:
Why couldn't the compiler simply translate a function call into a set of instructions?
It can, and does so via at least two mechanisms:
inlining a function call — during translation, the compiler can replace a source code call with its implementation directly inline instead of making an actual call to the function. Still the function needs to have an implementation defined somewhere and that can be in the standard library.
intrinsic function — intrinsics are functions that the compiler has been informed of without necessarily finding the function in a library. These are usually reserved for hardware features that are not practically accessible in any other way, being so simple that even the overhead of a call to assembly language library function is considered high. (The compiler can generally only automatically inline source code in its language, but not assembly functions, which is where intrinsic mechanism comes in.)
Still these being said, the best option sometimes is for the compiler to translate a function call in the source language into a function call in the machine code. Recursion, virtual methods, and sheer size are some reasons that inlining is not always possible/practical. (Another reason is intent of the build, such as separate compilation (object modules), separate load units (e.g. DLLs)).
There's no real advantage to making most standard library functions intrisics either (that would hard code a lot more knowledge into the compiler for no real advantage), so a machine code call again is often most appropriate.
C is a notable language that arguably omitted other explicit language statements in favor standard library functions. Though libraries pre-existed, this language made a shift to doing more work from standard library functions and less as explicit statements in the grammar of the language. IO in other languages, for example, was frequently given its own syntax in the form of various statements, whereas the C grammar does not define any IO statements, simply instead deferring to its standard library to provide that, all accessible via function calls, which the compiler already knows how to do.
edited 1 hour ago
answered 6 hours ago
Erik EidtErik Eidt
23.6k43263
23.6k43263
1
Nice answer. One should add some words why this decision in C was made: if I remember correctly, the main reason was actually because it made it way easier to create C compilers for many different hardware architectures.
– Doc Brown
5 hours ago
2
@DocBrown By 1975, there were enough examples in the area of the programming language development (ALGOL-68, anyone?) which showed that attempts to bake-in everything into the language directly led to considerable slow downs in both finsihing the language specifications and in producing language implementations.
– Joker_vD
5 hours ago
A similar example is what Python did withprint
: In 2.x, it was a statement, with its own special grammar, but in 3.x, it became just another function call. See PEP 3105 for the official explanation.
– dan04
3 hours ago
@DocBrown, portability was almost certainly not a reason. When Unix and C were created, they were designed and built for exactly one machine, a spare PDP-7, as Ken Thompson wondered what concepts could be salvaged from the failed Multics project. C was also created for one reason: to have a high level language in which to (re)implement Unix. They we’re basically an experiment in software design, not a serious attempt at a commercial multi-platform OS and language. See bell-labs.com/usr/dmr/www/chist.html for example.
– Euro Micelli
2 hours ago
add a comment |
1
Nice answer. One should add some words why this decision in C was made: if I remember correctly, the main reason was actually because it made it way easier to create C compilers for many different hardware architectures.
– Doc Brown
5 hours ago
2
@DocBrown By 1975, there were enough examples in the area of the programming language development (ALGOL-68, anyone?) which showed that attempts to bake-in everything into the language directly led to considerable slow downs in both finsihing the language specifications and in producing language implementations.
– Joker_vD
5 hours ago
A similar example is what Python did withprint
: In 2.x, it was a statement, with its own special grammar, but in 3.x, it became just another function call. See PEP 3105 for the official explanation.
– dan04
3 hours ago
@DocBrown, portability was almost certainly not a reason. When Unix and C were created, they were designed and built for exactly one machine, a spare PDP-7, as Ken Thompson wondered what concepts could be salvaged from the failed Multics project. C was also created for one reason: to have a high level language in which to (re)implement Unix. They we’re basically an experiment in software design, not a serious attempt at a commercial multi-platform OS and language. See bell-labs.com/usr/dmr/www/chist.html for example.
– Euro Micelli
2 hours ago
1
1
Nice answer. One should add some words why this decision in C was made: if I remember correctly, the main reason was actually because it made it way easier to create C compilers for many different hardware architectures.
– Doc Brown
5 hours ago
Nice answer. One should add some words why this decision in C was made: if I remember correctly, the main reason was actually because it made it way easier to create C compilers for many different hardware architectures.
– Doc Brown
5 hours ago
2
2
@DocBrown By 1975, there were enough examples in the area of the programming language development (ALGOL-68, anyone?) which showed that attempts to bake-in everything into the language directly led to considerable slow downs in both finsihing the language specifications and in producing language implementations.
– Joker_vD
5 hours ago
@DocBrown By 1975, there were enough examples in the area of the programming language development (ALGOL-68, anyone?) which showed that attempts to bake-in everything into the language directly led to considerable slow downs in both finsihing the language specifications and in producing language implementations.
– Joker_vD
5 hours ago
A similar example is what Python did with
print
: In 2.x, it was a statement, with its own special grammar, but in 3.x, it became just another function call. See PEP 3105 for the official explanation.– dan04
3 hours ago
A similar example is what Python did with
print
: In 2.x, it was a statement, with its own special grammar, but in 3.x, it became just another function call. See PEP 3105 for the official explanation.– dan04
3 hours ago
@DocBrown, portability was almost certainly not a reason. When Unix and C were created, they were designed and built for exactly one machine, a spare PDP-7, as Ken Thompson wondered what concepts could be salvaged from the failed Multics project. C was also created for one reason: to have a high level language in which to (re)implement Unix. They we’re basically an experiment in software design, not a serious attempt at a commercial multi-platform OS and language. See bell-labs.com/usr/dmr/www/chist.html for example.
– Euro Micelli
2 hours ago
@DocBrown, portability was almost certainly not a reason. When Unix and C were created, they were designed and built for exactly one machine, a spare PDP-7, as Ken Thompson wondered what concepts could be salvaged from the failed Multics project. C was also created for one reason: to have a high level language in which to (re)implement Unix. They we’re basically an experiment in software design, not a serious attempt at a commercial multi-platform OS and language. See bell-labs.com/usr/dmr/www/chist.html for example.
– Euro Micelli
2 hours ago
add a comment |
This is simply to keep the language itself as simple as possible. You need to distinguish between a feature of the language, such as a type of loop or ways to pass parameters to functions and so on, and common functionality that most applications need.
Libraries are functions that may be useful to many programmers so they are created as reusable code that can be shared. The standard libraries are designed to be very common functions that programmers typically need. This way the programming language is immediately useful to a wider range of programmers. The libraries can be updated and extended without changing the core features of the language itself.
+1, that is the exact reason why it could but shouldn't be done. Imagine having to create a new release of the compiler and having everyone in the world reinstall it just because some standard function changed!
– Kilian Foth
5 hours ago
add a comment |
This is simply to keep the language itself as simple as possible. You need to distinguish between a feature of the language, such as a type of loop or ways to pass parameters to functions and so on, and common functionality that most applications need.
Libraries are functions that may be useful to many programmers so they are created as reusable code that can be shared. The standard libraries are designed to be very common functions that programmers typically need. This way the programming language is immediately useful to a wider range of programmers. The libraries can be updated and extended without changing the core features of the language itself.
+1, that is the exact reason why it could but shouldn't be done. Imagine having to create a new release of the compiler and having everyone in the world reinstall it just because some standard function changed!
– Kilian Foth
5 hours ago
add a comment |
This is simply to keep the language itself as simple as possible. You need to distinguish between a feature of the language, such as a type of loop or ways to pass parameters to functions and so on, and common functionality that most applications need.
Libraries are functions that may be useful to many programmers so they are created as reusable code that can be shared. The standard libraries are designed to be very common functions that programmers typically need. This way the programming language is immediately useful to a wider range of programmers. The libraries can be updated and extended without changing the core features of the language itself.
This is simply to keep the language itself as simple as possible. You need to distinguish between a feature of the language, such as a type of loop or ways to pass parameters to functions and so on, and common functionality that most applications need.
Libraries are functions that may be useful to many programmers so they are created as reusable code that can be shared. The standard libraries are designed to be very common functions that programmers typically need. This way the programming language is immediately useful to a wider range of programmers. The libraries can be updated and extended without changing the core features of the language itself.
answered 8 hours ago
Vincent RamdhanieVincent Ramdhanie
524135
524135
+1, that is the exact reason why it could but shouldn't be done. Imagine having to create a new release of the compiler and having everyone in the world reinstall it just because some standard function changed!
– Kilian Foth
5 hours ago
add a comment |
+1, that is the exact reason why it could but shouldn't be done. Imagine having to create a new release of the compiler and having everyone in the world reinstall it just because some standard function changed!
– Kilian Foth
5 hours ago
+1, that is the exact reason why it could but shouldn't be done. Imagine having to create a new release of the compiler and having everyone in the world reinstall it just because some standard function changed!
– Kilian Foth
5 hours ago
+1, that is the exact reason why it could but shouldn't be done. Imagine having to create a new release of the compiler and having everyone in the world reinstall it just because some standard function changed!
– Kilian Foth
5 hours ago
add a comment |
In addition to what the other answers have already said, putting standard functions into a library is separation of concerns:
It's the compiler's job to parse the language and generate code for it. It's not the compiler's job to contain anything that can already be written in that language and provided as a library.
It's the standard libraries (the one that's always implicitly available) job to provide core functionality that's needed by virtually all programs. It's not the standard libraries job to contain all the functions that might be useful.
It's the job of optional standard libraries to provide auxiliary functionality that many programs can do without, but which are still quite basic and also essential for many applications to warrant shipping with standard environments. It's not the job of those optional libraries to contain all reusable code that's ever been written.
It's the job of user libraries to provide collections of useful reusable functions. It's not the job of user libraries to contain all the code that's ever been written.
It's the job of an application's source code to provide the remaining bits of code that's really only relevant to that one application.
If you want a one-size-fits-all software, you get something insanely complex. You need to modularize to get the complexity down to manageable levels. And you need to modularize to allow partial implementations:
The threading library is worthless on the single-core embedded controller. Allowing the language implementation for this embedded controller to just not include the
pthread
library is just the right thing to do.The math library is worthless on the micro-controller that doesn't even have an FPU. Again, not being forced to provide functions like
sin()
makes life a whole lot easier for the implementators of your language for that micro-controller.Even the core standard library is worthless when you are programming a kernel. You cannot implement
write()
without a syscall into the kernel, and you cannot implementprintf()
withoutwrite()
. As a kernel programmer, it's your job to provide thewrite()
syscall, you cannot just expect it to be there.
A language that does not allow for such omissions from the standard libraries is simply no suited for many tasks. If you want your language to be flexibly usable in uncommon environments, it must be flexible in what standard libraries are included. The more your language relies on standard libraries, the more assumptions it makes on its execution environment, and thus restricts its use to environment that provide these prerequisites.
Of course, high level languages like python and java can make a lot of assumptions on their environment. And they tend to include many, many things into their standard libraries. Lower level languages like C provide much less in their standard libraries, and keep the core standard library much smaller. That's why you find a working C compiler for virtually any architecture, but may not be able to run any python scripts on it.
add a comment |
In addition to what the other answers have already said, putting standard functions into a library is separation of concerns:
It's the compiler's job to parse the language and generate code for it. It's not the compiler's job to contain anything that can already be written in that language and provided as a library.
It's the standard libraries (the one that's always implicitly available) job to provide core functionality that's needed by virtually all programs. It's not the standard libraries job to contain all the functions that might be useful.
It's the job of optional standard libraries to provide auxiliary functionality that many programs can do without, but which are still quite basic and also essential for many applications to warrant shipping with standard environments. It's not the job of those optional libraries to contain all reusable code that's ever been written.
It's the job of user libraries to provide collections of useful reusable functions. It's not the job of user libraries to contain all the code that's ever been written.
It's the job of an application's source code to provide the remaining bits of code that's really only relevant to that one application.
If you want a one-size-fits-all software, you get something insanely complex. You need to modularize to get the complexity down to manageable levels. And you need to modularize to allow partial implementations:
The threading library is worthless on the single-core embedded controller. Allowing the language implementation for this embedded controller to just not include the
pthread
library is just the right thing to do.The math library is worthless on the micro-controller that doesn't even have an FPU. Again, not being forced to provide functions like
sin()
makes life a whole lot easier for the implementators of your language for that micro-controller.Even the core standard library is worthless when you are programming a kernel. You cannot implement
write()
without a syscall into the kernel, and you cannot implementprintf()
withoutwrite()
. As a kernel programmer, it's your job to provide thewrite()
syscall, you cannot just expect it to be there.
A language that does not allow for such omissions from the standard libraries is simply no suited for many tasks. If you want your language to be flexibly usable in uncommon environments, it must be flexible in what standard libraries are included. The more your language relies on standard libraries, the more assumptions it makes on its execution environment, and thus restricts its use to environment that provide these prerequisites.
Of course, high level languages like python and java can make a lot of assumptions on their environment. And they tend to include many, many things into their standard libraries. Lower level languages like C provide much less in their standard libraries, and keep the core standard library much smaller. That's why you find a working C compiler for virtually any architecture, but may not be able to run any python scripts on it.
add a comment |
In addition to what the other answers have already said, putting standard functions into a library is separation of concerns:
It's the compiler's job to parse the language and generate code for it. It's not the compiler's job to contain anything that can already be written in that language and provided as a library.
It's the standard libraries (the one that's always implicitly available) job to provide core functionality that's needed by virtually all programs. It's not the standard libraries job to contain all the functions that might be useful.
It's the job of optional standard libraries to provide auxiliary functionality that many programs can do without, but which are still quite basic and also essential for many applications to warrant shipping with standard environments. It's not the job of those optional libraries to contain all reusable code that's ever been written.
It's the job of user libraries to provide collections of useful reusable functions. It's not the job of user libraries to contain all the code that's ever been written.
It's the job of an application's source code to provide the remaining bits of code that's really only relevant to that one application.
If you want a one-size-fits-all software, you get something insanely complex. You need to modularize to get the complexity down to manageable levels. And you need to modularize to allow partial implementations:
The threading library is worthless on the single-core embedded controller. Allowing the language implementation for this embedded controller to just not include the
pthread
library is just the right thing to do.The math library is worthless on the micro-controller that doesn't even have an FPU. Again, not being forced to provide functions like
sin()
makes life a whole lot easier for the implementators of your language for that micro-controller.Even the core standard library is worthless when you are programming a kernel. You cannot implement
write()
without a syscall into the kernel, and you cannot implementprintf()
withoutwrite()
. As a kernel programmer, it's your job to provide thewrite()
syscall, you cannot just expect it to be there.
A language that does not allow for such omissions from the standard libraries is simply no suited for many tasks. If you want your language to be flexibly usable in uncommon environments, it must be flexible in what standard libraries are included. The more your language relies on standard libraries, the more assumptions it makes on its execution environment, and thus restricts its use to environment that provide these prerequisites.
Of course, high level languages like python and java can make a lot of assumptions on their environment. And they tend to include many, many things into their standard libraries. Lower level languages like C provide much less in their standard libraries, and keep the core standard library much smaller. That's why you find a working C compiler for virtually any architecture, but may not be able to run any python scripts on it.
In addition to what the other answers have already said, putting standard functions into a library is separation of concerns:
It's the compiler's job to parse the language and generate code for it. It's not the compiler's job to contain anything that can already be written in that language and provided as a library.
It's the standard libraries (the one that's always implicitly available) job to provide core functionality that's needed by virtually all programs. It's not the standard libraries job to contain all the functions that might be useful.
It's the job of optional standard libraries to provide auxiliary functionality that many programs can do without, but which are still quite basic and also essential for many applications to warrant shipping with standard environments. It's not the job of those optional libraries to contain all reusable code that's ever been written.
It's the job of user libraries to provide collections of useful reusable functions. It's not the job of user libraries to contain all the code that's ever been written.
It's the job of an application's source code to provide the remaining bits of code that's really only relevant to that one application.
If you want a one-size-fits-all software, you get something insanely complex. You need to modularize to get the complexity down to manageable levels. And you need to modularize to allow partial implementations:
The threading library is worthless on the single-core embedded controller. Allowing the language implementation for this embedded controller to just not include the
pthread
library is just the right thing to do.The math library is worthless on the micro-controller that doesn't even have an FPU. Again, not being forced to provide functions like
sin()
makes life a whole lot easier for the implementators of your language for that micro-controller.Even the core standard library is worthless when you are programming a kernel. You cannot implement
write()
without a syscall into the kernel, and you cannot implementprintf()
withoutwrite()
. As a kernel programmer, it's your job to provide thewrite()
syscall, you cannot just expect it to be there.
A language that does not allow for such omissions from the standard libraries is simply no suited for many tasks. If you want your language to be flexibly usable in uncommon environments, it must be flexible in what standard libraries are included. The more your language relies on standard libraries, the more assumptions it makes on its execution environment, and thus restricts its use to environment that provide these prerequisites.
Of course, high level languages like python and java can make a lot of assumptions on their environment. And they tend to include many, many things into their standard libraries. Lower level languages like C provide much less in their standard libraries, and keep the core standard library much smaller. That's why you find a working C compiler for virtually any architecture, but may not be able to run any python scripts on it.
answered 4 hours ago
cmastercmaster
6,41811220
6,41811220
add a comment |
add a comment |
One big reason compilers and standard libraries are separate are because they serve two different purposes (even if they're both defined by the same language spec): the compiler translates higher-level code into machine instructions, and the standard library provides pre-tested implementations of commonly-needed functionality. Compiler writers value modularity just like other software developers do. In fact, some of the early C compilers further split the compiler into separate programs for pre-processing, compiling, and linking.
This modularity gives you a bunch of advantages:
- It minimizes the amount of work needed when supporting a new hardware platform, since most of the standard library code is hardware-agnostic can be re-used.
- A standard library implementation can be optimized in different ways (for speed, for space, for resource usage, etc). Many early computing systems only had one compiler available, and having a separate standard library meant developers could swap implementations to suit their needs.
- The standard library functionality doesn't even have to exist. When writing bare-metal C code for instance, you have a full-featured compiler but most of the standard library functionality isn't there and some things like file I/O aren't even possible. If the compiler was required to implement this functionality, then you couldn't have a standards-conforming C compiler on some of the platforms where you need it the most.
- On early systems, compilers were frequently developed by the company that designed the hardware. Standard libraries were frequently provided by the OS vendor, since they often required access to functionality (like system calls) specific to that software platform. It was impractical for a compiler writer to have to support all of the different combinations of hardware and software (there used to be a whole lot more variety in both hardware architecture and software platform).
- In high-level languages, a standard library can be implemented as a dynamically-loaded library. One standard library implementation can then be used by multiple compilers and/or programming languages.
Historically speaking (at least from C's perspective), the original, pre-standardization versions of the language didn't have a standard library at all. OS vendors and third parties would often provide libraries full of commonly-used functionality, but different implementations included different things and they were largely incompatible with each other. When C was standardized, they defined a "standard library" in an attempt to harmonize these disparate implementations and improve portability. The C standard library developed separate from the language, like the Boost libraries have for C++, but were later integrated into the language spec.
add a comment |
One big reason compilers and standard libraries are separate are because they serve two different purposes (even if they're both defined by the same language spec): the compiler translates higher-level code into machine instructions, and the standard library provides pre-tested implementations of commonly-needed functionality. Compiler writers value modularity just like other software developers do. In fact, some of the early C compilers further split the compiler into separate programs for pre-processing, compiling, and linking.
This modularity gives you a bunch of advantages:
- It minimizes the amount of work needed when supporting a new hardware platform, since most of the standard library code is hardware-agnostic can be re-used.
- A standard library implementation can be optimized in different ways (for speed, for space, for resource usage, etc). Many early computing systems only had one compiler available, and having a separate standard library meant developers could swap implementations to suit their needs.
- The standard library functionality doesn't even have to exist. When writing bare-metal C code for instance, you have a full-featured compiler but most of the standard library functionality isn't there and some things like file I/O aren't even possible. If the compiler was required to implement this functionality, then you couldn't have a standards-conforming C compiler on some of the platforms where you need it the most.
- On early systems, compilers were frequently developed by the company that designed the hardware. Standard libraries were frequently provided by the OS vendor, since they often required access to functionality (like system calls) specific to that software platform. It was impractical for a compiler writer to have to support all of the different combinations of hardware and software (there used to be a whole lot more variety in both hardware architecture and software platform).
- In high-level languages, a standard library can be implemented as a dynamically-loaded library. One standard library implementation can then be used by multiple compilers and/or programming languages.
Historically speaking (at least from C's perspective), the original, pre-standardization versions of the language didn't have a standard library at all. OS vendors and third parties would often provide libraries full of commonly-used functionality, but different implementations included different things and they were largely incompatible with each other. When C was standardized, they defined a "standard library" in an attempt to harmonize these disparate implementations and improve portability. The C standard library developed separate from the language, like the Boost libraries have for C++, but were later integrated into the language spec.
add a comment |
One big reason compilers and standard libraries are separate are because they serve two different purposes (even if they're both defined by the same language spec): the compiler translates higher-level code into machine instructions, and the standard library provides pre-tested implementations of commonly-needed functionality. Compiler writers value modularity just like other software developers do. In fact, some of the early C compilers further split the compiler into separate programs for pre-processing, compiling, and linking.
This modularity gives you a bunch of advantages:
- It minimizes the amount of work needed when supporting a new hardware platform, since most of the standard library code is hardware-agnostic can be re-used.
- A standard library implementation can be optimized in different ways (for speed, for space, for resource usage, etc). Many early computing systems only had one compiler available, and having a separate standard library meant developers could swap implementations to suit their needs.
- The standard library functionality doesn't even have to exist. When writing bare-metal C code for instance, you have a full-featured compiler but most of the standard library functionality isn't there and some things like file I/O aren't even possible. If the compiler was required to implement this functionality, then you couldn't have a standards-conforming C compiler on some of the platforms where you need it the most.
- On early systems, compilers were frequently developed by the company that designed the hardware. Standard libraries were frequently provided by the OS vendor, since they often required access to functionality (like system calls) specific to that software platform. It was impractical for a compiler writer to have to support all of the different combinations of hardware and software (there used to be a whole lot more variety in both hardware architecture and software platform).
- In high-level languages, a standard library can be implemented as a dynamically-loaded library. One standard library implementation can then be used by multiple compilers and/or programming languages.
Historically speaking (at least from C's perspective), the original, pre-standardization versions of the language didn't have a standard library at all. OS vendors and third parties would often provide libraries full of commonly-used functionality, but different implementations included different things and they were largely incompatible with each other. When C was standardized, they defined a "standard library" in an attempt to harmonize these disparate implementations and improve portability. The C standard library developed separate from the language, like the Boost libraries have for C++, but were later integrated into the language spec.
One big reason compilers and standard libraries are separate are because they serve two different purposes (even if they're both defined by the same language spec): the compiler translates higher-level code into machine instructions, and the standard library provides pre-tested implementations of commonly-needed functionality. Compiler writers value modularity just like other software developers do. In fact, some of the early C compilers further split the compiler into separate programs for pre-processing, compiling, and linking.
This modularity gives you a bunch of advantages:
- It minimizes the amount of work needed when supporting a new hardware platform, since most of the standard library code is hardware-agnostic can be re-used.
- A standard library implementation can be optimized in different ways (for speed, for space, for resource usage, etc). Many early computing systems only had one compiler available, and having a separate standard library meant developers could swap implementations to suit their needs.
- The standard library functionality doesn't even have to exist. When writing bare-metal C code for instance, you have a full-featured compiler but most of the standard library functionality isn't there and some things like file I/O aren't even possible. If the compiler was required to implement this functionality, then you couldn't have a standards-conforming C compiler on some of the platforms where you need it the most.
- On early systems, compilers were frequently developed by the company that designed the hardware. Standard libraries were frequently provided by the OS vendor, since they often required access to functionality (like system calls) specific to that software platform. It was impractical for a compiler writer to have to support all of the different combinations of hardware and software (there used to be a whole lot more variety in both hardware architecture and software platform).
- In high-level languages, a standard library can be implemented as a dynamically-loaded library. One standard library implementation can then be used by multiple compilers and/or programming languages.
Historically speaking (at least from C's perspective), the original, pre-standardization versions of the language didn't have a standard library at all. OS vendors and third parties would often provide libraries full of commonly-used functionality, but different implementations included different things and they were largely incompatible with each other. When C was standardized, they defined a "standard library" in an attempt to harmonize these disparate implementations and improve portability. The C standard library developed separate from the language, like the Boost libraries have for C++, but were later integrated into the language spec.
answered 3 hours ago
btabta
50937
50937
add a comment |
add a comment |
Additional corner-case answer: Intellectual property management
Notable example is implementation of Math.Pow(double, double) in .NET Framework which was purchased by Microsoft from Intel and remains undisclosed even if the framework went open-source. (To be precise, in the above case it is an internal call rather than a library but the idea holds.) A library separated from the language itself (theoretically also a subset of standard libraries) can give the language backers more flexibility in drawing the line between what to keep transparent and what has to remain undisclosed (due to their contracts with 3rd parties or other IP-related reasons).
add a comment |
Additional corner-case answer: Intellectual property management
Notable example is implementation of Math.Pow(double, double) in .NET Framework which was purchased by Microsoft from Intel and remains undisclosed even if the framework went open-source. (To be precise, in the above case it is an internal call rather than a library but the idea holds.) A library separated from the language itself (theoretically also a subset of standard libraries) can give the language backers more flexibility in drawing the line between what to keep transparent and what has to remain undisclosed (due to their contracts with 3rd parties or other IP-related reasons).
add a comment |
Additional corner-case answer: Intellectual property management
Notable example is implementation of Math.Pow(double, double) in .NET Framework which was purchased by Microsoft from Intel and remains undisclosed even if the framework went open-source. (To be precise, in the above case it is an internal call rather than a library but the idea holds.) A library separated from the language itself (theoretically also a subset of standard libraries) can give the language backers more flexibility in drawing the line between what to keep transparent and what has to remain undisclosed (due to their contracts with 3rd parties or other IP-related reasons).
Additional corner-case answer: Intellectual property management
Notable example is implementation of Math.Pow(double, double) in .NET Framework which was purchased by Microsoft from Intel and remains undisclosed even if the framework went open-source. (To be precise, in the above case it is an internal call rather than a library but the idea holds.) A library separated from the language itself (theoretically also a subset of standard libraries) can give the language backers more flexibility in drawing the line between what to keep transparent and what has to remain undisclosed (due to their contracts with 3rd parties or other IP-related reasons).
answered 3 hours ago
miroxlavmiroxlav
474211
474211
add a comment |
add a comment |
This is meant as an addition to the existing answers (and is too long for a comment).
There are at least two other reasons for a standard library:
Barrier to Entry
If a particular language feature is in a library function and I want to know how it works, I can just read the source for that function. If I want to submit a bug report/patch/pull request, it's not generally too difficult to code a fix and test case(s). If it's in the compiler, I have to be able to dig into the internals. Even if it's in the same language (and it should be, any self-respecting compiler should be self-hosted) compiler code is nothing like application code. It may take forever to even find the correct files.
You're cutting yourself off from a lot of potential contributors if you go that route.
Hot code loading
Many languages offer this feature to one degree or another, but it would be enormously complicated to hot reload the code that's doing the hot reloading. If the SL is separate from the runtime it can be reloaded.
1
"any self-respecting compiler should be self-hosted" - not at all. It would be pointless to have versions of say LLVM written in C, C++, Objective-C, Swift, Fortran and so on to compile all these languages.
– gnasher729
3 hours ago
@gnasher729 isn't that a bit of a special case (along with other multilanguage targets like the CLR)?
– Jared Smith
2 hours ago
@JaredSmith I would say it is now the general case, not special at all. Nobody writes "a compiler" as a monolithic application any more. They produce compiler systems instead. Most of the functionality of complete compiler is completely independent of the particular language that is being compiled, and much of the language-dependent part can be done by supplying different data defining the grammar of the language, not by writing different code for each language you want to compile.
– alephzero
1 hour ago
add a comment |
This is meant as an addition to the existing answers (and is too long for a comment).
There are at least two other reasons for a standard library:
Barrier to Entry
If a particular language feature is in a library function and I want to know how it works, I can just read the source for that function. If I want to submit a bug report/patch/pull request, it's not generally too difficult to code a fix and test case(s). If it's in the compiler, I have to be able to dig into the internals. Even if it's in the same language (and it should be, any self-respecting compiler should be self-hosted) compiler code is nothing like application code. It may take forever to even find the correct files.
You're cutting yourself off from a lot of potential contributors if you go that route.
Hot code loading
Many languages offer this feature to one degree or another, but it would be enormously complicated to hot reload the code that's doing the hot reloading. If the SL is separate from the runtime it can be reloaded.
1
"any self-respecting compiler should be self-hosted" - not at all. It would be pointless to have versions of say LLVM written in C, C++, Objective-C, Swift, Fortran and so on to compile all these languages.
– gnasher729
3 hours ago
@gnasher729 isn't that a bit of a special case (along with other multilanguage targets like the CLR)?
– Jared Smith
2 hours ago
@JaredSmith I would say it is now the general case, not special at all. Nobody writes "a compiler" as a monolithic application any more. They produce compiler systems instead. Most of the functionality of complete compiler is completely independent of the particular language that is being compiled, and much of the language-dependent part can be done by supplying different data defining the grammar of the language, not by writing different code for each language you want to compile.
– alephzero
1 hour ago
add a comment |
This is meant as an addition to the existing answers (and is too long for a comment).
There are at least two other reasons for a standard library:
Barrier to Entry
If a particular language feature is in a library function and I want to know how it works, I can just read the source for that function. If I want to submit a bug report/patch/pull request, it's not generally too difficult to code a fix and test case(s). If it's in the compiler, I have to be able to dig into the internals. Even if it's in the same language (and it should be, any self-respecting compiler should be self-hosted) compiler code is nothing like application code. It may take forever to even find the correct files.
You're cutting yourself off from a lot of potential contributors if you go that route.
Hot code loading
Many languages offer this feature to one degree or another, but it would be enormously complicated to hot reload the code that's doing the hot reloading. If the SL is separate from the runtime it can be reloaded.
This is meant as an addition to the existing answers (and is too long for a comment).
There are at least two other reasons for a standard library:
Barrier to Entry
If a particular language feature is in a library function and I want to know how it works, I can just read the source for that function. If I want to submit a bug report/patch/pull request, it's not generally too difficult to code a fix and test case(s). If it's in the compiler, I have to be able to dig into the internals. Even if it's in the same language (and it should be, any self-respecting compiler should be self-hosted) compiler code is nothing like application code. It may take forever to even find the correct files.
You're cutting yourself off from a lot of potential contributors if you go that route.
Hot code loading
Many languages offer this feature to one degree or another, but it would be enormously complicated to hot reload the code that's doing the hot reloading. If the SL is separate from the runtime it can be reloaded.
answered 4 hours ago
Jared SmithJared Smith
1,247517
1,247517
1
"any self-respecting compiler should be self-hosted" - not at all. It would be pointless to have versions of say LLVM written in C, C++, Objective-C, Swift, Fortran and so on to compile all these languages.
– gnasher729
3 hours ago
@gnasher729 isn't that a bit of a special case (along with other multilanguage targets like the CLR)?
– Jared Smith
2 hours ago
@JaredSmith I would say it is now the general case, not special at all. Nobody writes "a compiler" as a monolithic application any more. They produce compiler systems instead. Most of the functionality of complete compiler is completely independent of the particular language that is being compiled, and much of the language-dependent part can be done by supplying different data defining the grammar of the language, not by writing different code for each language you want to compile.
– alephzero
1 hour ago
add a comment |
1
"any self-respecting compiler should be self-hosted" - not at all. It would be pointless to have versions of say LLVM written in C, C++, Objective-C, Swift, Fortran and so on to compile all these languages.
– gnasher729
3 hours ago
@gnasher729 isn't that a bit of a special case (along with other multilanguage targets like the CLR)?
– Jared Smith
2 hours ago
@JaredSmith I would say it is now the general case, not special at all. Nobody writes "a compiler" as a monolithic application any more. They produce compiler systems instead. Most of the functionality of complete compiler is completely independent of the particular language that is being compiled, and much of the language-dependent part can be done by supplying different data defining the grammar of the language, not by writing different code for each language you want to compile.
– alephzero
1 hour ago
1
1
"any self-respecting compiler should be self-hosted" - not at all. It would be pointless to have versions of say LLVM written in C, C++, Objective-C, Swift, Fortran and so on to compile all these languages.
– gnasher729
3 hours ago
"any self-respecting compiler should be self-hosted" - not at all. It would be pointless to have versions of say LLVM written in C, C++, Objective-C, Swift, Fortran and so on to compile all these languages.
– gnasher729
3 hours ago
@gnasher729 isn't that a bit of a special case (along with other multilanguage targets like the CLR)?
– Jared Smith
2 hours ago
@gnasher729 isn't that a bit of a special case (along with other multilanguage targets like the CLR)?
– Jared Smith
2 hours ago
@JaredSmith I would say it is now the general case, not special at all. Nobody writes "a compiler" as a monolithic application any more. They produce compiler systems instead. Most of the functionality of complete compiler is completely independent of the particular language that is being compiled, and much of the language-dependent part can be done by supplying different data defining the grammar of the language, not by writing different code for each language you want to compile.
– alephzero
1 hour ago
@JaredSmith I would say it is now the general case, not special at all. Nobody writes "a compiler" as a monolithic application any more. They produce compiler systems instead. Most of the functionality of complete compiler is completely independent of the particular language that is being compiled, and much of the language-dependent part can be done by supplying different data defining the grammar of the language, not by writing different code for each language you want to compile.
– alephzero
1 hour ago
add a comment |
Bugs and debugging.
Bugs:
All software has bugs, your standard library has bugs and your compiler has bugs. As a user of the language it is much easier to find and workaround such bugs when they're in the standard library as opposed to in the compiler.
Debugging:
It's much easier for me to see a stack trace of a standard library and give me some sense of what might be going wrong. Because that stack trace has code I understand. Ofcourse you can do dig deeper and you can also trace your intrinsic functions, but it's a lot easier if it's in a language you use all the time from day to day.
add a comment |
Bugs and debugging.
Bugs:
All software has bugs, your standard library has bugs and your compiler has bugs. As a user of the language it is much easier to find and workaround such bugs when they're in the standard library as opposed to in the compiler.
Debugging:
It's much easier for me to see a stack trace of a standard library and give me some sense of what might be going wrong. Because that stack trace has code I understand. Ofcourse you can do dig deeper and you can also trace your intrinsic functions, but it's a lot easier if it's in a language you use all the time from day to day.
add a comment |
Bugs and debugging.
Bugs:
All software has bugs, your standard library has bugs and your compiler has bugs. As a user of the language it is much easier to find and workaround such bugs when they're in the standard library as opposed to in the compiler.
Debugging:
It's much easier for me to see a stack trace of a standard library and give me some sense of what might be going wrong. Because that stack trace has code I understand. Ofcourse you can do dig deeper and you can also trace your intrinsic functions, but it's a lot easier if it's in a language you use all the time from day to day.
Bugs and debugging.
Bugs:
All software has bugs, your standard library has bugs and your compiler has bugs. As a user of the language it is much easier to find and workaround such bugs when they're in the standard library as opposed to in the compiler.
Debugging:
It's much easier for me to see a stack trace of a standard library and give me some sense of what might be going wrong. Because that stack trace has code I understand. Ofcourse you can do dig deeper and you can also trace your intrinsic functions, but it's a lot easier if it's in a language you use all the time from day to day.
answered 31 mins ago
Pieter BPieter B
11k12661
11k12661
add a comment |
add a comment |
Simone Broili is a new contributor. Be nice, and check out our Code of Conduct.
Simone Broili is a new contributor. Be nice, and check out our Code of Conduct.
Simone Broili is a new contributor. Be nice, and check out our Code of Conduct.
Simone Broili is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Software Engineering Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsoftwareengineering.stackexchange.com%2fquestions%2f386296%2fwhy-are-standard-libraries-not-programming-language-primitives%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
What do you mean "why couldn't the compiler simply translate a function call into a set of instructions"? That's roughly what the compiler does, standard library or not (Ok, Python only partway and Java to JVM bytecode; similar concept). Standard libraries really don't have anything to do with the compilation of code -> instructions.
– Delioth
8 hours ago
12
@Delioth I think Simone is asking why isn't everything in the standard library of language $LANG a primitive construct/function of that language instead. I'd say it's a reasonable question for anyone who is very new to programming languages :)
– Andres F.
8 hours ago
@Andres Yes that's exactly what I mean :D
– Simone Broili
8 hours ago
12
The standard library generally fills the gap between a working programming language and a useful one that people will use.
– Telastyn
5 hours ago
2
A significant part of Python's standard library is actually written in C and already compiled.
– ElmoVanKielmo
4 hours ago