Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Is pointer programming even necessary?

Reply
Thread Tools

Is pointer programming even necessary?

 
 
Danno
Guest
Posts: n/a
 
      03-31-2008
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?
 
Reply With Quote
 
 
 
 
Kai-Uwe Bux
Guest
Posts: n/a
 
      03-31-2008
Danno wrote:

> 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
 
Reply With Quote
 
 
 
 
Alf P. Steinbach
Guest
Posts: n/a
 
      03-31-2008
* 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

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
 
Reply With Quote
 
Juha Nieminen
Guest
Posts: n/a
 
      03-31-2008
Danno wrote:
> 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.
 
Reply With Quote
 
abir
Guest
Posts: n/a
 
      03-31-2008
On Mar 31, 6:30 pm, Juha Nieminen <(E-Mail Removed)> wrote:
> Danno wrote:
> > 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.


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
 
Reply With Quote
 
Alf P. Steinbach
Guest
Posts: n/a
 
      03-31-2008
* Juha Nieminen:
> Danno wrote:
>> 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.


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

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
 
Reply With Quote
 
Danno
Guest
Posts: n/a
 
      03-31-2008
On Mar 31, 2:01 am, "Alf P. Steinbach" <(E-Mail Removed)> wrote:
> * 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 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.

>
> > 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.


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.

>
> Cheers, & hth.,
>
> - Alf
>
> --
> A: Because it messes up the order in which people normally read text.
> Q: Why is it such a bad thing?
> A: Top-posting.
> Q: What is the most annoying thing on usenet and in e-mail?


 
Reply With Quote
 
Danno
Guest
Posts: n/a
 
      03-31-2008
On Mar 31, 1:07 am, Kai-Uwe Bux <(E-Mail Removed)> wrote:
> Danno wrote:
> > 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



Thanks for your help Kai.

 
Reply With Quote
 
Danno
Guest
Posts: n/a
 
      03-31-2008
On Mar 31, 7:30 am, Juha Nieminen <(E-Mail Removed)> wrote:
> Danno wrote:
> > 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.


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.






 
Reply With Quote
 
Danno
Guest
Posts: n/a
 
      03-31-2008
On Mar 31, 10:24 am, Danno <(E-Mail Removed)> wrote:
> On Mar 31, 7:30 am, Juha Nieminen <(E-Mail Removed)> wrote:
>
>
>
> > Danno wrote:
> > > 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.

>
> 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
CPU Usage frequently 100% even though it seems not even close tototal memory Newcomer Computer Support 3 11-15-2009 06:51 AM
CPU Usage frequently 100% even though it seems not even close tototal memory Newcomer Computer Support 0 11-14-2009 11:21 PM
Why my working ps/2 mouse freezes and even don't even get recon.after reboot ? demi General Computer Support 0 08-03-2007 05:30 AM
Why my working ps/2 mouse freezes and even don't even get recon.after reboot ? demi General Computer Support 0 08-03-2007 05:28 AM
Even older fart, even newer newbie Stan Goodman Java 11 07-04-2003 07:32 AM



Advertisments