For instance, when you only need to write two curly braces to create a “dictionary” (of course behind the scenes this is a hash table) many of the nuances of that data structure are hidden from you. You have no idea that accesses are O(1) amortized but worst case are O(n). Even if you do, maybe you don’t understand why. You have no idea that there is reallocation and collision handling code working behind the scenes constantly.
Python also lacks a number of nuances I consider it important to be aware of. You live your entire Python life blissfully unaware that everything is a pointer, and the impact that has on performance. You never come across static typing, or that it is possible to check your code for some level of syntactic correctness before it runs (i.e. Python is interpreted rather than compiled).
I think from this standpoint, it is worth learning a language like C to gain an appreciation for how truly complex a lot of the things Python allows you to do, are. I think that anything which helps you better understand what it is you are doing, how you are doing it, and why you are doing it that way, will make you better at doing that thing.
For a Python programmer who just wants to learn about static type systems, learn Typescript.
For a Python programmer who wants to learn about static type systems and mess around with pointers, learn Go.
For a Python programmer who really wants to get elbow-deep in a natively-compiled language with a fairly sophisticated type system, learn Rust.
For someone who doesn't want to actually use C and just wants to learn concepts, C doesn't really have any advantages these days. Its type system is anemic, its compilers are unhelpful, its abstractive capabilities are poor and leaky, and its claims of being close-to-the-metal are overblown on modern processors. There are plenty of good reasons to learn C, but IMO "to become a better Python programmer" is not one of them.
I still do think there is value in learning C, though. Of extant languages (disregarding assembly), I believe C is the ancestor of nearly every programming language today. From a historical perspective, understanding C and it’s shortcomings allow you to understand the motivations that created even higher level languages. Similarly, it would be hard to understand a lot of the decisions the C language makes without an understanding of assembly, why assembly instructions are as they are without understanding computer architecture, etc.
There is also an argument to be made that C is still extremely ubiquitous. I like Rust as a language very much and think there is a great deal to learn from it, but it is still so immature (though it has come a long way) that I would feel disingenuous suggesting it to someone who only knows python as a way to gain a better understanding of programming languages. I imagine it would be akin to encouraging a Buddhist to practice Lutheranism shortly after Luther’s schism rather than learn about Catholicism first - someone who does so would be blindly ignoring all the history and motives that drove that change in the first place.
(Imagine trying to learn Rust without experience with C. Oh man.)
If I would have had to learn it immediately I most likely would’ve felt disinterested and overwhelmed and given up since I didn’t know yet why I needed to learn it.
Build an application, then as you need to learn more to get things done you naturally pick up a deeper knowledge of the tech you're using.
Of course this is different for everyone.
Well, that is wrong. Single value accesses are O(1) amortized.
Also, Java is a lower level language but I don’t think simply programming in Java instead teaches you this. Either way, it’s the difference between learning how to write programs and learning computer science.
I suppose that’s also fair. I would say that Java at least makes you aware that there is magic afoot. You have to explicitly write that you’d like to use a HashMap, at which point someone writing or reading the code might wonder “what’s that?” Instead, python hides behind the abstraction of a “dictionary” when it should be in my opinion broadcasted from the high heavens that this is a hash map in disguise.
As far as the remainder of your comment, I agree wholeheartedly. Learn computer science. It makes you a better programmer.
That said do people know more about the innards of Java ? It shield you from a lot of details too. From memory layout, to polymorphic calls.
> From "Ask HN: Is it worth it to learn C in 2020?" https://news.ycombinator.com/item?id=21878372 : (which discusses [bounded] memory management)
> There are a number of coding guidelines e.g. for safety-critical systems where bounded running time and resource consumption are essential. *These coding guidelines and standards are basically only available for C, C++, and Ada.*
> awesome-safety-critical > Software safety standards: https://awesome-safety-critical.readthedocs.io/en/latest/#so...
> awesome-safety-critical > Coding Guidelines: https://awesome-safety-critical.readthedocs.io/en/latest/#co...
I would say every one of these concepts can be taught with effective curriculum using modern Python.
Now, I still think one studying computer science would be well served to learn C at some point! But Python is a great replacement for Java in the curriculum.
Yet in an era where inclusiveness and student retention are deemed more important than foundational learning, its no wonder Python is getting mass adoption.
You won't just get better at python, you'll get better at pretty much anything involving programming or understanding how a computer works.
I've seen a lot of people say that if you learn C well, you're basically employable for the next 30 years. I think I agree with that.
In embedded systems programming, right? It must take significant C expertise and experience to be gainfully employed. Maybe I'm overthinking it?
It seems liking the C language is frowned upon in this site.
Not to understand python, but to become a better programmer and gain a better understanding of computers.
We desperately need more people learning the 'hard' languages. Python is fun, but libssl, libcurl, the Linux kernel, and all the other 'important' things need more developers.
Learning more languages or different languages will let you see the similarities and differences but also the way they all end up running on the same system, calling into the same libraries and operating system.
That said, languages are generally just 'ways to write', often aligned with 'ways to think' but they aren't themselves the algorithmic and data structural concepts which are very useful to at least know and have played around with a bit. It doesn't mean you actually end up re-implementing every doubly linked-list in all your code, but knowing the concept of hashing and binary trees, seeing how they can be helpful in hashmaps, and how turning arrays into trees and back again gets you so much extra understanding that when you do finally end up writing some production code and needing to make it work faster, use bigger datasets or reduce cost by optimising resource usage you'll at least know where to look and what to search for in your refactoring spree.
Learning C and perhaps C++ is great for writing system libraries that need to run close to the metal, but I wouldn't really want programmers to still use those languages in general software development. If Go and Rust gets you there 90% of the way and you can glue things together with Python, Lua and other stuff you'll be able to make reasonable software for general use which is what most development ends up being anyway. Java (and C#) are still there of course, and you'll still want to at least play around with those just to get a sense of the (software world) around you. The time that you just boxed yourself in with 1 OS, 1 IDE and 1 Language with 1 Framework is passing (or has mostly passed) in commercial development. Throwing raw source code over the fence for 'ops' to do the rest is dying off.
However, for professional development, you should probably learn it anyways before you jump into other lower level languages.
C is the Latin of programming languages, as it's the common root of a flurry of languages, and you see it's influence in a lot of places. Even though it's not exactly "how a computer works," understanding its purpose and problems puts other languages into context.
The technology we call “C” is not just the language — it’s the whole system of language, preprocessor, compiler, linker, assembler and debugger that comes together to produce and inspect machine code. In terms of computing machinery, there is no more fundamental target than this.
Accordingly, you should learn enough about the C ecosystem to be able to debug a C program. It’s enough to be able to read code in C, but you will want to write some to get a feeling for the culture (passing the address of where you want the result of a function as a function argument is the big one, and it’s accompanying subtasks around memory management and pointers.)
You don’t have to go inside the compiler itself but I would recommend looking at some simple machine code and trying to assemble some yourself. You could do this on arm or x86, or on an emulator like this one for high school students: https://www.peterhigginson.co.uk/AQA/info.html
Once you build a sufficiently complex bit of assembly code you’re going to want to extract out common “functions” and give them names, and develop a convention for how to use memory, which registers do what when you call a function.
That’s what a C compiler actually does.
You should learn some more fundamental aspects of programming:
1. What's the stack, what's the heap, why do I get a stack overflow from recursion?
2. In C, what's a pointer, how does it relate to arrays?
3. What's garbage collection, and how does it work?
And that will eventually lead you to the inevitable:
4. Why is Python so slow? (haha - getting ready for the downvotes!)
In my experience Python programmers can be divided into two groups, those who write Python and those who write Python frameworks, aka Python for other Python programmers.
The latter group is trying to create an abstraction that helps solve a problem in an elegant way. Often to do that a deep understand of the language is needed such as the use of descriptors, higher order functions, the Python object model, metaclasses.
One of the best books for this is “Fluent Python”. It’s also a good to browse around significant projects and understand how they work and what patterns are used, eg Django, Flask, etc.
If what you really want is to write or read C, then of course you should learn C.
What about Python are you trying to understand? You can learn more about Python internals without needing too much C. And you can get better at Python without knowing much about the internals or C. So it looks like a waste of time.
Which of these 3 aspects do you feel C would help you understand better?
Maybe you are asking this question because you want to understand programming languages and how they work in which case a course in compilers and programming languages from a MOOC would help.
Maybe guide them to C++ for standard template library equivalence. But then you have another ocean of pain because C++ is the kitchen sink.
No need to learn C to better understand Python. Almost any gain you would make could be had by reading or watching an overview of the internals.
I learned python, JavaScript, and Java before C, and it wasn’t until I learned about manual allocations, pass-by-value, and pointers that the garbage collected languages made sense. It had never really clicked why all object params are references in those languages until I learned C and C++
Now, I don’t think it’s essential, but learning more about how computers and memory operate doesn’t hurt!
You could take weeks 1-5 of CS50 [1] to learn enough C to get by. The course continues from week 6 with Python so it’s the perfect intro.
But, the twist is start from a higher level algebraic problem, like a generalized N-dimensional distance function.
Get started with enough Python to do it in two dimensions, then translate the core of your algorithm to Cython and compare the benchmarks. This will get you up to speed with the build processes progressing towards pure C in comparison to plain old interpreted Python.
Are you using floats or integers? How accurate is it compared to using a calculator etc. as the numbers get much bigger or have many more numbers after the decimal point.
Then, what about the median distance of two arrays of 2d coordinates? Again, benchmark, try out some different approaches to the problem in both languages and see where the different strengths lie, wrapping your head around how programs interface with each other internally across domains - because that's what it's all about right?
Now... what about 3 dimensions? Or four?
I hope you see where I'm going here, if you're looking for a fundamental understanding then you need to get into the nitty gritty - albeit with a conceptually very straightforward problem.
The confusion starts when the optimzer throws around your code and makes it unreadable.
Many years ago, as a student, a friend let me borrow their copy of "Hacking: The Art of Exploitation". At the time I thought I was going to be learning about security. What I learned instead was what a program was, what a computer was, at a surprising level of detail.
Especially the early chapters, a true picture of what computers are doing is given to the reader. And once you understand that, you could apply the knowledge to security, no doubt. But you could also apply it to understanding many higher level languages- Python included.
You can find older editions online as PDF files. Really recommend it.
Whether it is true for C and Python I don't really have an opinion.
Any pointers to a good video on the topic? "Overview/Survey of features in programming languages"? Thanks.
When I look at a language like python or PHP I often just go down to the C code they call and use a tracer to watch calls to solve a problem without actually using the higher language.
Interfacing with python with your own C code is easy and the combination of the two is a much more powerful tool than either alone.
I would choose Python for fast prototyping and proofing-of-concepts, C for performance-intensive apps.
Don't let the fact that it has a garbage collector scare you -- you can turn it off if you don't like it.
Other strong choices of newer languages to choose from would be Golang, Rust, Red, or Vlang.
If you're a (reasonably proficient) C programmer, is learning to use Python worth the effort? Or is it just redundant education?
I can see that learning Python is probably worth it for a new programmer, but is it worth it for a proficient C programmer?
[Let the flame wars begin!]
E.g., Jax "just works" for a wide variety of numerical problems, handles the automatic differentiation and operator fusion and whatnot and figures out how to efficiently shove it onto whichever coprocessor(s) I want to target.
besides that, knowing other languages will help you become a better programmer in general. usual classic advice is learn c, lisp, and ml
however you still need to know good programming practices, data structures, and algorithms. with the exception of the first, these are not language specific
you might be able to grep cpython source more intelligently, but it won't help you at all with the semantics of the python language itself (versus its dominant implementation), and might hurt.