Live data from Hacker News

Ask HN: Learn C in 2023?

news.ycombinator.com

51–60 of 220 posts

Re: Ask HN: Learn C in 2023?

#51

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…

This. We called K&R as "The C bible" for a reason at Uni.

Re: Ask HN: Learn C in 2023?

#52
post #31

Earlier quoted context omitted.

Meh. People love to hate on C but the invariants you have to keep track of are relatively simple (things like 0 Some languages like Rust and Haskell do a little better by having the compiler keep track of most of them (if you use it right) but the consequence of misunderstanding them here is accidentally coding yourself into a corner which is extremely unpleasant. There are other things people like to talk about like…

I mean I’ve worked with C for a long time. It’s love-hate. I think it’s hard to see the value from the other side of having internalized C, and Rust definitely encumbers you. The number of things a beginner doesn’t have to know or worry about to code something as essential as a function that reads a file, searches for a string, and interacts in a serious way with the network in Rust vs C is substantial. Probably I’ll…

But you do learn from such things (opening a file, reading from the network). All the stuff that can go wrong, and that it all has to be handled. Like writing a device driver.

It’s useful to write that C code, and then try to break it (e.g., to force a segfault rather than a proper error-then-exit).

Is knowing all that necessary? No, as you are kind of implying. ;-)

Re: Ask HN: Learn C in 2023?

#53
The thing about C is that its library call API is generally how different languages interoperate: If you write a library in [insert language here] and you want it to be callable in any other language, you need to make bindings for C.

Likewise, if you're using any other language and you want to use a general library, you'll need to know enough C so that you can successfully encapsulate concepts like pointers; and copy your program's data into data structures that C can consume.

It's all much, much easier if you have some C experience.

In my case, I haven't done much C in 20 years. What really helped me "keep up" was occasionally doing Mac programming in Objective C. Because it's really easy to drop into C, it helped refresh me on a lot of the concepts. Even if you're doing Swift, you can mix in an class written in Objective C that's mostly straight C in the methods.

Re: Ask HN: Learn C in 2023?

#54

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 help you learn a bit about the compilation and linking phase and will expose you to the C compiler's flags---useful skills for debugging automated builds later. Once you get to the point where you are working on a larger project, then you will be in a better position to decide what build tools are most useful for you.

Re: Ask HN: Learn C in 2023?

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

+1 to https://hal.inria.fr/hal-02383654. It covers the language in extreme depth, and you likely won't remember it all on a first read but you'll walk away with a pretty good general understanding of the language. Plus, the author is an active contributor to the language.

I love C. As dangerous and as tedious it can be for large projects, I think it's my top choice for solo endeavors that don't require too many string manipulations. I don't think any language has come close to achieving the same balance of elegance and simplicity--maybe scheme? (zig comes close but has a substantial number of features that move it away from simplicity (e.g. payload capture))

Re: Ask HN: Learn C in 2023?

#56

maybe try some embedded development, like raspberry, light up some leds. Embedded development is fun, educational and one of the last bastions of programming where C makes sense.

ESP32 is quite nice. It is much lower level than Raspberry Pi or similar SBCs, and C really makes sense there. It ships with pretty high-level libraries (connecting to a Wi-Fi network is ~200 lines of C code), and you'll be running on top of a small operating system (FreeRTOS). But you still have full access to hardware and all the fun of working directly with it. The dev boards are quite cheap at $3-4 per piece, and…

I suspect they meant the Pico/RP2040.

Depending upon their goals, something like at ATmega may be a better choice. ESP32 and RP2040 development places a lot of emphasis on using libraries. That's fine, but it doesn't really highlight how C is different from most other languages. In contrast, there is a lot of information on low level programming for the ATmega. The RP2040 would be my second choice. I believe the libraries are entirely open source, which means you can read the datasheet and can reference the library source to see how something is implemented in C.

