General > General Technical Chat
How many people code in C these days, and if so, why?
<< < (97/99) > >>
rsjsouza:

--- Quote from: coppice on May 24, 2020, 01:49:10 pm ---
--- Quote from: rsjsouza on May 24, 2020, 01:33:35 pm ---
--- Quote from: westfw on May 22, 2020, 03:35:39 am ---There's a cult following who won't like your C++ programs unless they've become completely unintelligible to people expecting to see actual code.  "That's not C++, that's Just C With Classes - you're not even using the STL!
--- End quote ---
I agree, but to be fair I see that with C as well, especially with embedded. Modern compilers do a much better job reducing a somewhat lenghty (but legible) code but developers fall to the temptation to write cryptic constructs with the same effect. Perhaps to showcase how smart they are? Or job security?

--- End quote ---
Don't you realise that every parenthesis is sacred, and only to be used when all alternatives have been exhausted?  ;)

--- End quote ---
:-DD
And what makes me frustrated is to see that any IDE or editor worth its salt highlights the matching parenthesis, brackets, curly braces, etc., making these "savings" even less worth.
nuclearcat:

--- Quote from: Wolfgang on May 24, 2020, 01:55:49 pm ---On small controllers like Arduino, IMHO, C++ is off target. With the very little RAM available,
you have to always know how much space you have, when its allocated and when its freed.
Better forget about any dynamic memory, avoid String classes, and whatever uses it. Little
stack space is OK, keep constants in code space, use global vars when needed, ...
all the dirty tricks. But, most important, there is no "out of memory" message in an Arduino.
When stack and heap (or even static memory) collide thats just a crash in the best case,
in the worst its unrepeatable errors. And you cannot debug that. IIRC there is not even an STL
on an Arduino (would probably need all RAM just for itself).

--- End quote ---
If you use C++ in a way that uses C++ features minimally (for example just C++ classes), you can actually use equal amount memory with same efforts.
This article is in russian: https://habr.com/ru/post/347980/ , but google translate might do job.
At the end author come to almost same stack/flash numbers, but C++ code is much more concise and readable.
I think there is no need to say that the probability of an error in such code is much less.

But there is a simple reason to use C-only - MISRA and alike. C++ is just no-go in such applications.
madires:

--- Quote from: rgarito on May 24, 2020, 08:51:30 am ---My very well-known employer's bread-and-butter networking gear code is all written in C with a little Assembler sprinkled in.  (I'm one of the engineers)  It's equipment that you are literally using every day if you are on the internet, being about 80% of the largest companies in the world are our customers...  A small portion of our GUI code (backend to a web page GUI) is C++.  The entire system is FreeBSD-based (with a heavily-modified kernel) which explains the C.  Being such a large system, there is also a small amount of various scripting languages (bash, python, awk, perl, etc). 

--- End quote ---

That's an area where you have to deliver fast and efficient software, otherwise you would lose customers, And from experience I know that the differences in performance between competitors can be huge. At the same time something contrary is happening at the OSS side. Lots of slow Python to manage the network elements. Professional bodge-ware. >:D
Wolfgang:
I you exclude all C++ goodies (inheritance, STL, constructors and destructors, ...) the question is why you should use it then on a small platform (e.g., Arduino) at all. Just to write classes and methods instead of structs and functions is then more like syntactic sugar.
The code there is size limited anyway, and it *is* possible to write decent code in whatever. Its more a "Torvalds" platform
where he always want so foresee what code the compiler will create of his sources in order to keep contol.
SiliconWizard:

--- Quote from: Wolfgang on May 24, 2020, 02:57:01 pm ---I you exclude all C++ goodies (inheritance, STL, constructors and destructors, ...) the question is why you should use it then on a small platform (e.g., Arduino) at all. Just to write classes and methods instead of structs and functions is then more like syntactic sugar.

--- End quote ---

I agree with this.
Some people seem to like the syntactic sugar though.

I usually use a naming convention with a prefix, so it's really a matter of sugar indeed.

For instance:

--- Code: ---void GPIO_Set(void)
{...}

GPIO A;

GPIO_Set(A);
(or: GPIO_Set(&A), depending on how GPIO is defined exactly.)

--- End code ---

in C++ you'd have something like:

--- Code: ---GPIO::Set()
{...}

GPIO A;

A.Set();

--- End code ---

Cute, but that's sugar. Not even *that* much more compact. Thing is, C++ will tend to make you structure your code "better", whereas in C, you'll need more discipline for a similar result. To some it's not a problem at all, but I must admit I have witnessed a LOT of developers truly lacking discipline.

One aspect of C++ some developers seem to like in embedded settings are templates. Whereas they are arguably "better" and a lot more featureful than macros, they can also be a nice opportunity for shooting yourself in the foot, so I'm not sure I'm completely sold. Never had that much trouble using macros, as long as they follow some rules, are clear and don't have unwanted side-effects.

As some of us have already said, the crux of the matter is to define a subset of C++, with every developer using a slightly different one, and no real standard or hard guideline for choosing one.
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