by lumb63 · 4y ago · 0 comments
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.)
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.
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.
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.)
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.
The basics of C are easy and illustrative. And given that the main Python interpreter is written in C, can be helpful to know.
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.
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.
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.
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.
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.
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.
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.