General > General Technical Chat
How many people code in C these days, and if so, why?
<< < (15/99) > >>
profdc9:
I use C++ somewhat for embedded programming but sparingly.  Mostly I have used C.  I have tried C++ from nearly the beginning in the early 90s.

At first, the compilers were flaky and produced code that didn't work.  This was eventually fixed.

But the C++ added every "kitchen sink" feature that every other language had.  Writing a compiler for C++ must be horrendous.

The problem with C++ for embedded programming, as I see it, is that it is difficult to audit what code is produced (in size and complexity) when using some of C++ more advanced features.  Templates will bloat code enormously.  Virtual functions and methods are ok and are probably my favorite feature of the language, but you must be careful casting pointers to make sure that the correct vtables are referenced.  However, other languages do polymorphism better (e.g. Objective C).  Exception handling is a hot mess.  It introduces so many potential code paths that it is very difficult to know how your code will unwind.  gotos are better in my opinion because at least you know where the code is jumping to and where its jumping from.  Overloaded functions and operators may look nice but also add the possibility of calling the wrong function, especially if the overloaded function has nearly identical functionality (for example, a reference counted version of a regular function).  Add to that weird rules for constructors, destructors, when they are called, etc., and you got something deeply confusing and waiting for human error.

C may be the manual transmission of coding languages, but it's going to get you there, and you're going to know how much the engine revs when it does.
SiliconWizard:

--- Quote from: engrguy42 on May 06, 2020, 02:36:09 pm ---
--- Quote from: SiliconWizard on May 06, 2020, 02:22:45 pm ---Note that you can write (as some of us have already pointed out) code in an object-oriented manner in C. Whether it's more clunky than using C++ is all a question of perspective. As long as you know how to do it, and don't want to implement fancy OO features (which are often highly debatable anyway), doing that in C is not really that much clunky. I'm used to it. I've done that both in C and C++, and quite frankly, if done right, it doesn't even take more lines of code in C, or not significantly so. I'll admit that if you do that, you'll get less "verification" from the compiler, so in that respect, you need to be extra careful.

The same goes for functional programming -  you can pretty much program in a pure functional way in C. But to be frank, contrary to OO, where it doesn't really add any overhead compared to C++ (again if done right, and again as along as you don't try super fancy paradigms), pure functional programming in C WILL add overhead (sometimes considerable) compared to true functional programming languages that natively optimize a lot of internal data structures and data passing.

You can of  course also use a mix of approaches.

--- End quote ---

Absolutely true. You CAN do just about anything with any software, just like you can probably build a house using only a screwdriver  :D

IMO, what's important is that folks are familiar with each of the tools enough to know what's best for each task, and not restricted by a vague bias based on minimal experience.

--- End quote ---

I think we managed to all be reasonable in this thread, and avoid flame (and language) wars. Let's try and keep it that way.

Your comment was of course overly caricatural. My point was mainly to express 1/ what *I* do and why (which was the OP's question) and 2/ just correct the frequent misconception (especially for people exclusively using "higher-level" languages) that C code necessarily has to be a poorly structured mess of functions, global variables and loose data structures, and that you necessarily have to use some higher-level language to write "cleaner" code.

And of course, if you read my post,  your comment is a bit off: I just pointed out cases where using a reasonable OO paradigm in C would NOT necessarily be much more clunky than in C++ or other. Surely "clunky" is a somewhat subjective appreciation, so not everyone can agree on what it exactly means for them.

You won't do that without a generous amount of experience anyway, so your second sentence holds, but I vaguely feel like it was meant to defeat my point. It doesn't. If anything, using C++ because you're convinced it's way better than C for OO programming in general could fall into the category of "vague bias based on minimal experience."

Corollary of all this is, sure "the right tool for the job" - a common and general quote, but not always as clear cut as it looks. Whatever is right for a given task depends on a number of factors including the engineer's experience. Someone's right tool maye be someone else's worst nightmare - for the exact same project.
IDEngineer:

--- Quote from: profdc9 on May 06, 2020, 04:26:01 pm ---Overloaded functions and operators may look nice but also add the possibility of calling the wrong function
--- End quote ---
Overloading is my most hated aspect of C++ (or any language that employs it). Honestly, it feels like it is intentionally designed to cause errors. Sure I get the theoretical convenience of it, but ultimately code has to be 1) written, 2) debugged, 3) tested, and 4) work in real life. Overloading "feels" like it helps with #1 but it makes #2 and #3 much less deterministic which risks the reliability of #4. That's a Faustian Bargain.

