News for hackers. Stuff that matters.
Re:Teaching how to code is broken by asleepawake on Friday January 14, 2022 @02:28PM (#29939139)
Having a good mental model of a language seems like one of the fastest ways to be more productive in that language. Do you have any recommended resources for developing a strong mental model of python? For reference, Dan Abramov’s course JustJavascript [1] provides an amazing mental model of JavaScript, and Josh Comeau’s css for js developers [2] course provides an amazing model for understanding css. I have 5+ years programming in python but admittedly do not know much about the internals so my mental model is pretty weak!

[1]: https://justjavascript.com/ [2]: https://css-for-js.dev/

Re:Teaching how to code is broken by hexane360 on Friday January 14, 2022 @02:40PM (#29939285)
One way I've found is to dig into C/C++ extensions to Python. The Python C API reference is very helpful: https://docs.python.org/3/c-api/index.html

It can be quite fun to implement a simple data structure (tree, queue, etc.). in C and bind it to Python.

Otherwise, you can get a lot of dirty details by reading the source to complicated/magical libraries (e.g. pickle).

Re:Teaching how to code is broken by mynameismon on Saturday January 15, 2022 @06:42AM (#29945649)
I can confirm this works.

I was struggling to find why does a = [1, 2, 3] a = b b = b + [1] return a different value as compared to b += [1]

Looking into the source code, everything became clear. The + operator returns a pointer to a new list np containing all the elements from a and b, while += merely appends and returns a pointer to the original list

Re:Teaching how to code is broken by TuringTest on Saturday January 15, 2022 @03:06AM (#29944673)
> Having a good mental model of a language seems like one of the fastest ways to be more productive in that language.

True, but teaching s programming language is different than teaching programming.

Diving into a new language is something you do if you already understand how computers work and how to turn requirements into code. But to first acquire that understanding as a beginner, it's not enough to be introduced to the specifics of any particular language, which is what the article is talking about; you need to clarify what is the role of a programmer in understanding a problem and finding ways to model it as a group of data structures and functions that live in the computer.

Re:Teaching how to code is broken by touchngthevodka on Friday January 14, 2022 @03:09PM (#29939662)
Have you tried Fluent Python? It really helped to level up my knowledge of the language.
Re:Teaching how to code is broken by __mharrison__ on Saturday January 15, 2022 @01:11AM (#29944024)
(Disclosure: This is my content).

Why thanks for asking yes I do: I recommend my book, Illustrated Guide to Python 3 [0].

Yes, I teach "professional" Python programmers who lack a lot of the fundamentals. It is so easy to get my with Stack Overflow style of programming these days. (Plus a lot of my students don't want to be "programmers" they use Python as tool to get some job done.)

0 - https://store.metasnake.com/

Re:Teaching how to code is broken by bear8642 on Friday January 14, 2022 @11:24PM (#29943519)
Feel this mental model approach is part of the appeal of Scheme and SICP as you start with simple replace model but near the end (still exploring chapters 4,5) you get shown how to build an interpreter which forces you to know how it all works because otherwise it doesn't.

Feel that's sentiment get more now - it's *not* magic but the fact that everything works given it's all illusions is magical

Re:Teaching how to code is broken by istjohn on Friday January 14, 2022 @08:48PM (#29942803)
There is a truly excellent series of lectures on YouTube from a college course on the Python interpreter internals. But I can't for the life of me find it. One resource I can recommend though is pythontutor.com. It's a tool that will step through your code snippet and show how the code maps onto the internal representation.