4 ms·
Regarding learning assembly, I'm beginning to come to the view that it's in fact the best way to teach the first course in programming to kids. They don't come
by chetanahuja 11y ago
Regarding learning assembly, I'm beginning to come to the view that it's in fact the best way to teach the first course in programming to kids. They don't come with any preconceived notions of what programming should look like and given an explicit, visual model of the computer, they quickly learn the small number of operations to write programs. More over, once they learn to do
LDA A
ADD TWO
STA A
DAT TWO 2 <-- initializing variable TWO
then, this line of code
A = A + 2
in C or a higher level language makes soooo much more sense. That awkward phase of internalizing that '=' is an assignment operator and is different from another operator meant to test equality gets a lot shorter for a beginner.
Btw, this is the best online CPU simulator I've found for that use http://peterhigginson.co.uk/LMC/ http://peterhigginson.co.uk/LMC/ I'm shocked at how all the code academies and hour of code's haven't created a polished version of LMC (Little Man Computer... look it up).
- RodgerTheGreat 11y agoI've had some success teaching middle schoolers with Chip8 and a structured assembler: http://johnearnest.github.io/Octo/ http://johnearnest.github.io/Octo/
- chetanahuja 11y agoIf you're still involved in teaching school kids some sort of assembly but still in a fun and visual way, I highly recommend checking out the link to LMC I posted above.
- userbinator 11y agoThat looks like 6502 but it doesn't have ADD, only ADC. I prefer the Z80 though. :-) I also think starting with Asm is a good idea, because it forces you to think about things like data representation (often glossed over in HLLs) and breaking down complex operations into a series of simple steps - something that you have to internalise effectively to become good at programming. If there is time for it, going one step lower to logic gates would be even better to dispel the "magic" and see that CPUs are actually very conceptually simple and logical machines. Of course to become productive they should move to a HLL and learn the higher-level organisation (functions/procedures, objects, ...) but I agree that the basics are important to understand first. This is a book I strongly recommend, it's definitely written at a level readable for kids and young adults: https://en.wikipedia.org/wiki/Code:_The_Hidden_Language_of_Computer_Hardware_and_Software https://en.wikipedia.org/wiki/Code:_The_Hidden_Language_of_C...
- tachion 11y agoIn my personal case I am not sure if it didnt end up 'bad' for me. The first language I've learned was 6502 ASM on C64 (and learned is a word of many degrees here, I can't say I've written anything serious in it, ever) and for some reason I've been struggling with many other languages for years to come after that - tried Perl, PHP, C, AmigaE, without being able to grasp any of those. Until I've met Python, that in few days took me from ground to the stratosphere (which today again looks like a ground, but that's a different subject). And even then, old habits of counting cycles and thinking about what the hell is the language doing made me to prematurely optimize my code (like doing 'while 1' instead of 'while True' because in 2.7 True is simply a variable, what means the interpreter will have to check its value first and that means lost CPU cycles, and lots of other things that made sense in 6502 ASM) instead of getting it to do shit ;) It took me a while to 'unlearn' those habits and to simply enjoy the language in its own form.
- themartorana 11y agoWell yeah, except now I have some `while True:` statements to clean up...
- nnq 11y ago> That awkward phase of internalizing that '=' is an assignment operator and is different from another operator meant to test equality gets a lot shorter for a beginner. I'll probably have to thank one of my highschool math teachers for inadvertently helping me skip this phase altogether then :) He always pestered us to use the "equivalence" operators ⇔ or ≡ (the latter mostly for geometry stuff), and only use the regular equal when you had unambiguous contexts like "Let f(x) = x + 2" or "if x = 5". At the same time I was learning programming (with C++ as my first language...), and I could easily see "=" as being for assignment, since in other contexts you either used something more fancy (like ⇔ or ≡ in math, and "==" in code) or you used explaining words like "let" or "if" to clarify meaning. Though I think it took me a while to get things like `while (x = getch()) { ... }` :)
- nightcracker 11y agoI don't agree with your math teacher. ⇔ is not equivalence, it's a symbol for 'if and only if'. The left hand side implies the right hand side, and vice versa. Writing a * a - b * b ⇔ (a + b)(a - b) doesn't make any sense, because neither the left hand side nor the right hand side are logic statements.
- rodgerd 11y ago> That awkward phase of internalizing that '=' is an assignment operator and is different from another operator meant to test equality gets a lot shorter for a beginner. Pity language designers don't take the more obvious solution of making their maths-derived operators behave like the language they're drawn from.
- kriro 11y agoI've talked about the x = x + 2 / x == 0 "problems" with a couple of people during university and it seems there's different levels of problems/irritations people have with the syntax. For me it was mostly a "shrug ok so that's that, don't see the problem" when it came to accidentally using "=" instead of "==". A couple of friends seemed to have mental blockades and often wrote code containing the typical bug of "=" instead of "==" (the hotfix of 1 == a instead of a == 1 helped some). For me the irritating thing was x = x + 2 since it triggered my math brain which protested and simply said...well that can't be, error. So I guess I did have the exact reverse problem always seeing the assignment as an equality. Thankfully this passes really quickly after you immerse yourself in it for a day. Of course years later one of the first sentences from our Prolog 101 prof was "so you have been programming for a while now...let me write this down...i = i + 1...someone explain what this does...what would you suppose a (stereotyped) mathematician (that only knows math) would tell me" Kind of made me smile. /offtopic_anecdote
- aninhumer 11y agoSurely something like Logo has similar advantages (small set of simple instructions) without requiring students to learn about CPUs before they can start? Plus it means they get to draw pictures instead of relatively boring calculations. And switching to assembly seems like a pretty overkill solution to the = vs == problem.
- chetanahuja 11y agothe = vs == is just an example of how having a robust mental picture of how computers actually work makes high level programming more intuitive. And you don't really have to teach a real CPU for this to work. Check out that link I posted. It's a greatly simplified CPU simulator with visual feedback on every step the CPU is taking (e.g., PC increment, fetching the next instruction, storing something in memory etc.) It's great fun for kids to watch how a little program they wrote made the computer do all that work.