Is pointer programming even necessary?

D

Danno

I have decided that this year, I will refresh my C++ skills since they
are old and brittle. I have moved onto other languages over the past
10-15 years or so, and all the languages I have taken to don't have
the pointer logic associated with it (Java, Ruby, etc). I can't say
that I missed it. So my question is simple, is pointer programming
still viable or even necessary?
 
K

Kai-Uwe Bux

Danno said:
I have decided that this year, I will refresh my C++ skills since they
are old and brittle. I have moved onto other languages over the past
10-15 years or so, and all the languages I have taken to don't have
the pointer logic associated with it (Java, Ruby, etc). I can't say
that I missed it. So my question is simple, is pointer programming
still viable or even necessary?

If you are asking about C++ (which can be inferred since you are posting
here), then the answer is: Yes.

The standard library offers a nice collection of useful data structures. So,
you don't need explicit dynamic memory management anymore to use a doubly
linked list.

However, run-time polymorphism in C++ heavily relies on pointers. It is
really on the level of pointer and reference types where the "is-a"
relationship holds: if D derives from B, then the set of values for D* is a
subset of the set of values for B*. (The canonical map from the set of
values of type D to the set of values of type B is a projection not an
inclusion, and it goes by the name of slicing.) Since references cannot be
reseated, pointer still prove necessary at the very least in this context.

Of course, there are other reasons to use pointers: e.g., T* can be used
even for incomplete types, which sometimes makes it necessary to use T*
instead of T in the context of template programming.


Best

Kai-Uwe Bux
 
A

Alf P. Steinbach

* Danno:
I have decided that this year, I will refresh my C++ skills since they
are old and brittle. I have moved onto other languages over the past
10-15 years or so, and all the languages I have taken to don't have
the pointer logic associated with it (Java, Ruby, etc).

I think you mean "pointer arithmetic", because Java certainly have pointers.
Java reference values are pointers. They're called pointers by the Java
language definition (just consider what the heck you think a Java
NullPointerException is all about), and they act like pointers.

I can't say that I missed it.

Presumably, again, pointer arithmetic.

So my question is simple, is pointer programming
still viable or even necessary?

Presumably, again, pointer arithmetic.

Well, pointer arithmetic is necessary to build the foundations of languages such
as Java.

Any indexing operation or object field access reduces at a lower level to
pointer arithmetic.

It's incredible that you have programmed for 10-15 years and don't know this.

A good dose of assembler programming seems in order! :)


Cheers, & hth.,

- Alf
 
J

Juha Nieminen

Danno said:
I have decided that this year, I will refresh my C++ skills since they
are old and brittle. I have moved onto other languages over the past
10-15 years or so, and all the languages I have taken to don't have
the pointer logic associated with it (Java, Ruby, etc). I can't say
that I missed it. So my question is simple, is pointer programming
still viable or even necessary?

Do those languages offer the versatility of iterator-based generic
algorithms? Can you, for example, use the exact same function to sort an
array of integers and a double-ended queue of floats? Can you, for
example, use the exact same function to iterate through an array of
chars, a list of complex numbers or a balanced binary tree containing
your own type of objects, and have to function return the sum of all the
elements? Can you create your own innovative data container and have
those exact same functions perform those operations on it?

Ok, granted, I don't know if you can do that with Ruby. I know you
can't do that with Java.
 
A

abir

Do those languages offer the versatility of iterator-based generic
algorithms? Can you, for example, use the exact same function to sort an
array of integers and a double-ended queue of floats? Can you, for
example, use the exact same function to iterate through an array of
chars, a list of complex numbers or a balanced binary tree containing
your own type of objects, and have to function return the sum of all the
elements? Can you create your own innovative data container and have
those exact same functions perform those operations on it?

Ok, granted, I don't know if you can do that with Ruby. I know you
can't do that with Java.