The danger of overloading was proven to me most forcefully when I was debugging a function that was one of an overloaded family. As I stepped through the code, nothing made sense. Variables weren't changing the way they should, the debugger would skip lines of code when I single stepped, etc. I finally dropped into the disassembly listing and, looking at the program counter, realized the debugger was displaying the wrong source code... it matched the name (of course) but was the wrong overloaded function! It's bad enough that overloading can fool a human, but when the native debugger can be tricked - nope, no thank you. Once again you're working too hard to accommodate your choice of tool. Tools (whether T&M equipment or software) are supposed to make the job easier, not get in the way.
nctnico:

--- Quote from: SiliconWizard on May 06, 2020, 05:02:01 pm ---
--- Quote from: engrguy42 on May 06, 2020, 02:36:09 pm ---
--- Quote from: SiliconWizard on May 06, 2020, 02:22:45 pm ---Note that you can write (as some of us have already pointed out) code in an object-oriented manner in C. Whether it's more clunky than using C++ is all a question of perspective. As long as you know how to do it, and don't want to implement fancy OO features (which are often highly debatable anyway), doing that in C is not really that much clunky. I'm used to it. I've done that both in C and C++, and quite frankly, if done right, it doesn't even take more lines of code in C, or not significantly so. I'll admit that if you do that, you'll get less "verification" from the compiler, so in that respect, you need to be extra careful.

The same goes for functional programming -  you can pretty much program in a pure functional way in C. But to be frank, contrary to OO, where it doesn't really add any overhead compared to C++ (again if done right, and again as along as you don't try super fancy paradigms), pure functional programming in C WILL add overhead (sometimes considerable) compared to true functional programming languages that natively optimize a lot of internal data structures and data passing.

You can of  course also use a mix of approaches.

--- End quote ---

Absolutely true. You CAN do just about anything with any software, just like you can probably build a house using only a screwdriver  :D

IMO, what's important is that folks are familiar with each of the tools enough to know what's best for each task, and not restricted by a vague bias based on minimal experience.

--- End quote ---

I think we managed to all be reasonable in this thread, and avoid flame (and language) wars. Let's try and keep it that way.

Your comment was of course overly caricatural. My point was mainly to express 1/ what *I* do and why (which was the OP's question) and 2/ just correct the frequent misconception (especially for people exclusively using "higher-level" languages) that C code necessarily has to be a poorly structured mess of functions, global variables and loose data structures, and that you necessarily have to use some higher-level language to write "cleaner" code.

And of course, if you read my post,  your comment is a bit off: I just pointed out cases where using a reasonable OO paradigm in C would NOT necessarily be much more clunky than in C++ or other. Surely "clunky" is a somewhat subjective appreciation, so not everyone can agree on what it exactly means for them.

You won't do that without a generous amount of experience anyway, so your second sentence holds, but I vaguely feel like it was meant to defeat my point. It doesn't. If anything, using C++ because you're convinced it's way better than C for OO programming in general could fall into the category of "vague bias based on minimal experience."

Corollary of all this is, sure "the right tool for the job" - a common and general quote, but not always as clear cut as it looks. Whatever is right for a given task depends on a number of factors including the engineer's experience. Someone's right tool maye be someone else's worst nightmare - for the exact same project.

--- End quote ---
Well, there is also something like the 'right person for the job' who can handle the right tool for the job. Personally I'm not a fan of doing OO in plain C. C++ makes life a lot easier by hiding all the nasty stuff which results in much easier to read code. The Linux kernel is a particular poor example of doing OO in C. It is a huge convoluted mess.
Wolfgang:
Its generally not smart to mingle OO and real time. Reason: OO resource management is somehow unpredictable and might add uncalculatable runtime when you cant afford it.
No usable OS kernel I know is written in an OO language. Not even Windows :)
Navigation
Message Index
Next page
Previous page
There was an error while thanking
Thanking...

Go to full version
Powered by SMFPacks Advanced Attachments Uploader Mod