Live data from Hacker News

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

news.ycombinator.com

51–60 of 93 posts

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

#51
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.)

I think many programmers forget how it was to learn to program. Imagine the horror trying to make Rusts borrow checker happy without even understanding what an object scope or pointer is.

C is a really good beginner's language, since any oop is explicit with function calls, kinda like Basic. No invisible destructors etc. Modern compilers even warns you on returning pointers to stack locals etc.

I don't think Python is a good beginners language anymore with all its complexity. Maybe Go or Java.

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

#52
It’s not clear what is meant by “to better understand Python”. Better understand CPython, e.g. and you want to hack on the interpreter, or better understand how to write more creative/abstract/safe Python?

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.

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

#53
post #37

Earlier quoted context omitted.

>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 teach…

Updated the original comment accordingly. 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…

Yeah, that’s true. Calling it a “dictionary” definitely doesn’t help! I would support any and all efforts to stop inventing new words for established constructs. I learned to program with Python and I am confident these things held me back, now that you mention it.

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

#54

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.

are you saying that if you want to learn the internals of cpython you don't need to know c before hand? i think learning c is a must for this case

No, I'm saying C is not enough on its own.

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

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

I don't think the mental step between C and assembler is that big. You got almost no constructs in C that does not map directly to assembler, like function overloading or classes.

The confusion starts when the optimzer throws around your code and makes it unreadable.

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

#56

Earlier quoted context omitted.

are you saying that if you want to learn the internals of cpython you don't need to know c before hand? i think learning c is a must for this case

No, I'm saying C is not enough on its own.

sure there is much more to it than just knowing c, but learning it should be encouraged as an important stepping stone if someone wants to learn cpython internals ... or even internals of many (most?) popular python libraries

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

#57
The point of learning C as a python developer isn't to learn C nearly as much as it is to better understand what's going on in the levels of abstraction below.

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.

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

#59
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…

I always liked the stick shift versus automatic for drivers ed analogy.

Yet in an era where inclusiveness and student retention are deemed more important than foundational learning, its no wonder Python is getting mass adoption.

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

#60
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…

None of that pays the mortgage, though.
Post reply on HN