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

--- Quote from: engrguy42 on May 12, 2020, 08:16:47 pm ---Now honestly, I know you guys just LOVE your C and all that embedded stuff, but come on. You can't do that in C. No way. Not possible. GUI stuff? Logging to CSV file? Making realtime charts/graphs that auto-update scaling factors as data comes in? Hell, that would take weeks to do that in C. Maybe months. Or years.

Anyway, I apologize. Just messin' with ya. C RULES!!!  :-+

--- End quote ---

Well there is a lot of truth to that actually.

Technically being able to easily barf out a json/XML file or make a GUI with a few lines is irrelevant of the languages features. It just means having a library that does that thing for you with a few magical function calls. But in practice C/C++ does not provide any more than the most basic functionality from the standard set of libraries that you get with it.

The difference with C# is that the standard set of libraries includes pretty much everything under the sun, from reading and saving jpeg/png images to making HTTPS requests to accessing a database to graphics rendering to sound input/output to asking the OS to not go to sleep mode...etc Okay sure not all of those libraries are really that well made but most of them work really well. So instead of looking for C++ libraries that do the thing, git cloneing them, figuring out how to make them work etc... all you do is stick a "using Windows.Media.Audio;" at the top of your code and you got your library. If the built in libraries don't cut it for the specific thing you want to do you can still go find a C# library online and stick it in.

Not saying that C should also have this, just that this is most of the reason C# is so nice for quickly throwing an app together. The C# language it self is nothing that special, its just Microsofts take on a more performant Java clone. They could have used pretty much any other sensible language and the result would be similar once its packed in with those libraries and a IDE that "just works". That's why VB.net exists, its pretty much C# with Basic flavored lipstick so that the syntax looks familiar to people coming from VB6. Only reason for the C letter in C# is to look familiar to the large userbase of existing C programmers even tho the only thing it really shares with C is the semicolon flavored lipstick. Might be silly but it worked.
nctnico:

--- Quote from: engrguy42 on May 12, 2020, 08:16:47 pm ---Now honestly, I know you guys just LOVE your C and all that embedded stuff, but come on. You can't do that in C. No way. Not possible. GUI stuff? Logging to CSV file? Making realtime charts/graphs that auto-update scaling factors as data comes in? Hell, that would take weeks to do that in C. Maybe months. Or years.

--- End quote ---
Not really. There is a whole flurry of libraries for that. Qt is probably among the most advanced ones.
Karel:

--- Quote from: nctnico on May 13, 2020, 06:11:47 am ---
--- Quote from: engrguy42 on May 12, 2020, 08:16:47 pm ---Now honestly, I know you guys just LOVE your C and all that embedded stuff, but come on. You can't do that in C. No way. Not possible. GUI stuff? Logging to CSV file? Making realtime charts/graphs that auto-update scaling factors as data comes in? Hell, that would take weeks to do that in C. Maybe months. Or years.

--- End quote ---
Not really. There is a whole flurry of libraries for that. Qt is probably among the most advanced ones.

--- End quote ---

I was about to say that as well  :)   And with Qt you are not stuck with windows which is a big plus as well.
hans:

--- Quote from: Wolfgang on May 12, 2020, 04:05:49 pm ---
--- Quote from: madires on May 12, 2020, 03:07:17 pm ---Arduino is C++, just saying. ;D

--- End quote ---

Some thoughts to C++ on microcontrollers with limited memory:
IMHO, a really silly idea. Dynamic memory needs a memory manager, an this needs to take care of
fragmentation, free space recovery, garbage collection... Causing nondeterministic execution times, out of memory errors
when enough memory *should* be there, but not in 1 chunk as you need it and so on.
My strong advice: dynamic memory (malloc), OO string classes, ... forget it if you want a reliable app.
Arduino only works well if you never try something risky. Realtime/Interrupt stuff combined ith OO ? A nightmare.
Keep stack small, always know where your vars are, use C as an interface to machine language (L.Torvalds idea).
That should work on small platforms.

--- End quote ---
I agree that dynamic memory is a mess for embedded. But if you can avoid that, then my experience with C++ is the exact opposite. It's a bliss compared to plain C.

Case in point with the Linux source code: creating structs with function pointers to define several driver implementations according to a particular model, is much like object oriented programming. You can force it in C using that way, or switch to a C++ compiler and use classes.
Even more so, in C++ you get the option of compile-time inheritance and metaprogramming, which are very powerful tools for embedded devices in which we try to minimize run-time computations. These alone can drastically reduce the memory complexity and footprint of a program, while still offering flexibility in switching between hardware and simulation models of your BSP.
In C++ you can perform assertions using actual code, instead of using the rather convoluted preprecessor which quickly becomes a mess, and limits descriptions to pre-compile-time only (whereas in C++ you can use static_asserts with any constexpr function that's already available in the code base)

Keeping track of variables is a good thing indeed, so never use globals. If you can efficiently describe & manage data, it is also trivial to implement unit tests for them with side-effect free setup and teardown code. Unit tests have saved me a ton of time and debugging, in fact.. I hardly do any debugging on embedded devices except for BSP-related code.
olkipukki:

--- Quote from: engrguy42 on May 12, 2020, 08:16:47 pm ---Now honestly, I know you guys just LOVE your C and all that embedded stuff, but come on. You can't do that in C. No way. Not possible. GUI stuff? Logging to CSV file?

--- End quote ---
Why you (or somebody else) need to do this one-off stuff in C?  :-//


--- Quote from: engrguy42 on May 12, 2020, 08:16:47 pm ---And to log its behavior I used my C# data acquisition app (see below). Took me, on and off, a couple days to build that app and put the finishing touches.

--- End quote ---
Also, you probably do not need spend 2 days on that app...  >:D  (aka Python & Co)
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