Christopher Coale wrote: > nimak247 wrote: >> If I may ask a follow up question to what some of you mentioned: >> >> Several of you who replied seem to feel that you shouldn't use >> pointers in c++ anymore... Was this more of a statement about how >> everything is going managed code (frameworks like .Net, JVM, etc) vs >> native? Or did you mean that you should just use classes and pass them >> as objects? >> >> > If I can be honest, without the risk of being flamed by whoever said > that, do not listen to him about not using pointers in C++! Maybe he > meant for you to use references instead, but I still stand by my > statement. You have to be an absolute *idiot *to say that you shouldn't > use pointers in C++ (I'm talking to whoever originally said not to use > pointers in C++). Good luck trying to use any decent C++ API without > using pointers. ;)
I'm probably the most guilty party here. My view is that pointers are an _advanced topic_. It doesn't mean you shouldn't learn how to use them nor use them at all. They have their place. HOWEVER! Pointers are almost always taught too early in the process of learning C/C++. Most people are still learning the basic constructs of the language when pointers are taught. To have to learn the basic constructs (for loops, if-then-else, etc.) AND simultaneously learn an advanced topic such as pointers is too much for most people. In addition, C++ makes it entirely possible to write complete programs without using a single _obvious_ pointer anywhere in the application layer (i.e. anything requiring an _explicit_ dereference to access data). I consider passing-by-reference to still not really tread on pointer territory since you are guaranteed that an object is always passed at _compile-time_ (i.e. the compiler makes sure the object will be passed). Personally, I abuse temporary objects that allow me to avoid pointers within the main application layer. C++ makes it easy, the performance loss is _generally_ minimal and within acceptable tolerance, the code is MUCH more readable, AND I'm practically guaranteed to have a program free of crash bugs and memory leaks. The moment I start using pointers within the application layer is the moment I know I'm probably throwing the application's stability and maintainability out the window (usually in favor of performance but I very much prefer the first two). BTW, the application layer sits on the library layer. Any "C++ API" (usually a third-party library) will go in a layer I call the third-party layer, which is _below_ the library layer (I don't like third-party code). It will get wrapped up inside functionality in the library layer I write one time with an interface I want to use so I never have to deal with it again and the code will be solidly written in case of future use of that code. Then the application layer uses the library layer accordingly. Again, no obvious pointers at the application layer. As a result, I can read files, access databases, connect to remote websites and retrieve data, etc. without using a single direct/obvious pointer at the application layer in C++. This is why I say pointers are NOT necessary to create entire, powerful applications: Because I've done it before. Now those applications might not always perform spectacularly (temporary object abuse), but they get the job done. C++ makes it possible to defer teaching pointers until MUCH later on. -- Thomas Hruska CubicleSoft President Ph: 517-803-4197 *NEW* MyTaskFocus 1.1 Get on task. Stay on task. http://www.CubicleSoft.com/MyTaskFocus/
