It’s funny that I never have this trouble in C, but do in various reference languages. There’s something to be said for making pointers explicit to remind the developer that yes, there may be other pointers out there.
Separating references and values is extremely useful!
Functional languages, of course, prefer everything to be immutable. So if we want changes to be shared, we need to handle that as the exception rather than the rule. Immutability is a handy property, one that makes it harder to create several kinds of bugs. But when things do need to change, immutability can introduce complexity, so it’s by no means a free breakfast.
Languages like Haskell allow us to have mutation, we just have to actually talk about the mutation:
newIORef :: a -> IO (IORef a)
readIORef :: IORef a -> IO a
writeIORef :: IORef a -> a -> IO ()
We get tools to talk about values and tools to talk about mutation. Which seems to imply that we do get a free breakfast: by subsuming existing tools!
This is a feature, not a bug. I know that sounds trollish, but it seems really clear to me that the bug is based on the person misunderstanding either assignment or mutation. I think it’s the sort of mistake in a person’s mental model that you see a lot with inexperienced programmers. I find it hard to understand how partyDate.setDate(5); is supposed to NOT affect retirementDate since the mere assignment did not create a new object, and the mutation return value isn’t used.
I get what is being said there, but I guess I bristle at the title. I imagine the obviousness (or lack thereof) depends on the languages you cut your teeth on?
It’s a language feature. That doesn’t mean it can’t lead to bugs in programs.
Eh…I went in looking for signal processing reference and it turned out to be something entirely different. Is this really called ‘aliasing’? Both wikipedia and dictionary have no such reference. I wish folks didn’t misappropriate established terms according to their whims and fancies.
Yes, it’s an established term. It would less ambiguously be called “pointer aliasing”. It has a long history of use in connection with study of its implications for optimizing compilers.
Huh? The very first thing the Wikipedia article for aliasing says is:
This article is about aliasing in signal processing, including computer graphics. For aliasing in computer programming, see aliasing (computing).
With a link to the article about pointer aliasing.
Python explicitly calls this aliasing.
Objects have individuality, and multiple names (in multiple scopes) can be bound to the same object. This is known as aliasing in other languages.