← Back to context

Comment by yetihehe

1 year ago

> So why teach someone a language that doesn't have if, while, (local) variables, scopes, types, nor even real function calls?

You can teach them how to implement function calls, variables and loops using assembly, to show them how they work under the hood and how they should be thankful for having simple if in their high level languages like C.

That often leaves people with very bad mental models of how programs actually compile in modern optimizing compilers and in modern operating systems (e.g. people end up believing that variables always live on the stack, that function parameters are passed on the stack, that loops are executed in the same way regardless of how you write them, etc).

  • Think about how far they've come if you get them to have these "misconceived" ideas!

    They would understand code and data are in the same place, that all flow control effectively boils down to a jump, and they have a _more_ accurate picture of the inside of a machine than anyone starting out with Python or JavaScript could hope for.

    Having spent 25 years to get to assembler, I wish I'd started it sooner. It's truly a lovely way to look at the machine. I'll definitely be teaching my kids how to program in assembly first (probably x86-16 using DOS as a program launcher)

    • They have to want to understand any of those things first.

      Be very careful that you're not going to just kill enthusiasm for programming as an activity entirely with this approach.

      I see this happen a lot (I did a lot of robotics/programming mentoring), and then adults wonder why their kids don't like any of the stuff they like - and the reason is that the adult was really a dick about making them learn the things the adult liked, and ignored most of the fun aspects of the activity, or the wishes of the kid.

      5 replies →

    • > and they have a _more_ accurate picture of the inside of a machine than anyone starting out with Python or JavaScript could hope for.

      Frankly, a more accurate picture than those starting in C have, too.

  • After learning asm, teach compilers and have them think about how to generate code stupidly, then think about how to generate efficient code. If you don't want people thinking about the stack, just teach them RISC rather than x86.

    • So you think people should start their programming journey by writing a compiler in assembly? What exactly should it compile, if they haven't learned any other language?

      2 replies →

  • But if they know assembly, they can look at actual compiler output and form the correct mental models...