Live data from Hacker News

Getting started with C

not.cafe

31–40 of 106 posts

Re: Getting started with C

#31
I think this has merit not only for beginners to programming, but also for programmers who have never touched C. I like that it gets straight to business.

Good intro, and props to the author for introducing it on three major desktop platforms, using modern build tools.

Re: Getting started with C

#32
post #3

Introducing newbies to GTK is a great way to show them a lot of code they don't understand, will take a while to understand, and will break in non-obvious ways.

Really. That's just cruel.

GTK is good, but the programming model is exactly that. Especially in C.

If bare C is giving beginners a knife to play with, GTK is telling them to put electrical wiring together and "have fun". Oh but the lamp socket looks like a banana and wires look like ropes and vice versa. Good luck!

Re: Getting started with C

#34
One of my biggest bugbears on C / C++ programming is return 0; I wish people would #include / and use EXIT_SUCCESS / EXIT_FAILURE just to make the code more obvious for the beginner on what the intent is. :-) To quote the "zen of python" "Explicit is better than implicit" we know what "SUCCESS" or "FAILURE" is! And we can use enums for other exit values.

Re: Getting started with C

#35
post #34

One of my biggest bugbears on C / C++ programming is return 0; I wish people would #include / and use EXIT_SUCCESS / EXIT_FAILURE just to make the code more obvious for the beginner on what the intent is. :-) To quote the "zen of python" "Explicit is better than implicit" we know what "SUCCESS" or "FAILURE" is! And we can use enums for other exit values.

There should only be one way to succeed. Returning 0 for success makes complete sense. You can add layers of macros or enums to sugar coat this but retuning 0 for the success case makes complete sense

Re: Getting started with C

#36
post #5
post #3

Introducing newbies to GTK is a great way to show them a lot of code they don't understand, will take a while to understand, and will break in non-obvious ways.

I would be really interested in a course that actually holds true to the premise in the title here. I know my way around the JVM and python and started learning a little Rust on the side. However, I feel the need to at least dive my toes into C for a couple of weeks for completeness sake. Do you have a recommendation for something that is a little less than a book and a little more than learnCin10minutes?

CS50 online course uses C from “Week 1” and it’s set up for you in a controlled learning environment while you learn concepts.

If you have some programming experience you can probably jump straight to the Problem Sets.

Re: Getting started with C

#37
post #11
post #5

Earlier quoted context omitted.

I would be really interested in a course that actually holds true to the premise in the title here. I know my way around the JVM and python and started learning a little Rust on the side. However, I feel the need to at least dive my toes into C for a couple of weeks for completeness sake. Do you have a recommendation for something that is a little less than a book and a little more than learnCin10minutes?

It kind of depends on what you need out of C. The only real reasons left to use C in the wild are: * Legacy code * Embedded (including drivers, bare metal etc.) * Portability, FFI, etc. Performance used to be another major reason, but in $CURRENT_YEAR, if that's your goal, C++ and Rust are just as performant and there's very little reason not to opt into them. The other major reason to learn C is that it's a great "h…

I had C as an introductory language and I didn’t perceive it as very hardcore, because we were doing the most basic things. Key is in my opinion, that you do projects aligned with your current programming skill level.

I have never used C professionally, so I never worked with a large, complex code base. But I think getting the foundational concepts from it as a first language has helped a lot along the way picking up and switching between languages.

Re: Getting started with C

#38
post #34

One of my biggest bugbears on C / C++ programming is return 0; I wish people would #include / and use EXIT_SUCCESS / EXIT_FAILURE just to make the code more obvious for the beginner on what the intent is. :-) To quote the "zen of python" "Explicit is better than implicit" we know what "SUCCESS" or "FAILURE" is! And we can use enums for other exit values.

There should only be one way to succeed. Returning 0 for success makes complete sense. You can add layers of macros or enums to sugar coat this but retuning 0 for the success case makes complete sense

Yes, but if you use "magic constants" in your code, you will flunk code review in any halfway competent shop.

Always use the constant symbols.

Re: Getting started with C

#39

This is a very strange "getting started" guide to C, and I'm not sure who the intended audience could possibly be. The tone at the start really does seem to be aimed at "absolute beginners" ("[...] programs must be written in a very strict way. Miss a comma and the program will stop working"), but then it quickly gets into the weeds without much explanation. I'm trying to imagine an beginner reading this: The first t…

Wrt "the first line loads the stdio.h function library, which provides the printf() function", you're right, "loading a library" is not clear and, what's worse, is actively misleading as actually we're just telling the compiler that there is a function somewhere called printf that will get "loaded" (linked) later on. I remember that this was one of the things that confused me most about C when I learned it.

Re: Getting started with C

#40
post #18
post #11

Earlier quoted context omitted.

It kind of depends on what you need out of C. The only real reasons left to use C in the wild are: * Legacy code * Embedded (including drivers, bare metal etc.) * Portability, FFI, etc. Performance used to be another major reason, but in $CURRENT_YEAR, if that's your goal, C++ and Rust are just as performant and there's very little reason not to opt into them. The other major reason to learn C is that it's a great "h…

I would still suggest that people learn C before attempting C++; while someone with C# or Java experience could probably do well in a "modern C++" codebase, as soon as they go off-piste into memory allocation and pointers they're in for surprises. (Is there anyone who learns Rust who isn't already a proficient but frustrated C++ programmer?)

> Is there anyone who learns Rust who isn't already a proficient but frustrated C++ programmer?

Yes, I learnt Rust as a JavaScript/PHP/Python programmer who needed better performance for a project, and I'd thoroughly recommend it as a first low-level language. I found it much easier to learn than C++. There were a few new concepts to learn, but:

- There were far fewer than C++.

- The Rust Book provided a free and very approachable resource for learning them.

- The Rust compiler gave me immediate feedback if I was doing something wrong (no unexpected bugs in production)

- Most of my JS skills translated pretty straightforwardly

- /r/rust has a very helpful community which filled in any gaps that weren't covered elsewhere.

C is simple when you're working with toy examples, but as soon as you try to do anything moderately complex the complexity quickly jumps. e.g. If I wan't to use something as basic as a HashMap this is a trivial import in Rust or C++, but a non-trivial task in C. You either have to build/import a library (which is not that easy in C), or write one yourself! Same for string operations!

Post reply on HN