this post was submitted on 27 Jun 2023
9 points (100.0% liked)

Programming

13389 readers
60 users here now

All things programming and coding related. Subcommunity of Technology.


This community's icon was made by Aaron Schneider, under the CC-BY-NC-SA 4.0 license.

founded 2 years ago
MODERATORS
 

what is the best way to learn C ? I know basic python but would like to learn C, I tried searching online but couldn't find a good resource that's good for a beginner like me. any suggestions ?

top 22 comments
sorted by: hot top controversial new old
[–] [email protected] 8 points 1 year ago

There is no single best way for every beginner. When I web search for "how to learn c programming", then a lot of tutorials will appear. It would be good to know what does make them "bad resource" in your opinion, so one can give a better suggestion. Also it would be good to know what your end goal with C is; systems programming? cli programming? why is Python not enough? do you want work as a C programmer somewhere?

Read a book about C, follow the examples and try to solve stuff alongside, play with the code. Take your time. And look out that its not too old, as the language and tools changed over time. Here is a suggestion: A complete and up to date open source book as downloadable PDF

[–] [email protected] 6 points 1 year ago

https://jsommers.github.io/cbook/cbook.pdf

Might be a good way for someone who is familiar with a higher level language.

Than there is of course "The C Programming Language" by Ritchie and Kernighan and "advanced programming in the unix enviroment" by stevens and rago.

So, i'd guess just get your feet wet with small stuff. Find out how to take arguments from the command line, or read a file, maybe programm a simple guess the number game. After you are more familiar with the syntax and so on you could look into using your c code in a higher level language. For python you'd have to look into ctypes for that.

[–] [email protected] 3 points 1 year ago* (last edited 1 year ago) (1 children)

One of the thing I recommends is to start small. Going from Python to C is quite a leap, because C language requires some fundamental computer science understanding when you write codes that offers no railing or safety net when you make mistakes. I would actually suggests that you start with C#, it is very forgiving when you make a mistake and have various tools to help you identify the bug in your program.

Big part of C# is that there is available video tutorial on an introduction to C# provided by Microsoft and it have subtitles. The biggest reason why I would recommend C# to beginner is simply that they offers a lot of resources to help beginners understand the fundamental of programming in general. They have tons of books, video tutorials, vibrant community, and so forth. Also C# can run on wide range of platforms, Windows, Linux, Mac OSX, Raspberry Pi, and so forth. Once you master C#, you'll find that a lot of the knowledge you gained from it is transferable to C, C++, Rust, DLang, and so forth.

[–] [email protected] 6 points 1 year ago (1 children)

C#

eh... those are fundamentally different, C is not object-oriented so OOD part goes straight out of the window. The only thing similar about them is syntax to some degree (which is really irrelevant), approach is completely different.

[–] [email protected] 1 points 1 year ago

Yeah, but when someone is completely new to programming, it's best to start somewhere easy where there are quite a lot of tools to help them fix bugs in code. In C# IDE, it have a lot of visual indicators to help them identify bugs, debugger is pretty comprehensive and integrated, and there are quite a lot of resources to introduce them to programming in forms of videos and documentations and community. The goal of learning C# is not to only program C#, but to get them acquaintances with general programming such as for loop, memory management like using disposal in C#, recursion functions and so go on. They can use C# as a starting point to just basic programming and then once they are comfortable, they can move on to other language that they are curious about.

[–] [email protected] 2 points 1 year ago (1 children)

Why do you want to learn C?

This here might be an A B problem, so I'd like to check what is your goal, before recommending how to get into C. For most use cases there are much better options around nowadays.

Many of the use cases you needed C for in past decades now have better alternatives.

[–] [email protected] 0 points 1 year ago (1 children)

This is a primo StackOverflow style answer.

[–] [email protected] 3 points 1 year ago

Tbh, A-B-problems are something super common if you work in IT. So much time is wasted by going down the wrong road because someone comes to you with the apparent solution that they thought of, instead of just posing the problem they want a solution to.