Why not? Java can (Though i don't know why it is not in Arrays ) and
also ruby.
They both define iterator. However in java iterators are little
different than c++ , there is a single iterator to do the job, rather
than 2.
so where c++ iterators are like T* , java iterators are like C* (or c+
+ list kind of thing, or like intrusive containers ) or C& and
size_type index (for random access containers) .
So the abstraction level doesn't have any difference. However c++
defines them through traits, hence non intrusive while java defines
them as interface (Iterable, or a detailed JGL ). also Java and Ruby
can't access locations directly in memory, but rather uses arrays,
which is a language construct and implemented same way as c++ array
(apart from value type & primitive)

abir
 
A

Alf P. Steinbach

* Juha Nieminen:
Do those languages offer the versatility of iterator-based generic
algorithms? Can you, for example, use the exact same function to sort an
array of integers and a double-ended queue of floats? Can you, for
example, use the exact same function to iterate through an array of
chars, a list of complex numbers or a balanced binary tree containing
your own type of objects, and have to function return the sum of all the
elements? Can you create your own innovative data container and have
those exact same functions perform those operations on it?

Ok, granted, I don't know if you can do that with Ruby. I know you
can't do that with Java.

I think you're wrong. ;-)

Even if you meant to write "in a statically type safe way", well, Java has
generics, not as powerful as C++ templates but, without being familiar with
them, I'd think they'd be sufficient for that.

Put that "I know you can't do that" together with the OP's wrongness about
basics, and it gets really really wrong.


Cheers, & hth.,

- Alf
 
D

Danno

* Danno:


I think you mean "pointer arithmetic", because Java certainly have pointers.
Java reference values are pointers. They're called pointers by the Java
language definition (just consider what the heck you think a Java
NullPointerException is all about), and they act like pointers.

I was trying to be careful with the term, I did't think pointer
arithmetic was the best term. Pointer arithmetic is when you use
mathematical terms to manipulate the pointer (increment, decrement,
comparison). In C++ you can do that, but I used the general term
'pointer programming' so it can include pointer arithmetic as well as
merely setting the reference. But this exercise in semantics isn't
really my cause here.
Presumably, again, pointer arithmetic.


Presumably, again, pointer arithmetic.

Well, pointer arithmetic is necessary to build the foundations of languages such
as Java.

Any indexing operation or object field access reduces at a lower level to
pointer arithmetic.

It's incredible that you have programmed for 10-15 years and don't know this.

Whew, Damn it smells bad in here. That pomposity ought to be put
away.
A good dose of assembler programming seems in order! :)

A good dose of humility can work wonders too. ;)
 
D

Danno

If you are asking about C++ (which can be inferred since you are posting
here), then the answer is: Yes.

The standard library offers a nice collection of useful data structures. So,
you don't need explicit dynamic memory management anymore to use a doubly
linked list.

However, run-time polymorphism in C++ heavily relies on pointers. It is
really on the level of pointer and reference types where the "is-a"
relationship holds: if D derives from B, then the set of values for D* is a
subset of the set of values for B*. (The canonical map from the set of
values of type D to the set of values of type B is a projection not an
inclusion, and it goes by the name of slicing.) Since references cannot be
reseated, pointer still prove necessary at the very least in this context.

Of course, there are other reasons to use pointers: e.g., T* can be used
even for incomplete types, which sometimes makes it necessary to use T*
instead of T in the context of template programming.

Best

Kai-Uwe Bux


Thanks for your help Kai.
 
D

Danno

Do those languages offer the versatility of iterator-based generic
algorithms? Can you, for example, use the exact same function to sort an
array of integers and a double-ended queue of floats? Can you, for
example, use the exact same function to iterate through an array of
chars, a list of complex numbers or a balanced binary tree containing
your own type of objects, and have to function return the sum of all the
elements? Can you create your own innovative data container and have
those exact same functions perform those operations on it?

Ok, granted, I don't know if you can do that with Ruby. I know you
can't do that with Java.

Sure you can..All iterators in java are generic. Ruby is dynamic type
so you can use a Enumerable mixin (like an interface) to make that
object iterable. Then you can throw that to whatever you like since
you duck-typing is very lenient.
 
D

Danno

Sure you can..All iterators in java are generic. Ruby is dynamic type
so you can use a Enumerable mixin (like an interface) to make that
object iterable. Then you can throw that to whatever you like since
you duck-typing is very lenient.

Correction, they are generic as of 5.0. Sorry. I got used to use to
so much I always thought that they were there. ;)
 
D

Danno

Thanks for your help Kai.

Kai, I know where my problem came from.

In java and ruby, object variables hold object references. I forgot
in C++ that object variables hold object values. That means that
pointers are absolutely necessary.

Thanks again. That was the source of my confusion. ;)
 
A

Alf P. Steinbach

* Danno:
I was trying to be careful with the term, I did't think pointer
arithmetic was the best term.

It was, if that was what you were referring to.

You ended up being the opposite of careful.

Pointer arithmetic is when you use
mathematical terms to manipulate the pointer (increment, decrement,
comparison). In C++ you can do that, but I used the general term
'pointer programming' so it can include pointer arithmetic as well as
merely setting the reference.

Java does have pointers. What it lacks is pointer arithmetic, and the ability
to form pointers in other ways than via new.

But this exercise in semantics isn't
really my cause here.