Granted, the ESP32 is a lot more fun if the intent is to build something.

Re: Ask HN: Learn C in 2023?

#57

Well, GNU/linux is more "C plus GCC" than pure C. There are a lot of fancy things that GCC gives you that you'd otherwise have to do explicitly.

"GNU C" has a number of features that make the language far more pleasant if you're willing to give up the portability and use them. A big one if you've been using modern languages is anonymous functions.

It’s worth noting that GNU C uses trampolines to implement their “nested functions” extension, which in turn requires an executable stack.

In other words, using that extension silently disables one of the most basic and effective security mitigations we have for C.

Re: Ask HN: Learn C in 2023?

#58
post #16

I'm a C# guy who learnt C over the past 2 years. It absolutely made me a better programmer. I learnt by going through K&R first and then Expert C programming by Peter van der Linden. I also went through OS books, books that talk about the machines like Understanding the machine. I program in many high level languages. The main difference I felt when learning C is, I felt like I needed to learn how the machine actuall…

As C# guy who had to work with C for a while - this language is minefield. If you want to create your own language and want to experience what choices are subpar by modern standards - C is way to go. If I had choice then I'd pick Rust anytime when messing with low level programming. I don't understand fascination with C just because it's "tradition" "everywhere" or "gives you full control" - especially that, since it…

You'll wish you have decent C experience whenever you need to call an OS API directly; or whenever you need to write your own bindings to a library written in C.

PInvoke requires a working knowledge of C's concepts; you need to know the basics about pointers and how data is represented in order to do it correctly.

This statement comes from a lot of personal experience: I wrote a (currently closed source) adapter to call into SWMM from C#. (https://www.openswmm.org/SWMM51007/swmm5-c). (Hopefully I can open-source it at some point.)

In https://www.syncplicity.com/en, I wrote code in C# to interface with a closed-source driver to create a user-mode virtual disk drive. I also integrated with a different Virtual disk drive product that was written in C++ via PInvoke. I used PInvoke to create bindings between C# and Objective C for the Mac version as well.

Re: Ask HN: Learn C in 2023?

#59
Are you me? I am learning C lately, been a few weeks. I am an SWE with 7 years of experience in JS/TS world.

Currently I am trying to learn how to test C correctly, seems there are lots of approaches.

It began when I decided to learn low level development a few months ago. I completed my Chip 8 emulator. Next I bought Arduino a month ago and I was playing around with it. Now I am reading AVR Programming book so I decided to learn C properly. On the side I already made a small keyboard with a microcontroller with QMK firmware. Soldering and stuffs.

Next what I’m trying to learn is some electronics knowledge just enough to make stuffs.

This is way more fun than my web development job!

Currently the resources I use: - Learn C The Hard Way - BeeJ’s guide to C - random video tutorials from the internet - Make: Arduino - Make: AVR programming

Re: Ask HN: Learn C in 2023?

#60
post #58

Earlier quoted context omitted.

As C# guy who had to work with C for a while - this language is minefield. If you want to create your own language and want to experience what choices are subpar by modern standards - C is way to go. If I had choice then I'd pick Rust anytime when messing with low level programming. I don't understand fascination with C just because it's "tradition" "everywhere" or "gives you full control" - especially that, since it…

You'll wish you have decent C experience whenever you need to call an OS API directly; or whenever you need to write your own bindings to a library written in C. PInvoke requires a working knowledge of C's concepts; you need to know the basics about pointers and how data is represented in order to do it correctly. This statement comes from a lot of personal experience: I wrote a (currently closed source) adapter to c…

Maybe yes, but on the other hand I've never been paid for anything that used OS calls directly.

The only times I've used such APIs was creating simple keylogger for tests and very simple cheat for a video game (tested on non-official servers).

C# nowadays seems mostly like web backend development, tools, game scripting or automation, at least that's my perception.

Anyway even if WinAPI, then why not Rust?

Post reply on HN