Live data from Hacker News

Ask HN: Learn C in 2023?

news.ycombinator.com

81–90 of 220 posts

Re: Ask HN: Learn C in 2023?

#81
post #17

I like firearms as an analogy here. Rust is like a modern rifle, unloaded, with six safeties and three locked triggers in a gun safe. The ammunition will harmlessly self-destruct if you don’t focus properly before firing. C is sort of like Rust except the rifle is on the couch, loaded, one in the chamber, all the safeties are off, the numerous open triggers are held by RNGs, and the business end is pointed right at y…

This analogy is really more like dogmatic Rustacean-ism than actual truth. Rust has it's merits. However, it's a tired language. It doesn't maintain very good stability due to it's ever-evolving compiler which makes it almost unusable in anything but a "move fast and break things" environment. It's too particular, making development a burden and interrupting flow. Most importantly, the community is absolutely exhausting to listen to and this post is a perfect example.

C can be dangerous, yes. No one is denying that. C is also extremely stable, fast, and a "known-known". With proper discipline that any experienced developer of ANY language will have C can be very safe. Most, if not all, dangerous errors can be found and fixed simply by understanding how to use valgrind. With the advent of modern CI/CD it's never been easier to remember to valgrind your code.

C is probably the first language I would use in an environment I cared a lot about. For example, if binary size, availability of libraries, competency of programmer, etc would be in my list of concerns I would use C. I take particular offense to the "RNG" part of your analogy. C errors are not random at all. They are always the developer's fault and are often very predictable (use-after-free, poor array hygiene, etc). Despite the ever-evolving condition of post-C religions (Go, Rust, etc) there are only a handful of languages that fit the bill for a so-called serious systems project. C, C++, Java, and C#. You simply will not find a better library ecosystem and community of highly tenured developers to draw from for at least another decade in other languages.

Re: Ask HN: Learn C in 2023?

#82
Read K&R. Yes, it's explicitly not modern C, but it enables you to think about C from a foundational level from which you can then go on to learn modern C. Build a project in C to learn how and why it works, and you'll understand how memory safe languages like Rust came about. This is what we did in college, started with C then moved on to Rust, it worked well.

Re: Ask HN: Learn C in 2023?

#83
C was the first language I learned after messing around with various flavors of BASIC way back in the day. I learned C using Turbo C for DOS and a big book, which is probably an 'obsolete' way of learning in 2023.

Haven't used it professionally in over a decade now, I'd be interested in learning Rust, but don't really have a need to do anything low(ish) level these days.

Re: Ask HN: Learn C in 2023?

#84
There's was a great article on HN on how C is more than a programming language. It is a protocol for most of computing. I would suggest you to look into the actual influence of C on computing and protocols instead of just looking at software.

Re: Ask HN: Learn C in 2023?

#85
post #8

https://www.learn-c.org/ If you have lots of time: https://hal.inria.fr/hal-02383654 If you can't be bothered reading a whole book: https://matt.sh/howto-c Exercises: https://www.codestepbystep.com/problem/list/c and https://exercism.org/tracks/c Once you have syntax and basic algorithms down well, watch this, the only 2 hour YouTube video I'll ever recommend: https://m.youtube.com/watch?v=443UNeGrFoM Both r/cprogram…

Any recommendations on static analyzers, unit tests, coverage for c? Can clang tidy give hints about modern c they way it does about modern c++?

Not exactly your question, but valgrind is an amazing tool. It does execution-time analysis of your code and provides an in-depth report on memory usage. It will find and report memory leaks, use of uninitialized variables, bad memory references, etc. I love programming in C, but there are a lot of ways to corrupt memory, get segfaults, etc. valgrind is a useful and powerful way to guard against many of these kinds of problems. C++ is no better. The way I see it, programming in C is like lying on a bed of nails. Doable if you are very careful. With C++, they put a sheet over the bed of nails.

Re: Ask HN: Learn C in 2023?

#86
A main issue with learning C is getting the architecture right (header and source files), and figuring out the tooling for compiling and debugging and building (gcc and gdb and make/cmake for example). I like C in a Nutshell 2nd ed (Prinz/Crawford) 2016 as a reference for any questions about that:

https://www.oreilly.com/library/view/c-in-a/9781491924174/

As far as code examples, I find there's a lot of simple C graphics programs using the SDL2 library discussed on Youtube. Also simple ncurses programs are worth looking at. For example here's a video on making a tic-tac-toe game with pure C linked to github source code, just a few files:

https://www.youtube.com/watch?v=gCVMkKgs3uQ

https://github.com/tsoding/profun/tree/master/procedural

For practice, CodeWars has a lot of nice simple C challenges to work on.

Re: Ask HN: Learn C in 2023?

#87

Earlier quoted context omitted.

Any recommendations on static analyzers, unit tests, coverage for c? Can clang tidy give hints about modern c they way it does about modern c++?

Not exactly your question, but valgrind is an amazing tool. It does execution-time analysis of your code and provides an in-depth report on memory usage. It will find and report memory leaks, use of uninitialized variables, bad memory references, etc. I love programming in C, but there are a lot of ways to corrupt memory, get segfaults, etc. valgrind is a useful and powerful way to guard against many of these kinds o…

I haven't used valgrind in years, more used to asan, but I've been told it can do things asan can't?

Edit: to stretch the metaphor, modern c++ is like a thick rubber pad on the bed of nails, but often on the job you are hot bunking and you don't know which c++ your predecessor used to make the bed... Or you are in a hurry and you aren't sure which one you grabbed.

Re: Ask HN: Learn C in 2023?

#88
post #12

The C programming language book.

Just like C, there is a stark beauty to the original K&R C Programming Language book. And there's an admirable clarity in the writing that has set the standard for all language manuals that have followed. It is, indeed, a terrific read. As long as you're not trying to learn C. It's really out of date. It doesn't cover subsequent C standards; and it doesn't cover any of the best practices that have subsequently evolve…

> As long as you're not trying to learn C.

That's insane. K&R (2nd ed.) can easily be the only book you want to work through if you want to learn the basics of C.

Re: Ask HN: Learn C in 2023?

#89
I learned a lot getting an Arduino and building stuff with it in C. With zero C and zero Arduino experience I wired together an e-ink display, SD card reader, and some buttons to build a basic e-reader.

I would have never been bothered to build something in C in an environment where I can reach for any higher level language.

Re: Ask HN: Learn C in 2023?

#90

Earlier quoted context omitted.

Any recommendations on static analyzers, unit tests, coverage for c? Can clang tidy give hints about modern c they way it does about modern c++?

Set warning level to max, use clang static analyzer or clang tidy (I'm not quite sure how those two relate to each other though), and especially ASAN (Address Sanitizer) and UBSAN (Undefined Behaviour Sanitizer) (and if you write threaded code: TSAN (ThreadSanitizer). One thing that Apple did right in Xcode and where other IDEs lagged behind is easy access to those tools from the UI.

That sounds like all the things I do for c++. One thing I really like is that clang tidy can flag the "old way" to do stuff. Was hoping it had that for c.
Post reply on HN