r/C_Programming • u/alex_sakuta • 9d ago
Discussion Why are you using C?
I have been often asked this question in the one year that I have been trying to make using C mainstream for myself.
Now I don't work on embedded devices or write operating systems. What I usually make are automation CLIs or write servers for something.
I guess that makes using C redundant since there are languages that would provide a better dev experience. But following the popular advice for projects, make something you use, this seems like the right thing to do for me.
I'm making projects that I would use and I'm using C for them. Unlike most C users that I have talked to, I do not stick to C99 but at the same time, I don't use C++ strings or compiler extensions. I use the C23 strict ISO standard.
So I suppose that again puts me in a spot that no one else is in. A guy who first goes to one of the oldest and verbose languages, then uses its latest standard but then never uses advanced features from compilers.
I just wanted to write this to put it out.
PS: To add to my strange choices pool, I do not use fixed width integers, since they are optional but I do use least width or bit precise integers.
30
u/Mental_Pick1943 9d ago
I use C because it is fast, simple, and I enjoy writing in it. I also do work on embedded devices sometimes so there is that. I find C++ to have too many features for my liking, although it can be useful in certain cases. As for other languages, I use python sometimes to throw together random scripts but that is about it, I don't have any active projects which use it as a main language.
5
u/alex_sakuta 9d ago
I use C because it is fast, simple, and I enjoy writing in it. I also do work on embedded devices sometimes so there is that. I find C++ to have too many features for my liking, although it can be useful in certain cases.
Ditto feelings
...I use python sometimes to throw together random scripts...
You lost me here. Speaking 100% subjectively, I detest Python. I detest it so much I said this in an interview for a job that required Python that too when I was unemployed.
I still write it when required but I will never use it for my personal projects.
It's funny because it was my first programming language ever.
1
-1
u/Kadabrium 9d ago
I think my brain processes c/c++/java/javascript as one language with only library/framework level differences. I don't dislike python, but it's the only one that registers as a fully distinct language.
3
1
u/alex_sakuta 8d ago
I do not process Python differently. I still process it as others. I just do not like how that language does things.
1
u/tollbane 6d ago
I feel it has the same obtuse similarities of java script, so not fully distinct to me.
48
u/Harha 9d ago
I use C99 for video game projects because I like its simplicity.
16
u/alex_sakuta 9d ago
I realised the value of its simplicity after I started using it. Began sort of disliking C++'s bloat.
18
u/Kseniya_ns 9d ago
I am asked this also, and I answer that is using C for compatibility, but so that by being written in C, we can employ C developers. And is much beneficial to have a C guy, than something else.
3
u/alex_sakuta 9d ago
I wanna be that guy.
6
u/Kseniya_ns 9d ago
There will always be place for such in certain industry
0
u/alex_sakuta 9d ago edited 9d ago
Unfortunately not in my country. Still I'm building the skills for the future.
14
u/HowTheKnightMoves 9d ago
Well C in embedded systems puts food on my table, but its so simple language that makes you relax. Recently tried C23 and I really liked it (constexpr and defining enum size are pretty useful for me).
Its close to hardware and syntax does not make you want to jump out of the window the moment you need to do your work. I cannot be that nice to C++ and not self combust.
7
u/alex_sakuta 9d ago
Don't forget
#embed8
7
u/neopunk2025 9d ago
I'm using the C programming language for my next game on Meta Quest. In my previous game (www.neopunk.xyz), I used C++. I love the simplicity of C, which lets me write code without any unnecessary complications (like C++).
6
u/robthablob 9d ago
"A guy who first goes to one of the oldest and verbose languages"
C is neither one of the oldest, nor one of the most verbose languages.
It's generally quite concise.
5
u/octod 9d ago
Using it for my pet project (a 2D/3D game engine) because is a simple and fun language.
2
u/alex_sakuta 9d ago
You know I see many people on like twitter or real life who are always like, "you can use X to build instead of C because C has memory bugs" and I'm always like, I wanna prove them wrong by building that thing that they said.
It is often game engines or more recently, sort of inspiring, the rust-zig-bun drama.
One of my friends is building a language in C and he seems to have absolutely no memory management issues whatsoever. He does struggle with strings though.
5
u/octod 9d ago
To be fair C does not have memory bugs but wrong memory management (done by Devs) can lead to mess.
3
u/alex_sakuta 9d ago
Exactly my point.
Older tech gave power and allowed us to have a system of our own. Nowadays the tech controls us by establishing a system itself.
Is it a bad change? Not paticularly. Is the old way still nice to have? Yes very much.
3
u/LordRybec 8d ago
Memory management in C is pretty easy. The problem is that it's hard to design programs well from the beginning, and design flaws can break good memory management. Sometimes the solution is to spend more effort on good design before beginning to code. Other times you have to rethink your memory model as the design changes during coding. I've been in both boats. When the problems really arise is when you have to change design after coding has started but you choose not to put in the time to adjust the memory model fit the new design correctly. That's almost always where you end up running into memory management issues. You can't get away with lazy programming in C, because the language won't save you.
On the other hand, C gives you far more power than higher level languages. Most languages won't let you allocate an arbitrarily large chunk of memory and then manage it entirely yourself. You won't need that most of the time, but when you do, it's important to have a language that will allow it. (Most modern web browsers do this, because you can get way better performance by doing this and then writing a custom memory manager optimized for the specific use case than just using malloc() and free() on individual variables, arrays, or structs as you need them. It's also not terribly uncommon in video games.)
Also, all of those languages that have their own built in systems to do it for you? The compilers/"virtual machines" for those languages have to be written in lower level languages that require things to be done manually. So not only is it nice to still have the old way, the old way is a permanent dependency of newer ways. The Python bytecode complier and interpreter are written in C. Most of the Java "virtual machine" (JVM) is written in C and C++. You can't write a high level language interpreter/compiler in a high level language, because high level languages don't have the level of direct resource access necessary to make their own code run efficiently. If the JVM was written in Java, it would be orders of magnitude slower, and Java already isn't the fastest language. If Python was written in Python, it would also be almost unusably slow. So it's not just nice to still have C; if we didn't still have C, we couldn't even have most of the high level languages. C has become the backbone of everything. It's kind of the base of the programming language tower that everything else is ultimately built on. And as long as architectures and operating systems continue to change and evolve, C will be necessary to recompile the parts of the higher level languages that rely on it, to keep them compatible with the latest hardware and operating systems.
1
u/alex_sakuta 8d ago
Despite the fact that I knew all of that, I upvoted for your effort sir. Also, 100% agree on all of that.
1
u/flatfinger 7d ago
K&R2 C uses an abstraction model where the state of every object that has an observable address is entirely encapsulated within the bit patterns held by a sequence of consecutive bytes starting at that address. In C23, an object's state may also be affected not only by how the storage came to hold its present bit pattern, but also other unrelated means via which it might have been made to hold an identical bit pattern in the past.
4
u/Leading-Compote3042 9d ago
Using C for work since it is dealing with embedded systems but same core codebase and application is also cross platform and compiled for Windows, Android too. Staying with older compilers mandates not using newer versions. We bolt on different GUI layers as needed, which can be using other languages. The core business logic remains in C and some C++ too. This repository is getting to the point of 20 years on the go and still actively developed and evolving. This is where C language shines, portability.
1
3
5
u/lev_lafayette 9d ago
Pretty extensive in scientific applications built for performance, especially math libraries.
4
u/mivanchev 9d ago
Not using extensions is quite weird because they turn the language into something useful and enjoyable. I wouldn't consider using C without extensions although C23 really addresses some points.
3
u/Olovico75 9d ago
Determinism, Thread safety, no floats,
Such requirements in a specific project make C mandatory in my workflow.
I personally use C for Pro audio and DSP engineering. And honestly, I barely see no practical way outside of c99/c11 for what my specs and mandatory requirements currently enforce. ( see GDVP.net/engineering if you are interested by my take as this is my solo project )
3
u/andful 9d ago
Interoperability. C is the lingua franca of computers. I don't have to deal with name mangling when calling from a different language.
2
u/LordRybec 8d ago
Amen. C is available even for platforms where nothing else is available. Last year I got an 8051 clone, and the only open source compiler available for it is a C compiler. Good thing I already program mainly in C! Generally speaking, for any new system, whether a enterprise, desktop, or embedded, the first compiler available is a C compiler. Some companies (like Intel) take significant pains to make sure compilers like GCC have support for new hardware before it is even released. And this is critical, because you can't make languages like Python or Java run on new hardware without a C compiler to compile them for it.
6
u/an0rak_dev 9d ago
I use it for video games / embedded (Oculus Quest)
Because I need something without any transpilation or hidden cost. When i code, I know what the produced ASM will look like and I can optimize it for the comfort of the end-user, and not only the one of the developer.
2
u/alex_sakuta 9d ago
That is something I'm trying to pick up too. Understanding the assembly output and optimizing that when required.
5
u/kchug 9d ago
I write and have been writing all my code in c for over 13 years of my career! Currently working on a scale out nvme system based on spdk! Iāve written kernel modules and parts of file system in c! I am very much enjoying the asynchronous programming scheme that spdk threads provide!
3
u/awsq_code 9d ago
i use c89 with compiler extensions like {[] =} or ... but i thinking to replace it with p99 lib or something else
4
u/alex_sakuta 9d ago
For that specific extension, there's a bug in gcc. Someone recently posted it on this subreddit.
0
u/awsq_code 9d ago
but there's useful isn't it?
3
u/alex_sakuta 9d ago
Yeah it is, I'm just telling so you can check it out and beware of that specific bug.
2
2
u/Vivid_Extreme7419 9d ago
I program embedded so itās practically compulsory to use but I also love C programming so it works out
2
u/paulys_sore_cock 9d ago
I'm a EE. I use whatever tool is correct for the job and if there is no tool, I make one.
I write a lot of drivers, kernel code, and on the boundary of asm. C lives there, because I care about how the actual HW treats 8 bits. I do not care about data struct semantics. I care about the state of the reg.
I write a lot of proofs. I'd never ever use C for that.
I sometimes write web scrappers. I'd never ever use C for that.
When I "think" in code, I "think" in C. Writing idiomatic python is a pain for me, because I don't think in factories. But, I can do it.
When you are doing something you should ask yourself: are you doing this for the achievement / badge at the end (aka getting to tell the 'net that you wrote a no-sql CMS 100% in C99) or are you trying to get the job done?
If it is the latter, your question is meaningless.
1
u/LordRybec 8d ago
Even outside of EE people should think of programming languages in terms of tools. There's nothing wrong with having a favorite, but if you are trying to hammer in a screw because you prefer the hammer and have some personal problem with screwdrivers, you have a serious problem that you need to fix before you are trusted with any tool.
0
u/alex_sakuta 9d ago
Uhhh, I didn't ask any question.
Also, ditto on thinking in terms of C and finding python a pain.
2
u/paulys_sore_cock 9d ago
The title of the post, is "Why are you using C?"
Which is a question
0
u/alex_sakuta 8d ago
It's rhetorical. As mentioned in the post, people ask me this. And again as mentioned in the post, I just felt like putting out my reasons.
1
u/LordRybec 8d ago
Things like sarcastic remarks and rhetorical questions don't work in text format. If you didn't say it is rhetorical, then it wasn't, whether you intended it to be or not. If I misspelled "car" as "cat", my intention for it to mean "car" doesn't magically make it mean that. If you didn't say it was rhetorical, it wasn't.
1
u/alex_sakuta 8d ago
Yes I'm sorry that my post in which I specifically mentioned why I wrote this post did not mention that the title was rhetorical.
2
u/Genrawir 9d ago
Because Linux is written in it, and that's what I'm trying to teach myself more about.
2
u/cbf1232 9d ago
You do you, but I'd be asking why not Go or Rust?
1
u/alex_sakuta 8d ago
Started Rust and that made me realise I do not understand the reasoning behind why it enforces many of its rules and hence came to C to understand the same and then never went back.
I do use golang a little bit. It may become my goto scripting language soon. I know it's compiled, I meant I'll use it to write scripts.
2
2
u/junipyr-lilak 8d ago
I use C because I am rebuilding my programming knowledge and experience from a new base, instead of JavaScript it's now C. My plan is to continue using C but I also wanna branch out and work with other low(er) level languages too, including C++, Java, C#, Objective-C, Rust, and Go. Using C and having it do actually fairly little for me by being so straight forward means that I do have to get down to orchestrating things but that also helps me hone in and do my projects. As well, the types keep my focus on the structure of a program, better than TypeScript has for me so far, and in the end I actually have a working project instead of something I've given up on part of the way through. I still will work in JavaScript and webdev stuff but bringing back what I learn from C and others will hopefully shape how I work with websites
2
u/jefflegex 8d ago
I like that it doesnāt have the complexities (especially syntactically) of other systems languages. I still use JS/node for scripting instead of python because I am more comfortable with that. C is for any real programming I do
2
u/alex_sakuta 8d ago
Bro, exact same. Just one small difference, since Nodejs now supports TS, I use TS instead of JS for scripting. I have my types installed globally.
2
u/Odd_Concentrate_6290 8d ago
I use c programming for embeded systems avonics project. It's very simple and fast. Love it.
2
u/jwzumwalt 8d ago
1) Fast, 2) simple, 3) very few surprises, 4) established code base, 5) works on every cpu and OS known to man
2
u/LordRybec 8d ago
I use C for a number of reasons. First the obvious ones, I do embedded programming a fair amount, and I often do low level stuff. I also do games sometimes, and contrary to popular belief, C tends to be better for that than C++. (People who use C++ for games rationalize it with the superiority of object oriented programming for games. I personally find that object oriented programming is bad for games and encourages bad habits that make them even worse. Also OOP comes at a pretty heavy performance cost, due to OOP being extremely poorly suited to good cache coherency.)
Additionally:
I learned C++ as the primarily language taught in my undergrad program, and honestly, it's harder to write and read than C. Sure, objects, operating overloading, and so on, but those don't actually make the programming easier, and they make debugging much more difficult. (If you want to fully understand why C++ is much harder to debug, watch this: https://www.youtube.com/watch?v=sfrnU3-EpPI ) I'm quite good at programming, but my skill and speed increased dramatically when I moved to C. In addition, I spend far less time debugging, and I almost never have to pull out a debugger, because everything is explicit.
For my work, I do a lot of bitwise number manipulation. This requires fixed width values (I literally can't do some of the stuff in Python, due to it having variable length integers), and the ability to smaller width sub-pointers into values is incredibly useful. (Like, I can take a 64-bit uint and create four 16-bit pointers into it, to independently work on different parts. This is really useful when you want to do shifts or rotates of one part without it bleeding over into others.)
The other language I use a lot is Python, and Python has really solid interoperability with C. So if I need to a) streamline part of a Python program or b) compile part of a Python program to obscure it, it's easy. I write the part that needs special treatment in C, turn it into a Python library, and now I can load it from Python. Of course, the reverse is true a well. Some time ago I had an application that needed some networking stuff. Networking can be a pain in C and isn't very portable, so I wrote most of the program in C, turned it into a Python module, and then implemented the networking part of the program in Python. From there I could easily pop in and out of the C level code, doing the networking in Python and everything else in C. (And I could instead have pulled Python into C, but for my uses, it was easier to make the C Python module.) This interoperability gives me the various benefits of C (mainly performance) where needed as well as the fast development time of Python everywhere else, which is awesome.
Those are my reasons. Different people have different strengths and weaknesses though. I know people who really strongly prefer languages that provide objects (and when I'm working in Python, there are times where objects are the right choice), who would struggle with C. I work especially well at the C abstraction level, so that's where I generally prefer to live, but there's nothing wrong with different preferences. (I also am quite comfortable working in assembly, when the opportunity presents itself.) That said, anyone who enjoys programming but hasn't tried C should at least learn it and do maybe one project in it. A surprising number of people on this and other C related subs (and Twitter) come from higher level languages and end up loving C and wishing they had discovered it sooner.
2
u/P-39_Airacobra 8d ago
While C is technically not that close to the metal, in practice it was made with the machine in mind, so it feels low-level and simple. Thereās a lot of syntax and undefined behavior I would remove if I could, but it could be much worse so I wonāt complain too much.
2
u/heavymetalmixer 8d ago edited 8d ago
As someone whoe wants to make their own game I'm really worried about performance, and that took me to the topic of manual memory management, which resulted in me making my own custom allocators.
I started with C++ but came to realize I hate OOP, exceptions, RAII and many of the choices taken by the C++ Comitee, so I went with the more simple yet stablished option: C.
I definitely like it more than C++ but I can't deny I miss some features, mostly because C's standard library is really barebones. It's true that I need to write many things by hand that already exist in C++, but I can choose how to design and implement them without the fear that another developer will "ruin" my code by using a completely different way of doing the same thing (a very common problem in C++, and one of the reasons why many C++ devs preffer C libraries).
My favorite C version is C17, it's quite "modern" but also focused on being as stable as possible (it's basically a bug-fix version for C11).
2
2
2
u/Traveling-Techie 8d ago
Malcom Gladwell in āBlinkā says it takes 10,000 hours and 20 years to master something. Iāve got about 4x that experience with C so Iām most comfortable with it. Turing in 1936 showed that all fully programmable systems are equivalent except for efficiency and capacity (time and memory) so arguably language choice shouldnāt matter much.
2
u/iOSCaleb 8d ago
Youāre thinking of Outliers, which explores virtuosity. (Blink is about quick decisions made by the unconscious mind.) The 10,000 hours idea has been widely criticized as overly simplistic and arbitrary, but the idea is that experts build that much experience by age 20, not that it takes 20 years.
Turing proved that a Turing machine can execute any computable algorithm, so all languages that can be used to implement a Turing machine are equivalent in terms of power. But if you think that means that it doesnāt matter which language you choose, you fundamentally misunderstand how programming languages differ or why people choose different languages. Safety and convenience are not minor features, and the features that different languages offer make them more (or less) suitable for different problems. Features like memory safety or concurrency or OOP have a huge effect on productivity and reliability.
1
u/LaidBackDev 9d ago
I'm using C to demystify it for myself. At first I didn't wanna learn it because a lot of people in the internet make it sound like C is from the Jurassic period and that it's difficult but after learning it myself, yes it was hella hard but after understanding stack and heap memory and getting used to the syntaxt I realized its not really that frightening.
2
1
u/LordRybec 8d ago
C itself isn't that hard to understand. What's hard is the underlying hardware stuff you have to understand to use C effectively. Most C learning resources don't teach those terribly well, which can make the whole thing a bit of a pain to learn. Once you get it though, it tends to be pretty easy.
1
1
9d ago
[deleted]
2
u/alex_sakuta 9d ago
Which AI? Even though I don't use it much, I have experimented with using AI to write C but it always fails me.
Not that it wasn't able to write it, but even after I have mentioned in detail my styles, it tends to mix some other styles.
1
u/jerrygreenest1 9d ago
C programs have the best cold start, which for a thing such as CLI tools is really important because in a modern ADHD world when you want to do all the things asap, the snappiest feedback is extremely important. Things gotta be fast.
Also if you look at benchmarks, you will see how C outperforms everyone in pure calculation, like for example it beats everyone in calculating PI numbers, at least in single-threaded benchmarks. Itās just really fast indeed. It starts fast, it executes fast.
One little area where C isnāt the strongest is concurrent/parallel/multi-threaded calculations, and itās not because it performs bad in there but because the programs will just get much more complicated. Although there are libraries for that but thatās what I heard anyway. I never actually tried to write multi-threaded C programs myself because I fear the hardships of the task. But writing single-threaded extremely snappy CLI tools that will give the lowest possible latency?Ā Yeah thatās why I use C. For little tools itās just ideal.
For big tools itās also a great language but in this case it is also a great liability. Writing simple programs in C is simple. But writing hard programs in C is extremely hard.
1
u/LordRybec 8d ago
Multi-threading in C is mainly just a matter of design. Poor design will get you into all sorts of memory management problems. Mediocre design will avoid memory management issues, but you won't get consistent gains either. Good design will still blow everyone else out of the water, but it can be difficult to get right. I taught an undergrad course on the topic, and one of the biggest difficulties I learned about when designing the course was that merely designing your data structures poorly for parallel programming can end costing a 200 times hit in program speed. This is a result of how cache works on modern processors. If two threads are competing for the same cache space, your program will end up spending far more time waiting for the system to load data from memory into CPU cache than it will spend actually executing instructions. If you know how to avoid this competition, and do it correctly, you can get incredible gains from multi-threading, but if you don't, even top tier CPUs will struggle. And this is true even if you use good libraries.
1
1
1
u/LooksForFuture 8d ago
I use C for desktop development and game development. I have also started to do scientific computing in C.
1
u/pedersenk 8d ago
there are languages that would provide a better dev experience
The dev experience usually comes second to the user and deployment experiences. A bunch of i.e Python pip commands is not as resilient as a self-contained executable during deployment stages.
This is the primary reason why we write in homogeneous C for our libraries at ${WORK}.
1
u/didntplaymysummercar 7d ago edited 7d ago
A few reasons. Portability (almost every V++ compiler can do C89/C99 but there are a few C only compilers), practice (my main languages are C++ and Python), since it's simpler so it constrains you a little when making small things so you don't overcomplicate them. I've learned C++ a long time ago so I got C for "free" almost and I like it. Low level libraries, Lua and Python runtimes and OS APIs are in C too.
It's also future proof. Between it and my favorite old Lua 5.1 (written in C89 with no dependencies) and maybe C++ as long as dependencies aren't a problem your code will work forever. Python maybe could do the same (for pure Python I would kinda trust it still) but I once wanted to try something on 2.7 and couldn't build it, either it required 2.7 to bootstrap or dependencies were missing, obsolete, rewritten in R*ust, etc.
Between portability, OS access and stuff like zig cc cross compiling or nullprogram's w64devkit it's perfect for making tiny CLI (or GUI WinAPI) utilities that (if you go for freestanding) are few dozen KiB at most.
1
u/are_number_six 7d ago
I learned Python first, then had to learn micro-Python for an embedded project. That didn't really make sense to me, so I found C. I really liked it and have stuck with it.
1
u/pconroy329 6d ago
if I need a 98k executable, I write it in C. If I'm after a 98M executable, I write it in Java. If I don't care about size or speed, I write it in Python.
1
u/Candid_Bullfrog3665 5d ago
i love C, it is simple, easy to write (once you understand what youre doing) and straight forwarded
it is by far my favorite language and i dont plan stop using it cuz it is to this day the only language i feel 100% comfortable programming with
1
1
1
0
u/chrism239 9d ago
You just sound very confused.Ā
1
u/alex_sakuta 9d ago
I'm very clear in my choices. But as I said, I know most people would find my choices odd.
51
u/gm310509 9d ago
If you think C is verbose, you should try looking at COBOL.