C vs C++ vs Lisp (156)

109 Name: #!/usr/bin/anonymous : 2008-08-15 18:31 ID:svxdzyWV

>That Visual Basic has things called reference types and value types? Or that C++ does?

That VB.Net, C#, Java etc make a distinction of how objects variables are treated in OOP. That distinction means the programmer is always working with instances of the objects they create. It is OBJECT Oriented Programming.

A object variable in a language that has reference variables is ALWAYS going to be refering to the instance of the object created in any scope it is passed to. C++ certainly can do this, but this is not its default behavior. You have to create the reference or pointer to give it to different scopes. It takes extra in C++ steps to do a very basic OOP thing properley. So as an OOP language I do not see C++ being that great at it. The language itself should abstract the proper way to work with objects. I feel the proper way is to always refer to the instance of an object (as I understand OOP and working with objects in it), these other languages just handle it with references to that instance and the solution is a good one C++ already abstracts many things from the programmer, so it should abstract this basic conept of OOP (but can't of course lest it break its other paridigms).

>Finding the passage "A reference variable is one that evaluates to a pointer." would do that.

Yes, I did a quick search for that again. I can't remember the first search I did to find that. It is in there somewhere, but the documentation is extensive.

>So encapsulation is preserved.

Except implelementing the change to the instance is left up to the calling scope. If I pass a car to a paint funciton, I want that function to paint the car I gave it. I don't want it to paint another car. And then make that other car the car I just told the function to paint.

>In addition, for a high-level language, just because it has pass-by-value semantics doesn't mean it's doing copying under the hood.

That could be true, but now the programmer needs detailed knoweldge of the compiler optimizations making that not so high level.

>Yes, but what if you start with the second. You're faced with the following code:...

Your example makes sense. But I would contented that if someone else where to be modifying the code, they would at least need to know what those functions do. If they had no idea, they would most likey have no need to reorder those calls or insert calls inbetween them that would affect later calls. If that person does not understand that chunk of code, then they wouldn't be modifying it as their modifications wouldn't have anything to do with it, because that person would have an understanding of the modifications they are trying to accomplish.

This thread has been closed. You cannot post in this thread any longer.