Live data from Hacker News

Ask HN: Is it worth it to learn C to better understand Python?

news.ycombinator.com

1–10 of 93 posts

Re: Ask HN: Is it worth it to learn C to better understand Python?

#2
I advocate learning ASM to understand the machine; C and python are the same relation one step of abstraction up. So yes, more knowledge of C and how Python is written and what the interpreter is doing with your code is very likely to be helpful.

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.

Re: Ask HN: Is it worth it to learn C to better understand Python?

#4
I learnt C around the same time when I was learning Python and I don't believe it had much of an impact on the latter. Unless you're building a Python interpreter, I don't see how it can help with learning the language. While C has served me and many others well, I don't think it should come before learning a modern alternative like Rust or Go.

Re: Ask HN: Is it worth it to learn C to better understand Python?

#5
Unless you want to contribute to CPython, no.

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.

Re: Ask HN: Is it worth it to learn C to better understand Python?

#7
What do you want to understand about Python? To understand the performance of Python it's more important to understand how CPUs work, but C doesn't help much there. If you look up how e.g. a hash table is implemented at the low level it should give you and idea how the "standard library" and dicts of Python work.

Re: Ask HN: Is it worth it to learn C to better understand Python?

#8
Python is so far removed from C that I struggle to think of anything about C that would help you to better write or understand Python. If anything, it might make your Python worse if you try to import C idioms to Python.

If what you really want is to write or read C, then of course you should learn C.

Re: Ask HN: Is it worth it to learn C to better understand Python?

#9
In college I used to tutor students in computer science. Mid-way through my college career my school switched the curriculum to teach Python instead of Java. I found that the students who took Python lacked what I considered a basic appreciation for and understanding of how the language actually ‘does’ something.

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.

Re: Ask HN: Is it worth it to learn C to better understand Python?

#10

I would say it depends on what you want to do. I would choose Python for fast prototyping and proofing-of-concepts, C for performance-intensive apps.

I'd really rather recommend Nim [1] for performance-intensive apps. Its syntax resembles Python, it is far and away safer, but it complies (via generating C) to a full binary, and the resulting binary is very fast.

Don't let the fact that it has a garbage collector scare you -- you can turn it off if you don't like it.

1: https://nim-lang.org/

Post reply on HN