It should be.

It would be a good idea to understand, at least to some rough approximation,
what you're attempting to ask about. :)


Cheers, & hth.,

- Alf
 
E

Erik Wikström

I have decided that this year, I will refresh my C++ skills since they
are old and brittle. I have moved onto other languages over the past
10-15 years or so, and all the languages I have taken to don't have
the pointer logic associated with it (Java, Ruby, etc). I can't say
that I missed it. So my question is simple, is pointer programming
still viable or even necessary?

Viable, most certainly!

Necessary? Not always, you can write quite a lot of programs these days
without having to play with pointers. On the other hand, if you do use
pointers you can much more with a lot less effort.
 
D

Danno

* Danno:



It was, if that was what you were referring to.

You ended up being the opposite of careful.


Java does have pointers. What it lacks is pointer arithmetic, and the ability
to form pointers in other ways than via new.


What???? You just implied that java has pointer arithmetic. haha

"I think you mean "pointer arithmetic", because Java certainly have
pointers.
Java reference values are pointers. They're called pointers by the
Java
language definition (just consider what the heck you think a Java
NullPointerException is all about), and they act like pointers."



It should be.

It would be a good idea to understand, at least to some rough approximation,
what you're attempting to ask about. :)


So I dusted off my Bjarne's C++ book and also referenced a few sites.
Found out, you have no idea what you are talking about.
I will just rely on the knowledgeable posters in this group. ;)

Thanks
 
D

Danno

Viable, most certainly!

Necessary? Not always, you can write quite a lot of programs these days
without having to play with pointers. On the other hand, if you do use
pointers you can much more with a lot less effort.

Thanks Erik.
 
L

lbonafide

So I dusted off my Bjarne's C++ book and also referenced a few sites.
Found out, you have no idea what you are talking about.
I will just rely on the knowledgeable posters in this group. ;)

Exactly what was it that Alf (who is indeed one of them most
knowledgeable and courteous posters on c.l.c++) wrote was disproved by
your few minutes of web surfing?

Where are all of these brash newbies coming from lately?
 
D

Danno

Exactly what was it that Alf (who is indeed one of them most
knowledgeable and courteous posters on c.l.c++) wrote was disproved by
your few minutes of web surfing?

Well, looking up 'Bjarne's C++ book' isn't necessarily web surfing,
although I did do some web research on pointer arithmetic as well.

Also, 'It's incredible that you have programmed for 10-15 years and
don't know this.' isn't what I would call courteous or welcoming.

I have found Kai's, Erik's, and Juha's responses very courteous and
what I needed and in return I was courteous.

Where are all of these brash newbies coming from lately?

I am sure, if some of the denizens of c.l.c++ were more apt to help
than to insult out of the OP, they may not be so "brash". I know this
is USENET, and you guys have your share of jerks and spam, but there
is no reason to assume that of everyone.
 
L

lbonafide

Also, 'It's incredible that you have programmed for 10-15 years and
don't know this.' isn't what I would call courteous or welcoming.

I have found Kai's, Erik's, and Juha's responses very courteous and
what I needed and in return I was courteous.


I am sure, if some of the denizens of c.l.c++ were more apt to help
than to insult out of the OP, they may not be so "brash". I know this
is USENET, and you guys have your share of jerks and spam, but there
is no reason to assume that of everyone.

I think you're taking this way too personally, and I don't consider
Alf's comment to be an insult, just his opinion. And AFAICT, nobody
accused your post of being spam or you being a jerk. I do think it's
evident that you haven't read much of this group before posting or
your opinion of Alf would be different perhaps.
 
D

Danno

I think you're taking this way too personally, and I don't consider
Alf's comment to be an insult, just his opinion.

You say that as if opinions and insults are exclusive.
And AFAICT, nobody
accused your post of being spam or you being a jerk.

Never said that anyone did... I said that members here probably have
their share of jerks and spam.
I do think it's
evident that you haven't read much of this group before posting or
your opinion of Alf would be different perhaps.

That's hopefully obvious from my original post ;). I did look for
other posts that may have an answer before posting.

I hope that Alf and some other users takes some of my advice and offer
up some civility and maybe some humility. There will always be a lot
of noobs and people who have a new projects where a little or a lot of
C++ is involved and/or will need a refresher. They may not be brash
but only reacting to how they are treated and/or welcomed in this
forum.

I also hope that if you and Alf ever find yourself in a forum of
another programming language (good to continually learn new
languages ;) ) that you get treated respectfully and professionally
like I how I was treated by you, Kai, Juha, and Erik on this thread.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top