Live data from Hacker News

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

news.ycombinator.com

21–30 of 93 posts

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

#21
No, it won't help you better understand Python.

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.

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

#22
post #15
post #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…

There are certainly some advantages to be gained from greater mechanical sympathy and an appreciation of static types. However, in the modern day, I wouldn't suggest a Python programmer learn C to achieve either of these things. 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…

This is a fair point. Most of my response is driven by the fact that I think there is value in understanding a lot of the behind-the-scenes things that the language does, so I mostly agree. Really, I’d suggest learning as many languages as possible - they influence the way you think about the code you are writing and having the different perspectives allows you to broaden your horizons and see what else is possible. Eventually, this is how you form your opinions on what makes a programming language “good” and allows you to contribute to the decisions we all make daily over what technology to use and what becomes popular.

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.

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

#23

Yes. Learn C. 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.

Exactly. Learn multiple languages. Not really 'all of them' or all super in-depth, but if you want to do more than complete simple pre-cooked tasks of a to-do list (or JIRA board) you'll probably need to understand a bit more about the how/what/why.

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.

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

#24
post #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.

given that python is usually implemented in c (look up cpython), knowing c can help you at least understand internals of python

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

#25
post #15

Earlier quoted context omitted.

There are certainly some advantages to be gained from greater mechanical sympathy and an appreciation of static types. However, in the modern day, I wouldn't suggest a Python programmer learn C to achieve either of these things. 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…

Those are all vastly more complicated than C. And on top of that you have to learn three instead of just one! (Imagine trying to learn Rust without experience with C. Oh man.)

> Those are all vastly more complicated than C.

C's simplicity is an illusion. The vast quantity of footguns and edge cases make writing correct C extremely complicated.

> And on top of that you have to learn three instead of just one!

You don't need to learn all of those, select one based on what your goals are. And it's not like gaining a surface-level understanding of any of these programming languages would take more than a week to a month anyway.

> Imagine trying to learn Rust without experience with C. Oh man.

It's quite the opposite. Rust is a dream to learn compared to C. The Rust compiler is like having a personal tutor at your beck and call to teach you systems programming best-practices. Without exaggeration, these days I would not suggest someone start learning C until they have learned Rust.

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

#27
I think unironically learning assembly helped me the most in understanding the computer itself,I don't know about understanding Python through this manner.But through this fashion you can get an idea of how functions are made and operate.I feel like the jump between asm and C & 'higher' languages is bigger than the one between C and Python.

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

#28
I learned C and have worked with C++ professionally in the past and that knowledge doesn't help at all with understanding what Python is doing internally. Sure, CPython is written in C, but that fact doesn't tell you anything about the details of how it's implemented or what it does when it runs.

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

#29
here is a way knowing c can help you become a better "python" programmer: write a library that is much faster in c than in python (allways the case). then create a python wrapper around it and make it a python library. something like this happens with all numerical libraries in python

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

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

#30
post #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…

>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 on average O(1) but worst case are O(n).

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.

Post reply on HN