Velocity Reviews - Computer Hardware Reviews

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

Reply
Thread Tools

Is pointer programming even necessary?

 
 
Alf P. Steinbach
Guest
Posts: n/a
 
      03-31-2008
* http://www.velocityreviews.com/forums/(E-Mail Removed):
> On Mar 31, 12:56 pm, Danno <(E-Mail Removed)> wrote:
>> On Mar 31, 10:45 am, "Alf P. Steinbach" <(E-Mail Removed)> wrote:

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

>
> 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, to mix metaphors, I can sometimes, quite unintentionally, due to the
optimized connection from brain to mouth, or in this case, fingers, be an
elephant in a glasshouse.

I just hope as few as possible take that as serious attempts at offense.

It would ruin my earlier reputation (in some Norwegian "frustration"-groups) as
Master Of Offense (MOO(TM)).


Cheers,

- Alf
 
Reply With Quote
 
 
 
 
James Kanze
Guest
Posts: n/a
 
      04-01-2008
On Mar 31, 10: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 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.


At a lower level. In practice, even in C++ (at least at the
application level), I tend to pretend that it doesn't exist, and
think of expressions like a[i] much as I would in Java.

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


Yep, but that's the compiler writers problem, not mine.

Like you, I don't really understand the question, since I tend
to use pointers (and thus "pointer logic") a lot more in Java
than I do in C++. My impression is he's got it backwards, that
you have to concern yourself with "pointer logic" (e.g.
reference semantics, new, etc.) a lot more in Java, even when
logically, the problem doesn't call for it (e.g. an array of
complex).

--
James Kanze (GABI Software) email:(E-Mail Removed)
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
 
Reply With Quote
 
 
 
 
James Kanze
Guest
Posts: n/a
 
      04-01-2008
On Mar 31, 3: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.


I don't know about Ruby, but I know that this sort of thing is
no problem with Java---for most everyday jobs like this, in
fact, the Java collections library (and especially the concept
of iterators in Java) is far superior to the STL.

--
James Kanze (GABI Software) email:(E-Mail Removed)
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

 
Reply With Quote
 
Juha Nieminen
Guest
Posts: n/a
 
      04-01-2008
abir wrote:
> Why not? Java can


I don't believe you can use the same function to sort an array of
integers and, for example, an array of strings.

And by "array" I mean the [] type array, and by "integer" I mean
integer, not some class.
 
Reply With Quote
 
Juha Nieminen
Guest
Posts: n/a
 
      04-01-2008
Danno wrote:
> Sure you can..All iterators in java are generic.


Show me the code that sorts an array of integers and, for example, an
array of strings in Java. And "array" means the [] arrays and "integer"
means integer, not some class.
 
Reply With Quote
 
Juha Nieminen
Guest
Posts: n/a
 
      04-01-2008
James Kanze wrote:
> I don't know about Ruby, but I know that this sort of thing is
> no problem with Java


How exactly does it succeed in doing that? AFAIK Java generics do not
support basic types, such as integers and floats, nor can you create
pointers to arrays.

If Java generics have added support for basic types and creating
iterators from arrays lately then I stand corrected.
 
Reply With Quote
 
James Kanze
Guest
Posts: n/a
 
      04-01-2008
On Apr 1, 1:26 pm, Juha Nieminen <(E-Mail Removed)> wrote:
> James Kanze wrote:
> > I don't know about Ruby, but I know that this sort of thing is
> > no problem with Java


> How exactly does it succeed in doing that? AFAIK Java generics
> do not support basic types, such as integers and floats,


That's a different problem. The "basic types" in Java are
second class citizens, and you can't have collections of them
without boxing. (I've not kept up to date with Java, but
logically, the generic stuff they added should handle automatic
boxing.) It's a problem with the basic language, not with the
Java collections.

--
James Kanze (GABI Software) email:(E-Mail Removed)
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
 
Reply With Quote
 
Danno
Guest
Posts: n/a
 
      04-01-2008
On Apr 1, 5:26 am, Juha Nieminen <(E-Mail Removed)> wrote:
> James Kanze wrote:
> > I don't know about Ruby, but I know that this sort of thing is
> > no problem with Java

>
> How exactly does it succeed in doing that? AFAIK Java generics do not
> support basic types, such as integers and floats, nor can you create
> pointers to arrays.


Well, it is a C++ group, but why not.

You can most definitely use generics with integers and floats, and
with autoboxing it's a breeze.

List<Integer> list = new ArrayList<Integer>();
list.add(1);
list.add(5);
......
List<Float> list2 = new ArrayList<Float>();
list2.add(1.5f);
list2.add(5.4f);

Pointers to arrays is......is.....well, let me describe with code.

Since object variables hold object references and not object values.

int[] values = new int[10];

values is actually referencing the array

therefore..

values2 = values;
values2[3] = 4;
assert values[3] == 4; //true




>
> If Java generics have added support for basic types and creating
> iterators from arrays lately then I stand corrected.




 
Reply With Quote
 
Danno
Guest
Posts: n/a
 
      04-01-2008
On Apr 1, 10:20 am, Juha Nieminen <(E-Mail Removed)> wrote:
> James Kanze wrote:
> > That's a different problem. The "basic types" in Java are
> > second class citizens, and you can't have collections of them
> > without boxing. (I've not kept up to date with Java, but
> > logically, the generic stuff they added should handle automatic
> > boxing.) It's a problem with the basic language, not with the
> > Java collections.

>
> Hence the answer to the question "is pointer programming even
> necessary?". Maybe not absolutely necessary, but allows doing things
> like this.


I got my answer. I forgot that in C++, object variables hold object
values. Pointers and references are not handled for you in C++ like
they are in java and ruby.
 
Reply With Quote
 
Juha Nieminen
Guest
Posts: n/a
 
      04-01-2008
James Kanze wrote:
> That's a different problem. The "basic types" in Java are
> second class citizens, and you can't have collections of them
> without boxing. (I've not kept up to date with Java, but
> logically, the generic stuff they added should handle automatic
> boxing.) It's a problem with the basic language, not with the
> Java collections.


Hence the answer to the question "is pointer programming even
necessary?". Maybe not absolutely necessary, but allows doing things
like this.
 
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