I come from a PHP/Javascript background where things are stored in a variable directly in most cases, where we also had Object/Classes/Methods, etc. It was OOP.
Now I’m starting to learn Objective-C. I understand the basics of pointers. But everything is a pointer now. This is the part that I don’t get. Why aren’t we like in PHP/Javascript with direct assignment? We are still doing OOP afterall.
Thanks
If you look at the semantics of JavaScript and many other OO languages (perhaps including PHP, but I’m not sure and not willing to guess), you’ll see that these languages offer the same indirection Objective C offers through pointers. In fact, internally these languages use pointers everywhere. Consider this (JavaScript) snippet:
It’s roughly equivalent to (C as I don’t know Objective C) something like this, modulo manual memory management, static typing, etc.:
It’s just explicit in Objective C because that language’s a superset of C (100% backwards compability and interoperability), while other languages have done away with explicit pointers and made the indirection they need implicit.