5 ms·
Sometimes it is much simpler to solve a problem by passing by reference Sometimes, but very rarely. I got a long way in Swift before I needed to use inout para
by iainmerrick 5y ago
Sometimes it is much simpler to solve a problem by passing by reference
Sometimes, but very rarely. I got a long way in Swift before I needed to use inout parameters, or even realised the language had them at all!
The article is specifically talking about teaching beginners; call-by-reference is a risky technique of limited value, and therefore it’s best to delay introducing it. If you introduce it early, students will get into the habit of using it too often, mostly in the wrong places.
- qsort 5y agoOnly very rarely because modern languages implicitly pass pointers to objects instead of objects themselves. I agree that at a CS 101 level it's a useless complication, though.
- mikewarot 5y agoPascal will pass the value of an object by default, you can use a VAR parameter to explicitly allow side effects, or optionally, you could pass the @address of the parameter for things where you want to play with pointers. Wirth was a pretty smart cookie when perfected the lessons from Algol into Pascal. 8)
- qsort 5y agoYeah, I never used Pascal (I cut my teeth on C), but it does seem like a nice language, especially for its time. For something like Java or Python, though, it makes sense that the argument is implicitly a reference to the object it takes (at least as a default). 99% of the times you don't want to pass around stack-allocated stuff.
- iainmerrick 5y agoI started with BASIC, and never liked Pascal at all (I eventually took to C like a duck to water), but it must have something going for it as a systems language because the original Mac OS was largely written in Pascal (I’m not sure of the balance between Pascal and assembly). I wonder if we’d have fewer memory-related bugs now if the industry had standardised on Pascal strings (length prefix) rather than C strings (null-terminated)?