4 ms·
Oddly I find pointers intuitive and easy in Pascal and assembler - arcane and complicated in C. Java (memory model) is also rather difficult to internalize IMNH
by e12e 10y ago
Oddly I find pointers intuitive and easy in Pascal and assembler - arcane and complicated in C. Java (memory model) is also rather difficult to internalize IMNHO - probably because of the complication of "bare" types (eg: int), boxing, pass by reference and some rather muddy default/usual containers/objects/arrays etc.
Other than for teaching "an industry language" I don't immediately see much reason to teach C and Pascal - but I suppose the "modern" equivalent would be Python, Cython, C and assembler, followed by haskell/(oca)ml, Prolog and/or a lisp/scheme - with the benefit of showing C interop along the way.
- kazinator 10y ago> Oddly I find pointers intuitive and easy in Pascal and assembler Sure, sixy seven lines of assembly handily beats arcane crap like: obj->ops.tbl[BLAH]->func(obj, &obj->x, arg); Want to take an integer in a register, then add another register's integer multiplied by 8 or 4, and then a fixed offset? Just use LEA (load effective address) and don't comment anything. Let the reader figure out that no pointers are involved.
- emmelaich 10y agoI guess you're being sarcastic but I honestly can't tell. [edit: 99% sure is sarcastic]
- int_19h 10y agoI can't help but wonder if the reason why Pascal pointers feel less complicated because they're more constrained, or because of the syntax, or both. On the constrained part of things, there's no pointer arithmetic, and in Standard Pascal, there's no "address of" operator at all - a pointer can only point at dynamically allocated memory block, not at global or local variable, or some memory location inside another block. Consequently, there's also no pointer arithmetic. This is sufficient to make linked lists and other similar data structures, but also makes the concept much more opaque compared to C (i.e. it's less obvious that it's really a numeric address). On the syntax part, I think the big problem with C is that the moment you start dealing with pointers, the arcane rules for declarator precedence are in play. Pascal, OTOH, has a very regular type syntax, which in case of pointers is also easier to read - you just read ^ as "pointer to", and so ^integer is "pointer to integer". Same thing for dereferencing - again it's ^, but there you read ^ as "points to", and so a dereference like x^ becomes "what x points to". And there's also no confusion with any other operator, since ^ is reserved for pointers alone, and it has a fairly obvious mnemonic to it.