Hacker News new | ask | show | jobs
by lumb63 1608 days ago
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.

9 comments

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, 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.

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.

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.

> I don't think Python is a good beginners language anymore with all its complexity

It's not like the simpler parts of the language have gone away in recent versions. You can still program in python like it's 2.7.

Just as you can still program in C++ using C paradigms.

Agreed. C is a great starting point. It's a terrible continuing point though. Novice C programmers write seg-faulty code left and right, which is fine. That's not a problem; everything that's wrong is on the surface. In the mean time, they've learned how to implement a binary search tree or something, which is pretty cool when you do it in C. The intermediate two-star C programmer whose programs almost never segfault, that's the truly dangerous one. Precious few C programmers make it past that stage.
Ye, unless you to electrical engineering/close to hardware embedded or something. However even those probably benefits from mastering some memory managed language, before going back to C.
Good points. Though it would be a good debate that Go would be a better beginner language. Java's forcing of class based OOP would cause an avalanche of other kinds of problems that Go and C don't have to deal with.
Other than the 3 lines of boilerplate for the main method, Java ain’t forcing anything. You can write FP with it as well.

Also, it is probably better to get started with the much more common nominal typing over structural.

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

I don't think it's that bad - primarily because error messages are way more helpful, but also because it'll error about things that C would just choke on at runtime.

(I learnt/continue to learn Rust with only 'university C', fwiw.)

> 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.

They aren’t necessarily advocating learning C so that they can write lots of production code in C. They are advocating learning C to better understand lower layers of programming.

The basics of C are easy and illustrative. And given that the main Python interpreter is written in C, can be helpful to know.

Thank you. This was well explanined. Once again thanks for this. I am learning and will continue learning Python and Js. However, when I decide to pick a static language I will definielty be going for Go.
For many people (myself included), the ease of writing python jumpstarted my journey to eventually learning everything else you mentioned gradually.

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.

This is my major gripe with the college courses I took. They start at the molecular level and build to the planetary scale. This works for some people, but for me I had the hardest time finding a personal interest until I got to the application. It was the application I wanted to build, and to do actual work you don't manipulate the molecules directly.

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.

Yup yup yup. I've been coming to this realization about myself so much recently too. It's how I taught myself web/app dev with hackathons, facing a huge project head-on and "backtracking" to learn stuff as needed. It's how I taught myself machine learning by jumping into a research project with a prof without ever having written PyTorch. And it's how I'm now teaching myself higher math, having just jumped into the homotopy type theory textbook and an idea I have for application in NLP, and going backwards to learn the required category theory and algebraic topology.

I wonder whether the fundamental structure of curricula could be changed to take advantage of this fact, because I think it's true for a lot of people.

Agreed. I've found the insistence my college professors had on writing everything yourself and not using libraries or modules for common tasks to be in the end counter productive. Namely for the reason you described. To reference Carl Sagan, I didn't have the stamina in the beginning to build the universe before I made my apple pie.

Additionally, code is more collaborative than that, and it shows in a lot of engineering departments when people aren't trained on how to look at the shelf for existing parts before building something new.

>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.

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 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.

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.
You got me curious there. Do you have any resource recommendation to learn about the cost of different data structures/algos and such?
This is what big O (also little O and little omega) notation is all about. Unfortunately, all the resources I know of teach it as pure mathematics, so they require a firm grasp of mathematical proofs to understand the details and implications.

With that said I highly recommend the classic Introduction to Algorithms (CLRS for short) by Cormen et Al. It is written in clear and straightforward language. And the lectures on MIT OCW by Erik Demaine are outstanding.

By reading and watching the lectures I deeply understood stuff that I had just muddled through previously.

https://en.m.wikipedia.org/wiki/Introduction_to_Algorithms

Introduction to Algorithms is a classic that every serious programmer should read cover to cover.

at my first programming job (now almost 30 years ago), I remember implementing the red-black tree algorithms in C from that book. It is chock full of really useful ideas that will make your systems better.

CLRS is the text, but for a more gentle introduction see Grokking Algorithms.
Ideally you'd teach python to build a c compiler. ;)

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 https://news.ycombinator.com/item?id=28709239 :

> 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...

It seems like many of these problems were holes in the curriculum more than weaknesses in Python. However, modern python has type annotations, which help a lot with checking the program for correctness.

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.

I agree with everything you said, and feel exactly the same way; except my university switched from C to Java mid-way my attendance... so it probably just goes to show something or the other :->
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.

None of that pays the mortgage, though.