4 ms·
Ask HN: Is C Really That “Difficult”?
Reading introductory C++ books.
Seems like it is just a combination of bad designs that make doing simple things tedious and not being smart.
Any examples that really show the difficulties?
- binarynate 3y agoC and C++ are different languages. It's subjective, but both are generally more difficult than garbage collected languages because you have to think about memory management and they don't have some of the high-level utilities other languages do (like an easy to use timer). IMO, modern C++ isn't too gnarly (it has a nice standard library that with components like smart pointers and containers), but it's still a PITA compared to garbage collected languages because it builds slowly and you do have to think about memory management like I mentioned. C is gnarlier IMO because its standard library is much more bare bones and it doesn't have the built-in smart pointers or containers that C++ has.
- gregjor 3y ago"Difficult" doesn't describe a property of a programming language. The majority of code most of us run every day, from operating systems to networking to desktop and mobile applications exists because programmers wrote it in C or C++, or some closely-related derivative such as Java, C#, or Swift. So it follows that hundreds of thousands of programmers have mastered these languages over the years, and the languages stand out as tools of choice in many domains. C came out in the mid-70s, C++ about a decade later, and both still get used to write lots of new code. Some programmers find C and C++ difficult to learn and master, others don't. That depends on the programmer, not the language. Some people struggle with Python and Javascript too.
- bombcar 3y agoPointers are hard for many people. Once you get past that (really get past it, not just fumble through it) C has a large number of foot guns available. It's not a difficult language (it only has a few "instructions" if you will) but it is difficult to avoid all the possible mistakes. C++ is an entirely separate language that happens to have some similarities. https://beej.us/guide/bgc/pdf/bgc_usl_c_1.pdf https://beej.us/guide/bgc/pdf/bgc_usl_c_1.pdf is a good introduction to C.
- gregjor 3y agoC exposes the underlying memory structure rather than abstracting it away "safely" like many other languages. Requiring the programmer to understand and manage memory presents the difficulty, because programmers usually start with languages that hide the details, whether they start with BASIC like I did, or with Python as many do today. Understanding how CPUs and memory work requires the programmer to put in more effort learning the fundamentals at a lower level of abstraction. That creates a filter -- some people won't get through that and will forever find pointers, and therefore C, confusing and mysterious. I could say the same thing about SQL. If you don't actually understand the relational model and how databases work you stay at the surface level, never really sure what goes on inside. The best intro to C remains the classic The C Programming Language by Kernighan and Ritchie, called K&R for short. I would recommend Adam Osborne's books on microcomputers to understand processors and memory but they went out of print decades ago.
- leed25d 3y agoI didn't find C all that hard to grok. It helped matters that I had spent the previous 10 years programming in assembly languages.
- GianFabien 3y agoC was originally designed to write Unix operating system and its utilities. Until then such programs were written in assembler. I always think of C as a portable high level assembly language. Recent use of C/C++ for Arduino reinforces that positioning although I think that many Arduino abstractions are rather bloated. But of course, there's no reason why I can't re-write performance/space critical code in assembler.
- GianFabien 3y agoPersonally I find "modern C++" far more difficult than ANSI C. Due to my lack of competence with C++ I generally stick to writing C code. That is when I'm not writing some quick scripts in Python or web stuff in JavaScript - which for the most part is comparable to C. If you are finding C++ difficult, perhaps you could learn C first.
- simonblack 3y agoSome of us learned Assembly Language programming before we hit C. Assembly Language makes a lot of use of pointers. So we're very comfortable using pointers. I feel that we work better with C because of that. In fact, C has been called 'high level Assembly Language' by somebody in the past. C is not difficult. C++ is difficult because of its use of overloading (IMHO) and it seems quite messy. In C, the frugal language, what you see is what you get.