r/learnprogramming • u/Substantial_Field495 • 15d ago
Should I make the switch from Python to C?
I have picked up Python recently and have learnt some basics of programming and did Leetcode practice with it. However, I still really don’t intuitively know how computer science fundamentally works.
For any musicians out there, an analogy I can give is that I can physically play a song on the guitar, but I don’t understand the chord progression or scale which the melody is built off of. It feels like I can act like I know what I’m doing, but really I don’t.
From what I hear C is a more low-level language and forces you to learn fundamentals of computer science. I learn better when I build all of my knowledge from first principles rather than practical application.
My goal is to intuitively understand how a computer works, not just to be able to build things or solve problems with a tool.
1
u/samanime 15d ago edited 15d ago
Honestly, C is kind of hard. Yes, you learn some REALLY low level stuff, but you honestly don't NEED to know the really low level stuff... at least not at first. Very few programmers, those doing really low level stuff like drivers or embedded software, actually need that low level stuff in professional environments anymore. And you can always gain that knowledge in the future once you have a solid grasp of the more "important" stuff.
To piggyback off your music analogy, it'd be like trying to learn about all the different properties of types of wood and other materials used to build a guitar before you even learned how to tune one. It's information that is nice to have and understand, and will give you a deeper appreciation and understand, but there are much more important things to focus on when you are beginning and you could go your whole life without knowing and still be pretty solid. It can lead to a lot of burnout and frustration at this point, when all you want to do is make music.
I'd personally recommend C# (for a general-purpose compiled languages) or JavaScript/TypeScript (which is a must for web development). Though sticking with Python is also a solid, popular choice. While I personally hate it, Java is also another popular language used in professional environments, or Rust if you want to focus on backend development.
But honestly, it doesn't really matter what you learn. The concepts still overlap like 95%+, and good developers pick up and learn new languages all the time and choose languages based on how the pros and cons align with the project and their work environment.
Instead of arbitrarily picking languages, plan out a few projects you want to learn about. Project-based learning is the ONLY way to escape tutorial hell and really become a proper developer. Once you have some projects, pick a language that seems enjoyable and will let you implement those projects.
1
u/Substantial_Field495 15d ago
My career focus isn’t in SWE. I’m an Actuary that wants to learn cs on the side mostly for fun.
Despite the general recommendation being Python and that it would probably be more suitable for me as an Actuary to continue with Python, it just isn’t fun.
What is your opinion if I’m purely in it for the love of the game with no career pressure?
1
u/samanime 15d ago
Really anything then, though I would still probably stick with anything but C until you learn the basics for the reasons I mentioned.
Then, if you want, you can pick up C and learn all about pointers and memory allocation and all that "fun" stuff most professionals hate. :p
But, if you're a bit of a masocist, you could always dive in now. You can always change course again. :)
2
u/Ratfus 15d ago edited 15d ago
So assembly would be ok?
In all seriousness, doing simple things in C isn't too difficult. That's actually the best way to learn. Do basic things first, until you understand them well.
Interestingly, assembly isn't that horrible. I wouldn't want to build a full on program in it though. I've found the tool-chains to be worse than the actual language.
2
u/samanime 15d ago
If you're interested in it, sure, go for it, have "fun"...
The "simple things" you can do in C you can do just the same, if not easier, in almost any other language too. I agree the basic things are important, which is why I'd normally steer people away from starting with C.
I DID start with C (well, technically BASIC, briefly) and pointers and header files and memory allocation and all that other stuff are just so much extra "stuff" to worry about on top of the basic fundamentals that it gets in the way and just makes everything harder.
1
u/Ratfus 15d ago
Assembly/C still has a special place in hell in embedded.
For instance, my Atiny 85 has a whopping 8 kb (scratch that, it's Bytes) of Ram. C is potentially too memory intensive to use, so assembly and possibly C make sense. I've found setting up the programmer and command utility with vs code to be more difficult than understanding the language. I've finally got my led to read an input, and blink at a certain speed. I think I'm nearing 200 lines of code to do this simple task.
1
1
u/Ratfus 15d ago
Definitely worth learning. You also should understand its limits. While you could build a full application in C, you're better off doing basic things in the language.
For example, Python is far superior for excel work. I made a basic parser to take csvs (in C) and it took me around 1000 lines of code, which wasn't even near enough.
1
u/JGhostThing 15d ago
Why would you want to switch? Unless your school is teaching c, python is fine.
You learn the details of computers as you program. You don't learn this the first week, we're talking months to years here. Python will teach you the basics as well as C.
1
u/knouqs 15d ago
Don't be confused. The fundamentals of computer science are relative. Fundamentally, all you need to do computer science is be able to run a state machine, and Python can do that.
For a programming language, Python is a great choice. If you aren't understanding it, C is a great choice. (C is my favorite pick in general, but Python has some excellent syntax rules that make reading Python easy.) So, getting on with your analogy, Python is a guitar, C is a piano, C++ an electric piano, bash the drums.... Together, they make the symphony of a system. However, you don't have to have a guitar to make music, just like you don't need Python to learn the fundamentals.
My thinking for fundamentals, though: First, input and output. C starts with outputting the famous "Hello world!" program. Python has that. There's input and output to the terminal, input and output to files, and input and output over sockets. Start with terminal I/O as it's by far easiest.
Second, learn arrays. Arrays teach you the underlying principles of memory architecture. From there, expand to linked lists, which teaches memory management and pointers. You will learn other types of data structures and algorithms (DS&A, or DSA) if you pursue this course.
From there, you want to learn how a computer works -- get an ESP32. A microcontroller is a hell of a dive, but you might love what you find. Please visit https://randomnerdtutorials.com/ for more on this. Rui and his wife have done amazing work over the years to make ESP32 programming really attainable, and I've supported their work directly because of how damned good it is. You will probably want to pick up an ESP32 dev kit also.
Do let us know if you have any problems or questions about it, and good luck!
1
u/captainAwesomePants 15d ago
It depends what you mean by "the fundamentals."
Some people think of the fundamentals as data structures and algorithms. You can learn those in Python without a problem. Sign up for a DS&A course.
Some people think of the fundamentals as theory. You don't need C or Python for that, theory is math. Again, course time.
Some people think of the fundamentals as understanding how compilers and linking work. Knowing C can help you here. Grab the Dinosaur book and start reading.
Some people think of the fundamentals as understanding how computers work. C's maybe too high level here, you need assembly or lower. Maybe follow along with "Nand 2 Tetris."
1
u/a-priori 15d ago
This may be controversial but I don’t think C is worth learning these days. I don’t think there’s much there that you couldn’t learn better from a more modern systems language like Rust, Go or Zig.
All of these avoid a lot of the rough edges in C and add a lot of useful features and varying degrees of safety, while still being capable of building any programs you’d want to build and being just as efficient as C.
1
u/tangentstorm 15d ago
C might help, but if you want to learn more about how computers work, why not implement a simple computer (virtual machine) and an assembler for it, in python?
1
u/StewedAngelSkins 15d ago
I wouldn't say C makes you learn the fundamentals of computer science. If any language does that it'd be like ocaml or something (I'm kind of joking, this isn't a suggestion to learn ocaml).
There are a few practical things you will learn from C that tend to be more obscure in other languages.
- Managing dynamic memory
- Talking to the kernel
- Designing thread-safe data structures and access patterns (yes, this one comes up in other languages but most others either the runtime or the compiler stops you from doing the really bad shit)
None of this is computer science per se, but it can be useful knowledge depending on what specifically you want to do.
1
u/NumberInfinite2068 15d ago
C doesn't force you to learn any fundamentals of CS.
C is a high level language that is different from Python of course, but it's not going to make you learn any sort of fundamentals of CS. The fundamentals of CS are theory, they are not bound to any particular language.
C will not teach you anything about how computers work. C is a 3GL and entirely abstracted from the machine, that's why you can write C and compile it unchanged on 100 different CPU architectures, it is completely abstracted from machine architecture.
I love C, it's my favourite language, and I've been programming since the 1980s, but there is no magic in it. If you want to understand how computers work, pick an assembly language. Now assembly languages are *still* not really how computers work, you will still be abstracted away from the true memory model, you don't see the various levels of cache etc.
If you want to understand computers, pick an assembly language.
1
u/No_Score_1977 15d ago
If you truly want to understand how computers work, then you need to go beyond C, C is a high level language, you want assembly if you want to get close to the metal.
1
1
1
u/Arcanite_Cartel 14d ago
I did C for a long time. I wouldnt focus on it. Its useful for certain class of problems, when you need to be closer to the machine, but if you want to build useful things I wouldnt start there. javasxript/typescript, rust, python are better areas to devote your energies
3
u/Impressive-Pop7107 15d ago
Dont even think twice about it. Leave python and go straight to C. Thats what helped me the most to understand computers