Linux From ScratchThis Forum is for the discussion of LFS.
LFS is a project that provides you with the steps necessary to build your own custom Linux system.
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.
Distribution: LFS 9.0 Custom, Merged Usr, Linux 4.19.x
Posts: 616
Original Poster
Rep:
Quote:
Originally Posted by ReaperX7
I've never really liked plain C code myself. To me C is a dumb language, meaning it's very unoptimized, offers no real compile time benefits, and can't be really updated in syntax. C is just C, it always has been what it is and will be. It's universal and good for porting, but... that's about it.
C++ however was a vastly different story for me. It was highly optimizale, the syntax can be cleaned up more easily, and it has many compiler benefits that can be translated to various architectures.
To me the difference between C and C++ was like comparing Dueling Banjos to one of Beethoven's symphonies.
The optimization of C is not in the compiler, it's in the programmer. The assembly that pops out the other side is predictable. IIRC, C++ programmers have to use templates and such to make sure they don't trip cache misses and what have you. You can find a good overview of the pros & cons of using C at the OS level here.
Torvalds has also talked about this... I tend to agree with his statements except I think C could use some updating. Take a few ideas from Golang and some others. But just a few, the ones that will make the most difference.
I think languages end up dominating the areas they dominate because they're a good fit for that slot in the software layer. C++ is a mid-level API language that still gives some hardware control. C#/Python and all those dominate the top layer, where huge boiler plate libraries are expected and would take too long to write in C.
The way I've tried to explain it to java programmers and what have you is that C addresses the problem domain of the hardware, which doesn't speak object and class, it speaks instructions and data. C is good with those two structures; it was sorta designed for them.
Quote:
In other words, the only way to do good, efficient, and system-level and
portable C++ ends up to limit yourself to all the things that are
basically available in C. And limiting your project to C means that people
don't screw that up, and also means that you get a lot of programmers that
do actually understand low-level issues and don't screw things up with any
idiotic "object model" crap.
So I'm sorry, but for something like git, where efficiency was a primary
objective, the "advantages" of C++ is just a huge mistake. The fact that
we also piss off people who cannot see that is just a big additional
advantage.
If you want a VCS that is written in C++, go play with Monotone. Really.
They use a "real database". They use "nice object-oriented libraries".
They use "nice C++ abstractions". And quite frankly, as a result of all
these design decisions that sound so appealing to some CS people, the end
result is a horrible and unmaintainable mess.
Both forms of music have their places as do the two languages. Nevertheless, as one -- like most -- who started in C and then slowly migrated to C++, I've become more conversant in the latter. Initially, I simply wrote in C++ as if it were a "better C" and ignored the OO aspects. Then as I became more familiar with the essence of the language, the object orientation naturally flowed. I think the real epiphany came when the STL was standardized, especially the really nice things available in <algorithm>. The encapsulating of data and functionality in a class has made my programs less error-prone.
On the other hand, Linus Torvalds has some strong opinions about "Aggie" Bjarne Stroustrup's language:
...and by the way, GCC-4.9.0 is now available and will probably make it into BLFS (if not LFS) before too long. I was pleased to see that <regex> from the C++11 standard was finally implemented after all these years:
Distribution: LFS 9.0 Custom, Merged Usr, Linux 4.19.x
Posts: 616
Original Poster
Rep:
Here, the folks in this stack overflow thread sum it up well. Why, when, how C is better than ++ and when ++ is better than C.
A nice one for C being this:
Quote:
C is portable assembly with better syntax, yielding the programmer full control of everything.
C++ on the other hand, does a lot of funky magic (virtual functions, overloading, automatic conversion, etc etc) which may not be desirable when you want to make sure you:
don't use more memory than you want to
don't access memory pages willy nilly (the vtable can be anywhere)
don't invoke to much code accidentally
And want something really simple to work with, since you're focused on performance.
It just has no surprises, and that's very valuable.
If you want to (and I recommend it), read the JSF coding guidelines on what you need to think about when writing C++ for military avionics control. It's a lot of traps in there that you need to be aware of, and it may catch you out. Bjarne was part of that document, so he knows what it's about.
Also, C compiles like a scalded troll struck by lightning. C++, OTOH, was probably sponsored by the same people who invested in SSD companies .
(Personally, I'd prefer C++ though, but I don't like it...... either. ;-P)
BTW: Don't know why so many folks are down on Torvalds, like him or not the guy has been writing kernel code for 25 years... that's got to be worth some insight.
The more portable code is the less you'll want to drift into anything beyond C as C is fairly universal and an be manipulated on the build end rather within the code.
Because Linux as a kernel is multi-platform, you'll want to assign less architecture code into it as things like SIMD instructions and optimizations for platforms like AMD64/EM64T don't translate to ARM6 or ARM7, or even PPC, RISC, etc.
Distribution: LFS 9.0 Custom, Merged Usr, Linux 4.19.x
Posts: 616
Original Poster
Rep:
Quote:
Originally Posted by ReaperX7
Because Linux as a kernel is multi-platform, you'll want to assign less architecture code into it as things like SIMD instructions and optimizations for platforms like AMD64/EM64T don't translate to ARM6 or ARM7, or even PPC, RISC, etc.
Isn't that the whole point of the preprocessor though? So they're not manually dropping in macro's like the older languages... I don't think it's quite portable assembly, even though that's what its used for. But if you need small, simple, fast and optimized; there it is.
If you're linking an Apache WSDL & and LDAP on another OS to a command line(service) on a third heterogeneous system (something I've done). Hells no, I'm not writing that in C. In fact I've never written from-scratch C programs, always tweaking someone else's.
Distribution: LFS 9.0 Custom, Merged Usr, Linux 4.19.x
Posts: 616
Original Poster
Rep:
This VMWare method is turning out to be a gem. I do this with servers and don't know why it didn't come to mind for building software.
When I run into stuff that doesn't work right I just flip back to the last snapshot. When I am done I can create a "full clone" that will merge all the disk snapshots into a single file.
I'm running to quite a few that don't work: S-Lang is the latest. I was going to install it since it's small and might be useful at some point in nano, but if it requires a lot of troubleshooting then it's not worth it to me since I have no concrete plans to use it.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.