ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
C - simple, elegant, low-level, incredibly portable. But, if you had to write a new operating system or O.S. kernel, and you couldn't use C, which language would you pick?
"...you coudn't use C.." => it's very unlikely, no?
The real reasons for your question lie probably somewhere else?
Not a trick questions. I am simply wondering what people would consider to be a systems programming language nearly as good, as good, or better than C.
Obviously if I just asked the question "What is the best systems programming language", likely everyone would say "C" because it is tried and commonly accepted, and I would learn nothing from this thread.
Obviously if I just asked the question "What is the best systems programming language", likely everyone would say "C" because it is tried and commonly accepted, and I would learn nothing from this thread.
"C" didn't get that honour by accident. It is very powerful because of the almost unrestricted way you can use pointers (and typecasting).
Other languages (eg Java) try to restrict the ways you can use pointers because of the power that pointers give you in "C" (eg writing viruses). However, these are not intended to be systems programming languages.
Alternatives to "C" might include assembly language or some versions of "Forth" but I don't think many people would consider these seriously.
Obviously if I just asked the question "What is the best systems programming language", likely everyone would say "C"
I would say C++, not C.
If I were writing an OS or OS kernel, I would certainly select C++, not C.
Quote:
because it is tried and commonly accepted,
I see three aspects of that:
1) Leveraging the experiences of others. C has been used the most for the kind of work you describe, so any weaknesses of the language for such purposes has already been revealed. Some other language that seems good for such purposes may have weaknesses whose consequences are not yet fully appreciated.
2) Leveraging the wisdom of others. So many people have chosen C for such purposes, it must be good. I totally reject that notion. People are stupid and consensus is usually built on factors unrelated to whether the consensus is correct.
3) Popularity of a tool forms its own benefit. Even if everyone who chose C for a purpose was wrong, the fact that they did creates benefits for doing so again.
Quote:
Originally Posted by psionl0
"C" didn't get that honour by accident. It is very powerful because of the almost unrestricted way you can use pointers (and typecasting).
I think flexible pointers are a powerful tool in almost any interesting project, and more so in the kind of projects (such as OS kernel) where C dominates.
Most other popular languages are too restricted in pointer use. So more than a specific language (as an alternative to C) I would suggest some criteria, one of which is flexible pointer use, and the related feature of flexible composite structures.
In C (and C++) you can make a complicated composite that has parts directly contained and/or has parts pointed to. So far as I understand parts of an interesting composite in a language like Java must be pointed to. When the language has both those ways for a composite to contain parts, it tends to also need the ability for pointers to point into the middle of an object, something most languages lack.
Quote:
Originally Posted by psionl0
because of the power that pointers give you in "C" (eg writing viruses).
I would hardly list viruses as an example for either the extra power of flexible pointers or the extra danger.
Flexible pointers require extra competence from the programmer to avoid memory leaks and/or using data after it is deleted and/or using data that is the wrong type. I think having all those dangers is inherent in having the flexibility that I think is mandatory.
Quote:
Originally Posted by psionl0
Alternatives to "C" might include assembly language or some versions of "Forth" but I don't think many people would consider these seriously.
Assembly language is a very different niche than C. I never thought Forth to have a valid niche at all, and such technical merit it might have had has vanished as computers got more powerful.
Long ago, I used Bliss a lot. I found its syntax a little more awkward than C, but in many ways it was a better systems programming language. C is not an inherently great language. But the success of C has tended to kill things like Bliss and suppress the development of better languages that fill the same need as C. Meanwhile languages that fill different and narrower needs (Pascal, Java, Python, etc.) are not good alternatives to C for either big projects or "low level" projects.
Even the creators of the g++ compiler chose to write it in C... LOL
That is a project inertia feedback effect..
The gcc compiler is a massive project grown over a long period of time using a lot of extreme C programming to do things that would make far more sense in C++.
Think about what kind of person would join such a project and be productive in that environment. It pretty much requires a fanatic C programmer.
How would the decision be made to start transitioning it to C++? Most importantly who must make that decision? Obviously the people deciding whether to transition the project to C++ are fanatic C programmers, because they are the people who have already proven their dedication and ability in an extreme C project. So obviously they don't want to transition to C++.
Well, historically, for binary digital computers, the first OS was (obviously) written in binary. A rather difficult language, but it works.
Then a small assembler language interpreter was written (in binary, of course) which made things somewhat easier. (That assembler was - sometimes - called "A".)
Then a more compact, untyped, language ("B" or "Bcpl") was written in "A."
That was followed by a typed language, "C," which (along with "A") is still in use.
Those were followed by a large number of additional languages. But they all have one thin in common: no matter which "language" you use, the end result is binary code.
As to code with which to develop an OS, many different languages have been used. (I recall at least one hardware vendor - I've forgotten the name - wrote their OS in FORTRAN II.) Which one is "best" depends on your target. Currently the "hot" languages for OSs are C, JAVA (and Google's derivative variant) and "A" for special devices (usually hidden in "device driver microcode").
Note that "OS" is a vague term. Even here, in a Linux forum, many people refer to a distribution as though that was an OS; others call the combination of the GNU tools and the Linux kernel an OS; and others call the kernel itself the OS.
So, for your question, what do you mean when you say "OS?" And, if you intend to build your whole tool chain, at which level will you start? (And, given the current legal climate, where the US -- and some other jurisdictions -- allow patents on software, be cautious even starting your tool chain from the "binary" level. If you use a patented concept -- weird, but it has happened -- you might be liable for large infringement fees.)
Last edited by PTrenholme; 05-19-2013 at 04:14 PM.
So, for your question, what do you mean when you say "OS?"
In this context, I'm thinking mainly of a kernel, some kind of standard library, and device drivers. You would probably want to do the low level utilities in the same language as well (ls, cd, pwd, etc.) if it was a highly portable language.
Somebody earlier seemed to suggest that one could write an OS in any language. Is that correct? I was under the impression that you have to have the "flexible pointers" component, in order to work with the hardware I/O memory locations. (At least, if you want an O.S. that will run outside of a virtual machine.) Or am I mistaken about that?
BTW, I know that the HOUSE project attempted to make an OS with a modded version of Haskell. I haven't looked into it, but I think one of the key features was some kind of memory manipulation system which was supposed to be both type-safe and flexible enough for systems programming.
GCC now uses C++ as its implementation language [2012-08-14]
The cxx-conversion branch has been merged into trunk. This switches GCC's implementation language from C to C++. Additionally, some data structures have been re-implemented in C++ (more details in the merge announcement). This work was contributed by Lawrence Crowl and Diego Novillo of Google.
.
I am no fan of C++, but as a system programming language it's better than "C" because of better type strictness. C++ is almost exactly a superset of "C".
Well, my current favorite language is pure, which compiles to LLVM "portable" code. With that approach, you could do your development on an existing system, and, when you decided on your target hardware, all you'd need was a LLVM interpreter for that hardware and you'd be "good-to-go." I suspect that it could be done, but I'm 73 years old now and I don't think I'd be interested in trying to do it in the time I've got left to play with such things.
If you're interested, pure is a pure functional language, using (preferentially) "curried" functions. (Both haskell and curry are named to commemorate Haskell Curry. pure could, with some lack of precision, be thought of as a "mild" curry.)
<edit>
A pure example:
Code:
$ pure
__ \ | | __| _ \ Pure 0.57 (x86_64-redhat-linux-gnu)
| | | | | __/ Copyright (c) 2008-2013 by Albert Graef
.__/ \__,_|_| \___| (Type 'help' for help, 'help copying'
_| for license information.)
Loaded prelude from /usr/lib64/pure/prelude.pure.
> fact n = 1 if n==1; fact n = n * fact (n - 1) if n>1;
> map fact (1..10);
[1,2,6,24,120,720,5040,40320,362880,3628800]
> fact 100L;
93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000L
</edit>
Last edited by PTrenholme; 05-19-2013 at 11:12 PM.
@PTrenholme: Thanks! I'm installing it now from source.
Question: Can you explain a little bit about what kind of type system it has, or how it works? I am not quite clear on this: the intro page on its site stated that it is an "essentially typeless" language, but the wikipedia page said that it is a "dynamically typed" language. (I'm coming from a Haskell/GHC background, if that helps with the explanation.)
Everything about that question depends on exactly what you mean by "systems" programming.
If it means "being able to issue specific sequences of processor-specific instructions that run in privileged mode," the C language is ideally suited for that because it is, in essence, an "über-glorified assembler." Although Ada is used extensively in US (military) applications, in the civilian sector at least, "C" remains the workhorse of that, rather rarefied realm.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.