Live data from Hacker News

Ask HN: Learn C in 2023?

news.ycombinator.com

171–180 of 220 posts

Re: Ask HN: Learn C in 2023?

#171
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++?

You can't rely on one tool, different ones catch different things. No one tool is best.

I usually use "-Wall -Wextra -Wpedantic", the GCC static analyser "-fanalyzer", cppcheck, and Clang scan-build.

That's good enough for my personal projects.

I have a couple of blog posts about this:

https://superjamie.github.io/2022/05/24/c-static-analysis-to...

https://superjamie.github.io/2022/11/04/c-static-analysis-to...

Re: Ask HN: Learn C in 2023?

#172
post #50
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…

What is your opinion on K&R?

It's wonderfully written. I'm a big fan of both Dennis Ritchie and Brian Kernighan personally.

However the book was last updated in 1988 and I prefer C99+ for almost every feature it adds. If I'm going to recommend just one book it will be something newer.

Re: Ask HN: Learn C in 2023?

#173
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…

#c on libera is a genuinely helpful place full of neckbeards.

#c-jeopardy is great fun as well.

Re: Ask HN: Learn C in 2023?

#174
C is a very minimal language, you can learn it in a day if you are already familiar with C-like syntax. I would recommend using it on embedded systems, such as an Arduino (technically uses C++, but it's mostly hidden), so you can appreciate both the speed and minimal memory footprint and you would be abstracted from the complexity of operating systems.

Re: Ask HN: Learn C in 2023?

#175

Earlier quoted context omitted.

I kinda disagree. global hidden state under APIs is a really awful idea to put in someone's head. I think it also presents the notion to neophytes that there is magic under there

Unfortunately, global hidden state is an unavoidable fact of programming. I don't see how one could be very good at programming if they were kept blissfully ignorant of it. Sometimes there is magic under there, and you just have to do your best to empirically figure out how that magic works.

libc has a few interfaces with implicit global storage. This leads to lack of thread safety and other issues. A good library will let the caller provide storage for these cases, or provide the caller a handle with which to pass it later/free it.

A trivial example would be strtok vs strtok_r. There are some, like, say, asctime(), that operate against a global string buffer.

Sometimes interfaces "look like" they're returning a global buffer, for example readdir(), but that structure can hang off the DIR* struct ... Nonetheless there is readdir_r()

Re: Ask HN: Learn C in 2023?

#176
post #50
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…

What is your opinion on K&R?

It's one of the best examples of technical writing in the field. A good introduction to the basics of the language. Read it for culture.

Read something else for safe C writing in a modern environment. Books like Modern C and Effective C are good starts.

Re: Ask HN: Learn C in 2023?

#177
I think a good place to start is to mostly ignore most/all the advice in this thread. I haven't obviously read every response but I have struggled to find any response near the top which isn't recommending something which will give poor results or is outright wrong.

Good resources:

- #c on libera.chat *

- https://www.iso-9899.info/

Good books:

- C Programming: A Modern Approach - K. N. King

- K&R2 with the errata at hand and the guidance of someone experienced when doing all the exercises

Good advice:

- Don't write a single line for which you are not sure that the behaviour is either well defined by the standard or by your particular implementation (and if the latter is the case, ensure you are well aware of the implications and document them appropriately).

- C is not a "try it and see" language, trying it will lead to undefined behavior and buggy code which you might not even become aware of until you have "learned" the language.

- Lots of C out there is littered with poor practices or heavily specialised to the task/target set of architectures/situation and is therefore not a good example for learning. Feel free to read lots of C once you have the fundamentals down, not before.

Things to avoid:

- Every online tutorial (no I haven't seen them all but none of the popular ones seem to instill the right discipline and are usually full of errors, one of the ones linked from this thread has a bug in the hello world program in the first exercise).

- Most books on the matter.

- Writing C.

* disclaimer: I am one of the founders of this channel.

Re: Ask HN: Learn C in 2023?

#178

Programming in C can turn you into a very disciplined programmer for the simple fact that you will need to track when you request memory and when you need to free it. Essentially you will become the garbage collector. I would recommend you to the read classic "The C Programming Language" (Kernighan & Ritchie) and "Expert C Programming Deep C Secrets" (Van Der Linden) which will get you far enough to write useful prog…

I don't recommend learning how to use Autotools unless you need to work on a project that uses it (and even then, try to avoid it). Highly recommend learning CMake or Meson instead. If you're just getting started, there's no need to tie yourself into knots learning "how to set up a project the right way". It's a waste of time. Your time would initially be better spent just calling the C compiler directly. This will h…

I have a C project I picked up (and got working thanks to help from HN users) that was heavily dependent on Autotools. I wanted to be able to compile it under Windows and couldn't make heads nor tails of it. After guessing and tweaking a config.h file to replace the one it didn't create, I was finally able to get gcc to compile everything using a batch file.

Eventually I'll be purging Autotools, make and all build systems, replacing it with a single batch file that wipes the slate then compiles. It only takes a few seconds to run, and removes a huge set of dependencies.

I hope to port the code to run under the Cosmopolitan library so I can be cross-platform and more.

Re: Ask HN: Learn C in 2023?

#179
I'm not a C programmer, but I have a program written in C that I've adopted. So I to am interested in learning modern C. Is there a text that gives the current recommended techniques for C23?

Re: Ask HN: Learn C in 2023?

#180

Earlier quoted context omitted.

C is one of those things that unless you have proper testing, tooling and linting you don't know if you code is incorrect. It may have subtle memory bugs, rely on undefined behavior or crumple in exploitable ways under bad input. Having a feedback loop is really important in learning and improving. Undefined behavior helps subvert it. For the exact example of above, how would a developer learn not to use gets? The be…

All of this is true, but if you are just starting with C, none of it matters. If you continue using C, then you should eventually learn this stuff, but to overburden someone with a list of 100 things they must do right is the surest way to frustrate them to the point where they give up. If OP eventually writes C code that goes into production for a company, it is the company's responsibility to have procedures and sa…

> If OP eventually writes C code that goes into production for a company, it is the company's responsibility to have procedures and safeguards which ensure that OP writes reasonable code. Ideally, one such safeguard will be a senior colleague to introduce them to the thornier parts of C.

You've mentioned something like this in reply to a few comments in here. This is a strange argument. It isn't too much to ask of a book to lay down more of a foundation so you don't need a 1 on 1 tutor later to correct misconceptions.

I get people like K&R because it is short and easy to read. Some subjects aren't best served by short and easy to read. The subject was well served by it when C was new and novel. We live in a very different world.

Post reply on HN