News for hackers. Stuff that matters.
Re:Getting started with C by pjc50 on Thursday December 17, 2020 @05:01AM (#25454165)
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.
Re:Getting started with C by qsort on Thursday December 17, 2020 @05:11AM (#25454213)
..and that uses non-standard concepts like GObject.

Win32 examples would have been peak hilarity.

More seriously, I see where the author is coming from, but even historically, GUI code has always been a massive pain in C.

Re:Getting started with C by pjc50 on Thursday December 17, 2020 @05:43AM (#25454372)
Telling people that the default string type is LPTCSTR and the default integer type is HRESULT would be top trolling.
Re:Getting started with C by kbumsik on Thursday December 17, 2020 @10:47AM (#25456590)
Right? What absolute beginners will learn about C from GObject? I bet most of them will learn that C is a weird language, and they also will learn that it is better not to learn about C again.
Re:Getting started with C by benibela on Thursday December 17, 2020 @07:58AM (#25455143)
>Win32 examples would have been peak hilarity.

ExAmples

Re:Getting started with C by megous on Thursday December 17, 2020 @12:38PM (#25457892)
Being able to produce a GUI app may be more interesting to beginners than crunching some IO with basic console C program. Really, you don't need to understand GObject much to just use GTK+. Surface understanding suffices, and you can structure your program at first in such a way to not need to create custom GObject based classes/interfaces.

Beginners will probably be a bit lost, because the article doesn't go into any depth about event loop, retained mode GUI, GTK signals/handlers, nor does it link to GTK+ docs that would explain each part of the code, etc., etc.

Re:Getting started with C by 0x008 on Thursday December 17, 2020 @05:07AM (#25454201)
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?
Re:Getting started with C by qsort on Thursday December 17, 2020 @05:19AM (#25454249)
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 "hardcore introductory" language that will expose you to foundational concepts like pointers and memory management (it's really hard to understand what problems Rust is trying to solve if you're not familiar with malloc and free, for instance), but if you're already programming that's less of an issue.

Re:Getting started with C by pjc50 on Thursday December 17, 2020 @05:40AM (#25454360)
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?)

Re:Getting started with C by nicoburns on Thursday December 17, 2020 @07:15AM (#25454890)
> 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!

Re:Getting started with C by steveklabnik on Thursday December 17, 2020 @11:02AM (#25456764)
> (Is there anyone who learns Rust who isn't already a proficient but frustrated C++ programmer?)

We have a lot of people who come from ruby/python/js, and/or haskell/ocaml/scala. They find Rust an easier foray into systems languages than C++.

And even some C veterans who never got on board the C++ train.

Re:Getting started with C by qsort on Thursday December 17, 2020 @05:48AM (#25454397)
Completely agree, that was part of the point I was making, for example, I doubt I would ever have understood RAII had I never seen malloc.

Parent was suggesting they are already a programmer, so I assumed they already had at least a grasp of how pointers and manual memory management work. If one happens to lack such knowledge, I agree learning C is an excellent first step.

Re:Getting started with C by asveikau on Thursday December 17, 2020 @12:08PM (#25457510)
I understood malloc very well long before RAII made sense to me.

I think what made RAII seem like a good idea was seeing a large C code base at a major company which had a consistent approach to cleanup and error handling. It's very possible to write good code that way, but it takes manual effort, discipline, consistency. At that point I understood that RAII was about letting the compiler handle what I was already doing in C.

Re:Getting started with C by ognarb on Thursday December 17, 2020 @08:05AM (#25455195)
I would recommend you to watch "CppCon 2015: Kate Gregory “Stop Teaching C"" https://www.youtube.com/watch?v=YnWhqhNdYyk
Re:Getting started with C by 0x008 on Friday December 18, 2020 @08:41AM (#25466932)
I learn Rust because I need a statically typed non-jvm alternative for backend and for me Go is lackluster in its expressiveness after coming from Scala.
Re:Getting started with C by 0x008 on Thursday December 17, 2020 @05:27AM (#25454297)
Well for me one objective definitely would be to better my understanding of gnu tools, gcc etc.

But for the most part, yes it is about "foundational concepts". A lot of the time when you learn system level programming people will refer to certain quirks or terms from the C world.

Re:Getting started with C by qsort on Thursday December 17, 2020 @05:42AM (#25454368)
If you're just looking for a cursory introduction to the underlying concepts, I agree with the other comments that K&R is what you are looking for. I'd add the caveat that due to the fact that C is a tiny language with a tiny standard library, most code you'll see in the wild uses custom concepts/libraries/object models on top of C. So for most practical purposes, there isn't really "C" as much as there is "unix programming C", or "embedded C", or whatever else have you, and all of them add a thick layer on top of the core language.
Re:Getting started with C by smoe on Thursday December 17, 2020 @07:02AM (#25454802)
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 by coldpie on Thursday December 17, 2020 @09:01AM (#25455613)
Strong disagree. Unless you're using it as "C with classes", C++ is a nightmare hell language that you should only use if you're forced to by your environment. Stay far away.

C is a fine language, but it is from the 60s and 70s and feels like it. Rust is very nice, although poor for half-assed prototyping (which is actually maybe a good thing). Both are fine choices for systems-level programming.

Re:Getting started with C by glouwbug on Thursday December 17, 2020 @12:57PM (#25458157)
I've been working on this which you might find of use:

https://github.com/glouw/ctl

Re:Getting started with C by dvfjsdhgfv on Thursday December 17, 2020 @02:03PM (#25458998)
That's interesting. Do I understand correctly though that the performance of CTL is mostly on a par with that of the STL?
Re:Getting started with C by glouwbug on Thursday December 17, 2020 @03:26PM (#25459931)
Yes, I'd say at worst its 20% slower. The implementation is naive and readable (and therefor hackable). I did not have the time to implement all the heuristics that make STL as fast as it. The goal is hackability and ease of use (think text book function examples), while giving embedded engineers (or even desktop engineers with an aversion to C++) a chance to focus on getting their work done.

That, and lighting fast compile times, where programming feels like (oh, the heresy) a _drastically reduced C++_.

Re:Getting started with C by ku-man on Thursday December 17, 2020 @09:49AM (#25456036)
Not quite. I use C to interact with scientific libraries and to do some image processing. I would like to learn and use Rust but is still lacking in the scientific libraries department. I avoid C++ because it's a nightmare of complexity.
Re:Getting started with C by opheliate on Thursday December 17, 2020 @05:23AM (#25454266)
It's a fairly controversial pick amongst the C community, and it is a full book, but the first few chapters of 'Learn C the Hard Way' by Zed Shaw are (imo) a great resource to get started with the language, and also point you towards tools like Valgrind which you might not come across otherwise.
Re:Getting started with C by a-nikolaev on Thursday December 17, 2020 @09:46AM (#25456006)
I have lecture notes for the intro programming course I taught a few years ago: https://a-nikolaev.github.io/cpp-spring-2015/

It is actually in C++, but the goal was to cover C features first as the foundation, before going into objects, strings, and similar more advanced concepts. (It still uses C++ I/O from the very beginning, since it's was a C++ course.)

Re:Getting started with C by cle on Thursday December 17, 2020 @12:23PM (#25457699)
Personally I think C isn’t useful to know topically. It really only became useful once I had a basic grasp on computer architecture, assembly language, and operating systems. Then suddenly its use made a lot more sense to me. If you’re not thinking about those things when writing C then you’re probably using it for the wrong reason, and there’s probably a better tool for the job.
Re:Getting started with C by learnstats2 on Thursday December 17, 2020 @06:55AM (#25454746)
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 by enriquto on Thursday December 17, 2020 @05:11AM (#25454212)
Just read K&R for 10 minutes.
Re:Getting started with C by vkazanov on Thursday December 17, 2020 @05:19AM (#25454250)
:-) I wish people would stop recommending this outdated book, along with a few other default goto books (say, the Dragon book).

Its super optimistic approach is more about the language K&R wanted C to be than the real thing.

Re:Getting started with C by rightbyte on Thursday December 17, 2020 @05:51AM (#25454419)
The book is fine. It is way better to start off by sorting words from stdin with K&R than to follow a tutorial to do a GUI window.
Re:Getting started with C by wsc981 on Thursday December 17, 2020 @07:29AM (#25454965)
I thought the book by K.N. King was a great introduction to (modern) C [0]. Easy to follow, nice questions at end of each chapter including a few challenges.

———

[0]: http://knking.com/books/c2/index.html

Re:Getting started with C by redprince on Thursday December 17, 2020 @05:47AM (#25454388)
Maybe there aren't any good alternatives to "read this go to book as the first book on the topic". Prove me wrong. (Please)
Re:Getting started with C by shadowofneptune on Thursday December 17, 2020 @09:46AM (#25455999)
If an absolute beginner were to use K&R as a start they'd be learning C from 35 or so years ago. It's well written, but not helpful as a reference. Even something as simple as how a function is organized has changed.

C Programming: a Modern Approach teaches C89 and C99, pointing out the differences in features when appropriate. Having used it myself this year, I found it much more helpful than K&R

Re:Getting started with C by icedchai on Thursday December 17, 2020 @11:51AM (#25457321)
If you start with the second edition (C89 / "ANSI C"), you'll discover that C has barely changed.
Re:Getting started with C by shadowofneptune on Thursday December 17, 2020 @09:16PM (#25463060)
Yes, that's true. C Programming is largely a C89 book with small segments about C99.
Re:Getting started with C by icedchai on Thursday December 17, 2020 @11:50AM (#25457316)
I taught myself C using K&R when I was a teenager... back in 1991. The second edition was only a couple of years old.
Re:Getting started with C by 0x008 on Thursday December 17, 2020 @05:22AM (#25454264)
Re:Getting started with C by enriquto on Thursday December 17, 2020 @05:27AM (#25454296)
Exactly.

It's a great read, even if you don't plan on programming in C.

Re:Getting started with C by pjc50 on Thursday December 17, 2020 @05:41AM (#25454365)
The companion Programming in the UNIX Environment has some outdated details but a surprising amount of it still works.
Re:Getting started with C by raverbashing on Thursday December 17, 2020 @06:21AM (#25454557)
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!