Quote:
|
Originally Posted by Soulstorm
Although you can write most programs without the use of pointers, They will tend to be larger in size than otherwise.
|
Rubbish. If you're referring to size of source code do do something specific in a particular language, the most common driver of program size is programming technique (i.e. if you use poor tools for the job at hand, your source code tends to bloat as you need to implement lots of workarounds). If you're referring to size of an executable file, and we ignore tricks such as breaking programs into pieces using run time libraries, the dominant contributors of executable size are programming technique (again) and the quality of implementation of compilers and linkers. In fact, several modern compilers optimise for execution
speed by default and achieve this even if it means a larger executable file.
Quote:
|
Originally Posted by Soulstorm
Alsom without pointers, you can't proceed into understanding polymorphism in C++.
|
Sure you can. The following implements polymorphic behaviour, but there is no pointer anywhere in the code;
#include <iostream>
class Person
{
public:
virtual void Speak() = 0;
};
class Australian : public Person
{
public:
void Speak() {std::cout << "G'Day\n";};
};
class German : public Person
{
public:
void Speak() {std::cout << "Guten Tag\n";};
};
void Talk(Person &person)
{
person.Speak(); // this line exhibits polyporphic behaviour
}
int main()
{
Australian aussie;
German german;
Talk(aussie);
Talk(german);
} And, no, references are not pointers.
Quote:
|
Originally Posted by Soulstorm
Although errors with pointers will give you the creeps at first, it is an essential part of C++ programming. And do not forget that the only reason that a thing like this exists, is to facilitate the work of programmmers, and not make it more difficult than it already is. So, as you understand, you will become more efficient if you use pointers and references.
|
In this, I sort of agree with you but have some quibbles.
Understanding pointers is more essential in C than it is in C++. Not because pointers are necessarily a good thing (or not), but because C programmers tend to use them a lot. One of the purposes of the C++ standard library is to provide access to techniques that don't involve use of pointers. I suspect that one of the most common reasons pointers are used in C++ code is because C idioms are being employed (i.e. C++ is often used as "C with extensions").
Pointers are a language feature and, like any feature of a programming language, have their place. They are also a feature of C and C++ that are very easily misused, and also one of the features that are associated with many urban myths. One of those urban myths is that pointers make either programmers or programs more efficient (by any measure). In fact, the opposite is probably closer to being true in practice: pointers are so easy to misuse that they introduce inefficiencies (eg programmer [or, worse, customer] time to track down a pointer error, workarounds in code to cope with poor usage of pointers by other code, etc etc)
Quote:
|
Originally Posted by Soulstorm
Finally, without pointers, you will really have no luck if you intend to proceed into learning Objective-C (not that you said that you intend to, but just saying...  )
Everyone sees it as a difficult part of C++ at first, and that is proved by the numbers of tutorials and threads on pointers on the internet. But don't let that intimidate you...
|
Not having a lot of exposure to Objective-C, I won't respond to the first.
The reason that pointers are seen as a difficult part of C++ is that C++ is rarely the first programming language that people learn. And most languages that people learn before C++ (or C, for that matter) either do not support pointers
at all or (if they support pointers) do not support language features such as pointer arithmetic. Which means that, when learning C/C++, there are several concepts related to pointers that are new to everyone. And new concepts are among the most challenging things to learn: it is easier to learn different ways of applying something than it is to learn a new concept (one reason why a lot of people learn by "hands-on" practice).