Live data from Hacker News

Ask HN: Learn C in 2023?

news.ycombinator.com

111–120 of 220 posts

Re: Ask HN: Learn C in 2023?

#111
post #68

If you're fluent in Rust, you will have no problem learning C considered as a language. If C has any faults it is that it is too simple. Rust even sensitizes you nicely to the worst pokey bits of C, so you won't be wandering blind through the landscape of memory safety like most people learning C. I don't think you'd need books or anything, just grab some tutorials online and start banging away. It's not a hard langu…

There wasn’t historically a C “platform” in the sense you describe it here due to C’s age. Rust built itself around a single “platform“ because Rust was built in the 21st century. (Python and Ruby didn’t have “platforms” either, but they had uncommonly useful standard libraries.)

Re: Ask HN: Learn C in 2023?

#112
post #50

Earlier quoted context omitted.

What is your opinion on K&R?

Not the person you are replying to, but here are my thoughts. It sounds like OP is looking to learn C for historical and contextual reasons, and for that K&R is perfect. The history of C is very K&R-centric. For modern, practical C programing it is missing a lot though. It is a short, simple, from the original authors introduction to the language itself. There is nothing about how to test your code, how to set it up…

> or how to mitigate some of the security downfalls.

I think I'd go further, there are places where it advocates downright unsafe practices. Eg. It's been a long time, but I thought I remember it introducing gets() unironically, without any caveat. For those that do not know, there is no safe use of that interface possible.

Re: Ask HN: Learn C in 2023?

#113

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.

What book would you suggest to someone who started with the K&R 2nd ed, then did other things, and now wants to catch up on the more modern C standards, at least the more widely supported ones?

Re: Ask HN: Learn C in 2023?

#114

I'm not a C engineer, but I think I have an interesting recommendation to consider. Since you are already familiar with other languages, you obviously don't need to know the basics of C. The basics are the same everywhere. Instead, you'd likely want to build that mindset on how to build good software with C. I suggest you read other people's code and try to deep dive into the whys. I heard Redis is a well-written sof…

I've got a single digit number of contributions to projects that I like, mostly because of how daunting it is to familiarize oneself with a codebase, and this 'git log -reverse' trick seems incredible as an entry point to a new project. That being said, how do you feel about using this technique for repos with 2k+ commits? It seems unrealistic to read all of them, or am I being short-sighted here? I get demotivated j…

Reading 2k+ commits is a big waste of time.

Forcing yourself to read every commit to a project you "like" in order contribute to it is putting the cart before the horse. Just because you "like" a project doesn't mean you will have the skills to contribute usefully to it. This isn't a bad thing. I "like" GCC, but I don't have the skills to contribute to it. I'm not losing any sleep over this, and I'm definitely not thinking about reading every commit to GCC in chronological order.

If you use a project, you might find a bug or some deficiency in it. Then it might happen that you have the skills to quickly fix this problem. Either that, or this bug causes you so many problems or slows you down so much that it becomes worth it for you to develop the skills to fix the problem.

Re: Ask HN: Learn C in 2023?

#115

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…

Deep C Secrets is one of the best programming books ever written.

Re: Ask HN: Learn C in 2023?

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

Don't bother with this stuff (or with "modern C") if you're just beginning to learn the language. You don't need it for small programs. No one is going to yell at you if your first effort isn't perfect. And no one is going to yell at you if you read the "wrong" book, or try things out in the "wrong" order. Pick any learning resource and get started now. You'll probably get distracted and move on to something else. Come back to it later or not.

Re: Ask HN: Learn C in 2023?

#117

Earlier quoted context omitted.

Not the person you are replying to, but here are my thoughts. It sounds like OP is looking to learn C for historical and contextual reasons, and for that K&R is perfect. The history of C is very K&R-centric. For modern, practical C programing it is missing a lot though. It is a short, simple, from the original authors introduction to the language itself. There is nothing about how to test your code, how to set it up…

> or how to mitigate some of the security downfalls. I think I'd go further, there are places where it advocates downright unsafe practices. Eg. It's been a long time, but I thought I remember it introducing gets() unironically, without any caveat. For those that do not know, there is no safe use of that interface possible.

If you're just beginning with C, it doesn't matter. If anything, it's better to be exposed to these unsafe practices and make mistakes with them in the very safe environment of your own home, where absolutely no one cares what you're doing.

K&R C is an excellent learning resource primarily because it's extremely strong pedagogically. Read K&R and then move onto something else later when you're done with it. If you eventually get a job doing something with C, then you'll learn on the job what's important to the job you're doing.

Re: Ask HN: Learn C in 2023?

#118

I'm not a C engineer, but I think I have an interesting recommendation to consider. Since you are already familiar with other languages, you obviously don't need to know the basics of C. The basics are the same everywhere. Instead, you'd likely want to build that mindset on how to build good software with C. I suggest you read other people's code and try to deep dive into the whys. I heard Redis is a well-written sof…

For me, when I learned more than 20 years ago, reading source and manpages from Linux and other Unix like projects was a source of inspiration.

I'd recommend OpenBSD libc. https://github.com/openbsd/src/tree/master/lib/libc

String functions especially are a good way to get into the C way of thinking. Since C's approach to strings is unique.

I also learned a lot by reading manpages of libc functions or Unix utilities and thinking about how they were implemented, and writing my own little versions.

Re: Ask HN: Learn C in 2023?

#119
post #67

One thing I always loved about C was how easily you could slip in and out of x86 assembler with the __asm__ tag. There is no ceremony & it seems like magic. Like if you have 3 C int's a,b & c, and you want to add a & b and store the result in c, you would do: __asm__ ( "addl %%ebx, %%eax;" : "=a" (c) : "a" (a) , "b" (b) ); Then you could just continue in C as if nothing had happened, and a printf("%d",c) would give y…

Man, that is one complex, interconnected and interesting System!

I would love to work on something like that even if it is just maintaining a legacy product. Seriously, let me know (contact in my profile).

On similar lines, I have been thinking of using Erlang/Elixir for distributed programming over the Web (even in the browser if possible) and dropping down to C/C++ and J programming languages as required on individual nodes.

Re: Ask HN: Learn C in 2023?

#120
The suggested way to learn C in 2023 is the same as the suggested way to learn all languages for the past decade or so.

Do you like videos? Find videos on YouTube and watch them.

Do you like books? Go on Amazon and search for "C programming".

Do you like reading code? Go on GitHub and start reading the source for any project.

Or just find any online resource and use that.

The most important thing is to write code to do something you're interested in. If you're interested in solving puzzles, solve some puzzles. If you want to write a game, write a game.

Above all, you shouldn't waste time concerning yourself initially with what the "right" thing to do is. Do NOT let the perfect be the enemy of the good. It's OK to ignore the advice of anyone who tells you you need to be concerned with how to set up your project the right way, or tells you to avoid certain "dangerous" functions in the standard library. Just avoid all dogma.

Since you're learning, thinking about these things now is a huge waste of time. It's much better to write code that actually does things. If you thoroughly engage with this process, you will figure this stuff out on your own naturally. Or you won't, and then someone will correct you later, at which point you will be in a better position to appreciate their advice.

Biggest time-waster: reading this thread. These threads are mainly a venue for people with minimal experience to regurgitate things they have read elsewhere.

Post reply on HN