r/C_Programming • • Oct 18 '26

C limitations

Hi all,

I am currently learning c++. Its okay. Not sexy but also not as bad as some say.

The reason I am learning c++ is that I have read that C has limitations as soon as a project gets more complicated. For example, if you make a scientific calculator with many features like graphs etc.

Trading engines/tools are also not recommended to programm in C.

Since I have not learned C and have only read from some old forum posts etc, I cannot confirm/deny these facts.

I am aware that "everything" is possible and that C++ comes with QoL improvements especially with Classes. But I assume that doesn't mean that someone has to use C only for kernel work. Embedded is also possible with C++ right?

I would appreciate your thoughts and opinions.

The goal of this post is to understand how and if C could fit me more with my goals and what real advantages or disadvantages C has.

51 Upvotes

114 comments sorted by

View all comments

3

u/tastygames_official Oct 18 '26 edited Oct 19 '26

even though they are very similar, they are almost worlds apart, simply because of the (trap) doors C++ opens up with OOP. With C you really can only do imperative programming (of course there is a way to get into true OOP but basically at that point you're better off going with C++), but there is literally absolutely nothing you can't create with imperative that you can in OOP. In fact, I dare say the opposite might be true, as OOP limits you into how things can and cannot be done, so you have to break out of OOP in order to do some things.

Anyway, I love C because it's simple and the logic flows in the code just like it does on the processor (more or less). With OOP, you tend to abstract away the actual computer programming and instead end up focusing on hierarchies and structures and propagation and making all sorts of flowcharts just to be able to figure out where the program logic is. But with imperative, it's literally all right there: line by line.

I recommend learning both, but probably C first. Or if C++, don't start learning classes and OOP until a while later. I've seen programmers with decades of experience simply not be able to do the simplest tasks in imperative programming because they never learned it and can only think in the OOP way, meaning they only think about structures and controlling flow of data rather than the underlying functionality that those complex structures are actually doing. But the opposite is not true at all - imperative programmers have no problem learning and working with OOP. It's frustrating as hell because it's needlessly complex and takes much more effort to read, write and understand, and infinitely more time to debug, but it's very doable.

Do yourself a favor and dive deep into C - maybe even an older standard like C99 or even C90. Figure out how to do everything with that before moving on to "quality of life "improvements"" and "shortcuts" that later standards and higher-level languages offer.

But if after a month of working with C every day you really don't like it and find it too rudimentary, there is no problem with abandoning it and moving on to higher-level languages. Not every programmer needs to be a computer engineer or understand what's happening to the memory or on the CPU every tick. But at least learning about it and getting experience in it will always be a good thing.

8

u/chrism239 Oct 18 '26

Every time you've used 'functional programming' I believe you meant 'imperative, or procedural, programming'.

4

u/pjl1967 Oct 18 '26

Yes. C is procedural. Languages like Haskell, Elm, and OCaml are functional languages.

1

u/tastygames_official Oct 18 '26

indeed. It's been a LONG TIME since I studied the stuff academically (and I did computer engineering and not software, so technically I never actually learnt it as such), but eventually the line in the sand for me became whether or not you can create classes with inheritance and functions all turn into methods. Whereas functions/procedures without hierarchical class structure became "functional" programming (as it's only functions and no classes and you opt for "function over form"(whereas the OOP folks tend to prefer "form over function", as it's all about getting your structure to look elegant, regardless of how complex or nasty or tough to debug it is under the hood).

But yes- I do in fact mean "procedural programming".

Although still to me function = procedure and the functionality is what I'm all about. So it is still "functional programming", even if it's not "functional programming", if that makes sense ;-)

English is a fun language.

2

u/LordRybec Oct 19 '26

You should learn Haskell. That should help you separate "functional" from structured procedural programming. Having functions does not make a language "functional". In programming terms, "functional" refers to functions in terms of math not in terms of subroutines. Programming borrowed the term "function" from math and then blindly applied it to subroutines due to largely superficial similarities. What you view as "functions" are not actually functions. They are programming subroutines that we've incorrectly applied the term "function" to. In a programming context, when you say "function" we all understand what you mean. But when you say "functional", that means (even in programming terms) languages modeled after actual mathematical functions rather than just programming subroutines. Languages like C and C++ are not even remotely "functional" languages and do not use "functional programming". What they use is called "structured programming", which is a subset of imperative programming.

"Procedural programming" technically includes structured programming and functional programming, so it's not a useful distinction here. Structured programming includes subroutines, functions (by the mathematical definition), loops, etc..., which both structured imperative languages and functional languages both have. So C is procedural but so is Haskell, Lisp, and other functional languages. The correct term here is imperative. C is imperative, Haskell is functional. Both are procedural. (Technically functional languages are also structured, but we don't generally called them that. The term "structured" was originally used in programming to distinguish between functionless languages like assembly (which also doesn't even have formal loops) and some versions of Basic and languages like C that have functions and formal loops, all of which are imperative.)

Anyhow, if you say "functional" in terms of programming languages, that term means languages like Haskell, Lisp, and others. It does not mean languages that have subroutines which we've collectively applied the term "function" to, even though they are rarely actually true functions. So if you insist on using the term incorrectly, expect to continue being corrected and misunderstood.

I'm not trying to be rude here, but when people within a community insist on continually using well established terminology incorrectly, it hurts all of us.

1

u/tastygames_official Oct 19 '26

yeah, I know the difference, but I just like the play on words. Like how a knife is "functional" as it "serves a function", so is it in my mind with "functional programming": you write commands and procedures to serve a singular function (change some data, save it to disk, send it across the internet, change the color of an object on screen, etc). But I know that in computer science they mean something else.

I just prefer logical steps instead of "magic" stuff that happens due to structure. I actually like wikipedia's example on imperative vs. functional: https://en.wikipedia.org/wiki/Functional_programming#Imperative_vs._functional_programming

# imperative
int[] numList = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
int result = 0;
for (int i: numList) {
    if (i % 2 == 0) {
        result += i * 10;
    }
}

# functional
import java.util.Arrays;

int[] numList = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
int result = Arrays.stream(numList)
    .filter(n -> n % 2 == 0)
    .map(n -> n * 10)
    .reduce(0, Integer::sum);

so I can see how somebody who is not a programmer will like the functional one more since it reads like a human thinks: "ok, so we we take our list of numbers, then filter them by whether they are even or odd, then multiple each of those by 10, then sum them". But this is too high-level for my taste as you don't know exactly what's happening each step of the way. While this is fine for a simple example like this, in real life when we need good performance and scalability, knowing exactly how each of thse steps of the process work is CRITICAL. And if, for example, we need to modify one of the steps in this process, it becomes a Herculean task as each function is built on top of another function in another class and implementing another interface and so you really have no other choice than to go to imperative programming to get your custom code to run. Either that or stick with the hierarchical logic of functional programming and extend the logic tree to create a superset of commands that now can be controlled via a flag or maybe it's a whole new implementation or something. It drives me absolutely insane when I know EXACTLY what needs to be done but have to fight with some kind of hierarchical abstraction to get it to do what I want. It's like knowing that the fish has to go into the frying pan but all you have are ways to put it in the oven. The burner is right there, as is the pan, so just use them. But instead you have to define a new class that can either be a stovetop or an oven and then a baking tray or a pan, and then make sure they all have implementations of the cook() and check_doneness() functions that are inherently way different but because we need this hierarchy, we must shoehorn our log into this structure. And god forbid we want to bake the fish in the oven and finish in the pan for crispiness - now we have to abstract the cooking process to include a "Listable" interface or something with each node being a step in the process that can be be potentialy infinite even though our use case is simply one or the other.

Anyway, this is giving me anxiety. Time to go back to "functional" (imperative ;-) ) programming in C. Have a nice day!

2

u/LordRybec Oct 19 '26

Ah, I see. Then maybe just make it more clear that it's a joke, so that people don't get confused!

As far as the rest goes, I generally agree. I really like Haskell, but I never use it, and part of the reason is not knowing what is going on under the hood. Most of my programming is low level stuff. Either it's full on microcontrollers, or I'm going super low level number manipulation. This is really easy to write and to follow in C. I can do complex pointer manipulation stuff to work with 8 or 16 or 32 bit partitions of 64 or 128 bit values, and it's still fairly easy to see what is happening. I don't even know if I can do stuff like that in Haskell. And in microcontroller programming, things like order of operations are really important, and I spend a lot of time manipulating registers and such. Order of operations isn't guaranteed in functional languages. I actually think I can do register related memory accesses in Haskell, with unsafe memory accesses, but it's basically imperative at that point anyway, and Haskell does not make that stuff easy. I wrote an Asteroid clone in Haskell, for my undergrad senior project (my idea, as I figured if I could do a real-time game in Haskell, I could do pretty much anything), and it actually wasn't too bad, but it certainly wasn't even remotely well optimized. I'm not sure I'd do a game in Haskell again, due to the optimization thing, but what I do for my daily drive/job just doesn't work in functional at all. Functional is like asking the system for the outcome you want, and then the compiler does its best to do it. That only works if the compiler understands the underlying hardware well enough to know how to achieve that outcome. With imperative you are giving it the steps you think will achieve what you want. That means bugs are more likely, but it also means you have 100% of the power available within the system/OS you are coding for.

So as much as I like functional, only imperative (and especially low level like C) can do what I need the way I need.

2

u/tastygames_official Oct 19 '26

I think I'll just go back and edit my comment to say "imperative" instead of "functional"

1

u/Ok_Reserve996 Oct 18 '26

Thank you very much! Can you give me some examples where the difference is visible? Or will it be something that I have first to experience myself while coding?

3

u/chrism239 Oct 18 '26

My favourite distinction is:

C: mow(the_lawn);

.vs.

C++: lawn.mow_thyself();

2

u/mjmvideos Oct 19 '26

But it could be: gardener.mow(the_lawn);

1

u/tastygames_official Oct 18 '26

it's perhaps complicated to explain to a beginner, but basically a typical C functional programming snippet might look like this:

/* some function that modifies the cart */
update_cart_total(&cart);

/* check prices or something */
for(i=0; i<cart_size; i++) {
  if(cart->item[i].price <= 0) {
    cart->item[i].price = 0;
  }
}

So you just chug along and do one thing after the other and jump into functions whenever they are needed. But for OOP (which C++ tends to be, even though you technically don't have to write OOP) is more like this:

InputParams input_params = InputParamFactor::get_instance()->retrieve_input_params(user_context);
Cart cart = CartFactory::get_instance()->retrieve_cart_by_input_params(input_params);
cart.update();
CartIterator price_check = CartIterator::new({...bunch of data abstracting out the price check iterator logic instead of just programming it...})
CartIteratorHandle h_price_check = cart.add_iterator(price_check);
CartIteratorFactory::get_instance()->perform_iteration(h_price_check);

so you can kinda tell what's going on, but there's a lot of boilerplate stuff to make it all work within common modern paradigms and design patterns, so it just ends up making the code really hard to read. Notice how many extra functions you have to call and variables you have to create just to save yourself from writing out the logic by hand. The whole idea with these OOP design patterns is to have the structure do all the work so you only ever just pass around some configuration settings and everything just "magically" gets done. But the worst part is when you look into one of the functions to see what's actually happening it just looks like this:

void CartIterator::run(IteratorItem *item) {
  IteratorSettings settings = IteratorSettingsFactory::get_settings_for_iterator(item);
  return item->run(settings);
}

so it's a neverending chase to track down where the code is actually being executed as every function is written small and only ever does one thing so it can be unit-tested but this means you never have a full understanding of what's going on without looking through tens (if not hundreds) of functions and files just to track down what's going on.

Maybe I'm biased, but when I entered into software development as a career (after maybe like 10 years of doing it "just for fun"), I quickly was forced into doing everything the OOP way for a lot of stuff and it just really got to me over the years (decades, really), so I'm so super happy to be back in functional programming land where everything is right there in one place and the logic follows top to bottom rathe than having to look through an entire project just to find its entry point.

4

u/frasnian Oct 19 '26

Your contrived "c++" example is an abomination. No working professional would write code like that.

This is how you tell me that you don't actually know C++ and have never really used C++ professionally without actually saying that you don't actually know C++ and have never really used C++ professionally.

3

u/LordRybec Oct 19 '26

Lol! Yeah, I've seen professional C++ code just like that, from those with 5 to 10 years or more of experience. In fact, I've seen worse and then rewrote it in C myself to eliminate the temptation for someone "maintaining" the code in the future to turn it back into that kind of abomination. This is part of the reason I prefer C. There are a lot of bad C++ programmers out there who would write much better code in C because C doesn't leave room for writing code that terrible!

2

u/tastygames_official Oct 19 '26

I once rewrote a core API endpoint for a client that was causing some problems. They were using some framework and had all this "magic" dependency injection stuff going on and the guy who made it was super proud about how clever it was and easily extensible it was (it wasn't - it was only extensible if you had to do add another use case that already uses the same exact data format).

Anyway, it was very slow so I was brought in to consult, and for shits and giggles I rewrote the most complex use case as just a single, straight-shot program with no OOP, no framework - just literally data in -> process -> data out. I didn't even to any kind of optimization (paralellization, caching, more performant data structures) and got a 175x speed boost. I asked if this would be a direction they would like to go in, and the guy who made the system (CTO or head of tech or whatever) told me "that's not really programming!" He was as just as old as I was, and had a degree in something software-related, but seriously thought that unless you use some kind of hyper-abstraction paradigm it's "not really programming". Absolutely blew my mind.

Since then I've encountered more and more "software architechts" who seem to think that you need it to be complex and abstract in order to be "real". My guess is that it has to do with how they were taught - probably skipped the basics and went right to learning the frameworks/paradigms. The worst part? companies (and customers) seem to not care about performance or simplicity anymore. Sofware is continuously rolled out now so anything that doesn't work today can be fixed tomorrow and people are just OK with it.

3

u/LordRybec Oct 19 '26

Like people who think Python isn't a "real programming language". I mean, Basic was widely considered a real programming language, and it was interpreted as well. And modern Python generally isn't even interpreted. It's compiled to bytecode and then run through a sort of emulator. It's basically the exact same model Java uses, except that Python isn't so egotistical that it calls the emulator a "virtual machine", despite no such machine actually existing.

Yeah, anyone can write massive piles of code to do a simple thing. A real programmer can do the same thing in very little code. But too many people take far to long to understand that, and some never figure it out.

2

u/tastygames_official Oct 19 '26

perfect take on python/java ;-)

1

u/tastygames_official Oct 19 '26

it's a generic OOP, not necesssarily C++. But yes - most of my time in the last 30 years or so has been with Java, PHP, TypeScript, C# were the most recent and worst offenders. My last foray was a C++ project (godot) before calling it quits and moving over to C forever. But these design patterns hold true no matter what language. It usually gets that way when it's some sort of framework or platform that everyone uses and it's just awful because it's so generic and abstracted to hell.

Don't take offense - all languages have their merits but I'm just staunchly against OOP at this point in my life because it's always going to get abstracted to hell for the sake of "looking nice" rather than being functional or performant.

Object-Oriented Programming is Bad
"Clean" Code, Horrible Performance
Abstraction Bad? | Clean Code : Horrible Performance
The purest coding style, where bugs are near impossible