7 ms·
Sometimes you just don't have other options than C. Like kernel drivers, embedded (microcontroller) development. Or perhaps you just need to develop a small l
by vardump 9y ago
Sometimes you just don't have other options than C.
Like kernel drivers, embedded (microcontroller) development.
Or perhaps you just need to develop a small loadable library without any runtime (no malloc, etc.). Or perhaps writing Python, Lua etc. C-module for better performance.
You just need to treat C with proper respect, not be too arrogant about your skills.
I hope over time we can move more and more to Rust or some other language which gives as many errors at compile time as possible and helps with not shooting at our feet.
Shouldn't have too many C-macros, of course. Some macro messes I've seen can be nearly impossible to debug...
- pcwalton 9y ago> You just need to treat C with proper respect, not be too arrogant about your skills. We've been hearing "C isn't the problem, bad programmers are the problem" for 40 years. This has continued to perpetuate the problems with the language. I mean, I certainly agree that there are no alternatives to C now for certain domains, but there are real problems with it that aren't solved by just "treating it with proper respect".
- vardump 9y agoHaving programmed C for soon 30 years, I absolutely agree with you that C is the problem. But often you just need to get the job done, and have limited options available. Perhaps in 50-100 years, people looking back at software from this era won't be able to understand how we managed to make it work at all. I haven't met or know anyone mastering C/C++ (especially C++), and doubt I'll ever hear about one.
- jstimpfle 9y ago> I haven't met or know anyone mastering C/C++ (especially C++), and doubt I'll ever hear about one. C can definitively be mastered. C at it's core is pragmatic minimalism. The basic ideas are very simple. If you want to be a language lawyer and know the standard completely (including all historical accidents), it can get complex, but still manageable. But anyways, you shouldn't be a language lawyer. That's not C. Make maintainable programs instead, stay in the middle of the road. C gets out of the programmer's way. It's not about mastering C, but about mastering programming. And while I agree there's much bad C software out there: I haven't seen one maintainable non-bloated Java project. Here is one master of C that I'm sure you know: Linus Torvalds. Of course there are many, many more. Just remember it's not about C, but programming machines in general.
- vardump 9y ago> C can definitively be mastered. If that's true, how come there are almost no widely used network facing C programs that didn't have plenty of security vulnerabilities? (Anything written by Daniel J. Bernstein doesn't count, because there's no way he's a mere mortal. :))
- shaklee3 9y agoWhich language has? Keep in mind market share, so don't say Go.
- littlestymaar 9y agoEven djb had flaws in his C code despite being a semi-god. It took a $10k bounty and several years to be found but it was there !
- hedora 9y agoOpenBSD has done a great job, especially if you look at what they achieved, how fast they got there, and what resources were at their disposal.
- qznc 9y agoQmails direct competitor Postfix? Postfix has more, but Qmail has one with a higher score: https://www.cvedetails.com/vulnerability-list/vendor_id-8450/product_id-14794/Postfix-Postfix.html https://www.cvedetails.com/vulnerability-list/vendor_id-8450... vs https://www.cvedetails.com/vulnerability-list/vendor_id-86/product_id-143/Dan-Bernstein-Qmail.html https://www.cvedetails.com/vulnerability-list/vendor_id-86/p... Postfix is also much more widely used than qmail.
- Avshalom 9y agofor, while, do...while, recursion, goto: is not a sign of "pragmatic minimalism" unless one choses to define it tautologically as "what C has".
- hedora 9y ago
- hedora 9y agoI know plenty of C masters, and a few C++ masters. If you want to meet C++ masters, go to cppcon or get a job writing systems software at a respectable C++ shop. I’d say I had a working knowledge of C++ after about a year ramping up on a codebase based on a mature C++ framework. That was after years of writing reliable, performant C code. My C++ is now significantly better than the C I can produce, on both fronts, and at the same time. I’m also much more productive as a side effect of that.
- pjmlp 9y agoI doubt very seriously that any of those C masters can recite by heart the 200 plus use cases of UB recognized by ANSI C.
- majewsky 9y agoA friend of mine who is working in HPC research (high-performance computing) generates CUDA kernels using higher-kinded templates. He can instantiate you a template<template<class>, template<class, template<uint>>, class> before breakfast.
- agumonkey 9y agoI'm curious about what other languages could be used in place. Maybe ADA ? it's both generic oriented and low level.
- shouldgowork 9y agoWe've been hearing "how long will the problems of C persist" mere persist before people realize there might be reasons it's the most successful programming language yet invented?
- Avshalom 9y agoPath dependency is why. It's not complicated, it's just expensive to overcome.
- pcwalton 9y agoThere are definitely reasons behind C's success. Most important was that it was the language of Unix, which spread like wildfire in the '70s and '80s because it was free. There are equally important reasons why C's usage has been in steady decline from the '90s to today.
- WalterBright 9y ago> Most important was that it was the language of Unix More important was it was the only language that really worked on DOS, which ruled the computer biz for 10 years. I would guess 80% of programming was done for DOS, and C was a very good fit for the 640K systems.
- pcwalton 9y agoWell, sure, but Microsoft wouldn't have chosen to promote C if not for the success of Unix. :)
- pjmlp 9y agoQuite true, and on those days Microsoft was equally promoting Quick Basic and Quick Pascal, while writing MS-DOS in pure Assembly.
- pjmlp 9y agoOn my corner of the planet we were using Turbo Pascal, Turbo Basic, Quick Basic, Clipper, FoxPro, DBase. C and C++ had no special place on the spectrum of programming languages usage, unless we were porting code between MS-DOS and UNIX. Until it was time to move into Windows, and anyone not using C or C++ started to be left behind, manually writing FFI wrappers (e.g. Turbo Pascal/Delphi) and we eventually migrated to one of them.
- nickpsecurity 9y ago"Sometimes you just don't have other options than C." You always have other options if better languages can compile to C or integrate it via FFI. There's been plenty to do that, too. For simple and safe, Modula-2 was early one compiled to C that couldve had syntax modified to be more like it. If aiming for power, PreScheme was a systems dialect of Scheme that compiled to C at one point. The OcaPIC (Ocaml) project and use of ATS language for 8-bit show stuff like that could probably be made to wofk in areas C is used in, too. So, I'd say it's a myth you need to develop in C just because a target has only C libraries or compilers that safer languages can use. Instead, we get a new claim that people just didnt do it for reasons that varied per project or person but wasn't technical capability.
- kurtisc 9y agoFor the microcontrollers example, the 'C' that the device's compiler uses could be a very loose implementation of a subset of the language. How do you ensure that the code you're compiling to will work for it?
- nickpsecurity 9y agoThat's a good point. I doubt most languages generating C put a lot of thought into what subset is supported in proprietary compilers. If anyone tries one, then there could be profiles done for unusual compilers where the generated code has certain properties. Far as the past, I think people couldve tested the output just to see what happened. Then, either ditch high-level language per fuction, module, or project depending on how far incompatibility effects went. How does that sound?
- pjmlp 9y agoDepends on the microcontroler. The majority of them also enjoy Pascal and Basic compilers. https://www.mikroe.com/ https://www.mikroe.com/ So sometimes, there is indeed an option. Also many languages have compilers that are able to generate C code. As to ensuring, well that is what testing is for.
- flavio81 9y ago>Sometimes you just don't have other options than C. Like kernel drivers, embedded (microcontroller) development Use Common Lisp to generate C code. There are three libs that are specific for this, see C-mera for example.
- hedora 9y agoWait. If I use non-tail recursion on a micro controller, then I’ve probably implemented a stack out of memory crash, which, for embedded devices, is actually worse than a buffer overflow on unsanitized input. Is this a joke, or do they do some sort of stack-bounding static analysis?
- sedachv 9y agoWhat are you talking about? Running out of stack has nothing to do with what you use for code generation/preprocessing. I also don't see why running out of stack would ever be worse than a buffer overflow. The former is at least going to be fail-fast.
- pjmlp 9y agoThat is how the .NET GC was originally implemented.
- audunw 9y ago> Sometimes you just don't have other options than C. This is true. With all the new and fancy languages around, it's strange that there are so few attempts at making a better C. I would say that the characteristics of C is: dead simple, manual memory management, "fancy assembly". Rust is close, but fails on being dead simple. The best attempt I know of, is Zig: http://ziglang.org/ http://ziglang.org/ But it's still very early in development. I am using it for microcontroller code right now though, and it's much nicer than C already, despite having to deal with bugs.
- quicknir 9y agoI keep hearing this. How exactly common is it that you can't use C++ for technical, as opposed to human, reasons? gcc is by far the most talked about compiler in this space (at least from what I hear) and obviously it's a C++ compiler as well. My guess is that in most (not all) cases C++ is usable instead of C, but the culture of such development is to prefer C. It's a real pity, because for someone with a moderate amount of judgement (i.e. not going off the deep end on unnecessarily complicated C++), it only takes a moderate amount of C++ knowledge to be able to write more maintainable and correct code that performs equally well.
- Koshkin 9y agoWhat happens in reality though is that as soon as developers get access to the stanard library all hell breaks loose. People switch to the Java mode of thinking and start almost mindlessly using vectors, maps, shared pointers, etc. and C-level performance goes out of the window. With their exposure to templates, there goes their sanity and, as a consequence, code maintainability.