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

Programming

13380 readers
1 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 1 year 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 21 comments
sorted by: hot top controversial new old
[–] thingsiplay 12 points 1 year ago (1 children)

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

[–] ShadowCat@lemmy.dbzer0.com 4 points 1 year ago

I just want to learn the low level stuff about how programs are written in C, and things like how system starts processes, how programs interact with the OS etc, (I guess that's basically systems programming ?).

It would be good to know what does make them “bad resource” in your opinion

some that I've looked up seem rather shallow and don't explain things well, what I'm struggling with is the memory allocation stuff, like what is malloc ? realloc ? calloc ?

why is Python not enough?

Python is enough, I'm happy with it; I just want to learn more.

[–] Dunstabzugshaubitze@feddit.de 8 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.

[–] I_like_cats@lemmy.one 5 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

[–] arisunz@lemmy.blahaj.zone 4 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/

[–] TheTrueLinuxDev 4 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.

[–] reinar@distress.digital 7 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.

[–] TheTrueLinuxDev 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.

[–] flashgnash@lemm.ee 4 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

[–] reinar@distress.digital 3 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?

[–] ImHereForVorePorn@yiffit.net 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.

[–] ericjmorey@programming.dev 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 of anything in the employment market. They need a $50 option for no certificate and "unlimited" course access. But with shareholders, would they ever consider such a thing?

[–] ImHereForVorePorn@yiffit.net 1 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/

[–] ericjmorey@programming.dev 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.

[–] SIGSEGV@waveform.social 2 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.

[–] squaresinger@feddit.de 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.

[–] pelotron@midwest.social 5 points 1 year ago (1 children)

This is a primo StackOverflow style answer.

[–] squaresinger@feddit.de 5 points 1 year ago* (last edited 1 year ago)

Tbh, A-B-problems are something super common 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 reasons 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.

[–] liori@lemm.ee 1 points 1 year ago

Do it like me. First start with C64 Basic, then go to m68k assembly, then some Pascal, then C becomes very obvious.

[–] ericjmorey@programming.dev 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.

[–] Hundun 1 points 1 year ago

This thread already has some good recommendations, I would also suggest you check out Raylib engine (https://www.raylib.com/) of you're interested in learning through game development.

It's free, open source, written in pure C, and designed with educational purposes in mind.

load more comments
view more: next ›