In case of this post, there are quite a few reason why the OP wants to learn C after learning a bit of Python, and some of them have C as the correct solution, some don't.

For example:

  • OP wants to make C-modules for Python -> C is the correct language, though Google might already have a fitting module
  • OP heard that Python is slow and C is fast -> Improve your Python skills, learn algorithmics
  • OP has a legitimate problem to solve where Python is not fast enough -> Check out Java/C#/Rust or, if it really has to be, C++
  • OP wants to program microcontrollers -> C is good, but might want to check out MicroPython
  • OP wants to program games -> Unity + C#
  • OP wants to go real low level -> C
  • OP is a masochist -> C or Assembly

Especially the "C is faster" argument is often a trap for new programmers, since C is only faster if you really know what you are doing. C can also be much slower if e.g. you mess up memory management. Or, more common, C is not at all, because the rookie programmer gets stuck at arcane error messages that they can't fix.

In most cases the pure execution speed is not what is limiting the performance, but instead the algorithms and data structures used. For example, if you loop through a large array to find an entry it doesn't matter that the looping is 4x the speed, when you could also just use a hashmap/hashset, which will be orders of magnitude faster.

[–] [email protected] 2 points 1 year ago* (last edited 1 year ago)

I've started learning C four years ago, after a career spent coding ruby/javascript/Go, so I guess I was in the same position than you. I started by reading the GNU C manual, then the Glibc documentation, and the man pages for headers and functions I was using (all glibc functions have a man page ; depending on your distros, it may already be installed or you may need to install a specific package to install them all at once). And of course, reading header files in /usr/include/ is always useful for using this or that library. Later, I discovered the book Modern C and it completed my education to feel at home with C. I can't say if it's the best path, but it worked for me.

[–] [email protected] 2 points 1 year ago

Going right from python to C is rough. But you can try. I would suggest watching YouTube tutorials or reading a Book about C

[–] [email protected] 2 points 1 year ago (1 children)

Harvard’s CS50 course is free online and does a pretty good job touching on the fundamentals of C in the first half.

[–] [email protected] 1 points 1 year ago* (last edited 1 year ago) (1 children)

Ever since edX had their IPO, I hesitate to call it free. Each edX course is free for a limited time now and their prices are way too high if you aren't interested in a certificate and the certificates aren't worth much in the employment market. They need a $50 option for no certificate and "unlimited" course access.

[–] [email protected] 0 points 1 year ago (1 children)

The content isn’t exclusive to edX, though.

Harvard hosts it outside of edX.

https://cs50.harvard.edu/x/2023/

[–] [email protected] 2 points 1 year ago

That puts a bit of organizational overhead on the learner. The material is all there and organized, but it's not as conveniently presented nor does it mark your progress automatically. I like that they switched to GitHub code spaces and away from cloud9 which complicated things further.

[–] [email protected] 1 points 1 year ago

Maybe cross posting this to https://programming.dev/c/c_lang and https://programming.dev/c/learnprogramming might get some quality responses.

[–] [email protected] 1 points 1 year ago

Personally I wouldn't jump straight from python to C, python tends to hold your hand quite a bit and C will absolutely let you shoot yourself in the foot.

Personally I consider languages like c# and java a middle point but I don't do C so I'm probably not the best person to gauge that, just have seen a lot of people try and fail to jump straight into C from high level languages

[–] [email protected] 1 points 1 year ago

the "best" way to learn a language is going to change from person to person, BUT i would take a look at Modern C by Jens Gustedt if you haven't already: https://gustedt.gitlabpages.inria.fr/modern-c/

[–] [email protected] 1 points 1 year ago

there's a lot of different C's out there - I mean coding for microcontrollers looks really different to coding graphics with opengl, for example, especially for a beginner.
What do you want to do achieve with C specifically?

[–] [email protected] 1 points 1 year ago

Coming up with ideas for programs to code is the part I struggle with the most, so I like to use codewars.com when I'm trying out a new language. Really, the only way to learn is to practice, practice, practice.