Velocity Reviews - Computer Hardware Reviews

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

Reply
Thread Tools

Is pointer programming even necessary?

 
 
Juha Nieminen
Guest
Posts: n/a
 
      04-01-2008
Danno wrote:
> You can most definitely use generics with integers and floats, and
> with autoboxing it's a breeze.
>
> List<Integer> list = new ArrayList<Integer>();


That's not an integer. That's a class.

> List<Float> list2 = new ArrayList<Float>();


Neither is that a float, but also a class.
 
Reply With Quote
 
 
 
 
Danno
Guest
Posts: n/a
 
      04-01-2008
On Apr 1, 12:07 pm, Juha Nieminen <(E-Mail Removed)> wrote:
> Danno wrote:
> > You can most definitely use generics with integers and floats, and
> > with autoboxing it's a breeze.

>
> > List<Integer> list = new ArrayList<Integer>();

>
> That's not an integer. That's a class.
>
> > List<Float> list2 = new ArrayList<Float>();

>
> Neither is that a float, but also a class.


Ooops should've caps on the Integers and Floats. That is right.
There are no generics for 'primitive' types, but with the autoboxing
between the primitive and objects you can still use the generic
collection type.
 
Reply With Quote
 
 
 
 
James Kanze
Guest
Posts: n/a
 
      04-02-2008
On Apr 1, 6:20 pm, 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 don't see the relationship.

Formally, in C++, an expression like a[i] involves pointer
arithmetic (or more often, an overloaded operator).
Practically, at the application level, you should probably
program as if it were a true indexing operator (i.e. as it is in
Java), and forget that pointer arithmetic even exists. In fact,
at the application level, it should be fairly rare to use
something like a[i] except with an overloaded [] (in which case,
formally, it's a function call, not pointer arithmetic).

Obviously, if you're implementing something like std::vector<>,
you'll probably need to deal with pointer arithmetic. Just as
you would if you were implementing the array operations in a
JVM. But you don't usually need to do so, and if you do, you're
doing something that you cannot do at all in Java, so the
comparison doesn't apply.

More generally, of course, pointer programming (as opposed to
just pointer arithmetic) is essential in both languages: in C++,
any time you have an object whose lifetime doesn't correspond to
a scope, or an object for which the number or types of
sub-objects isn't know until runtime, and in Java, any time you
have an object (or an array, since arrays are also objects).
The most characteristic operator involved in pointer
programming is the new operator, and my experience is that I use
it a lot more often in Java than in C++.

--
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
 
ppi
Guest
Posts: n/a
 
      04-07-2008
On Mar 31, 2:38 am, Danno <(E-Mail Removed)> 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?


Yep they are

They are not necessary or wanted (at least with their C/C++ meaning)
in Java, ruby and other languages with automatic memory management or
garbage collection since they provide you with a raw handle to memory.
In these languages such abstraction is not necessary (or wanted) and
does not fit with the other languages abstraction provided to you.
But with languages like C and C++, you do manage the memory yourself
(deterministic memory management: you know when memory is freed),
pointers are mandatory and natural since they are abstraction provided
by these languages to access this memory (pointers arithmetics are
just a consequence of that: to iterate through memory).

They are still necessary and probably will always be there, lurking in
the corners. In Java almost everything is pointer/reference and we do
manipulate them every time we access/use objects.
People tend to think that pointers == self memory management, but no
this is no the case. This is due to the extensive use of C and
assembly (where they are a natural abstraction), so when one talk
about pointers, they think of pointers the way they are used/defined
in these languages.
C/C++ provide the programmer with all operations you would expect on
pointers: referencing (access), arithmetic (iterators operation), life-
time (you create/destroy their associated content)
On dynamic languages, Java etc. you are always provided with pointers,
but only with the referencing part, other uses are out of your reach.

On a more practical point of view, every memory intensive application
is best programmed using pointers (as used in C/C++) because you can
map the life-time of your objects directly to memory (once again this
is just because they are in that case the best abstraction for this
purpose).

So yeah, do not expect them to go away anytime soon

hope it will help,
-- paulo
 
Reply With Quote
 
Danno
Guest
Posts: n/a
 
      04-08-2008
On Apr 7, 8:21 am, ppi <(E-Mail Removed)> wrote:
> On Mar 31, 2:38 am, Danno <(E-Mail Removed)> 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?

>
> Yep they are
>
> They are not necessary or wanted (at least with their C/C++ meaning)
> in Java, ruby and other languages with automatic memory management or
> garbage collection since they provide you with a raw handle to memory.
> In these languages such abstraction is not necessary (or wanted) and
> does not fit with the other languages abstraction provided to you.
> But with languages like C and C++, you do manage the memory yourself
> (deterministic memory management: you know when memory is freed),
> pointers are mandatory and natural since they are abstraction provided
> by these languages to access this memory (pointers arithmetics are
> just a consequence of that: to iterate through memory).
>
> They are still necessary and probably will always be there, lurking in
> the corners. In Java almost everything is pointer/reference and we do
> manipulate them every time we access/use objects.
> People tend to think that pointers == self memory management, but no
> this is no the case. This is due to the extensive use of C and
> assembly (where they are a natural abstraction), so when one talk
> about pointers, they think of pointers the way they are used/defined
> in these languages.
> C/C++ provide the programmer with all operations you would expect on
> pointers: referencing (access), arithmetic (iterators operation), life-
> time (you create/destroy their associated content)
> On dynamic languages, Java etc. you are always provided with pointers,
> but only with the referencing part, other uses are out of your reach.
>
> On a more practical point of view, every memory intensive application
> is best programmed using pointers (as used in C/C++) because you can
> map the life-time of your objects directly to memory (once again this
> is just because they are in that case the best abstraction for this
> purpose).
>
> So yeah, do not expect them to go away anytime soon
>
> hope it will help,
> -- paulo


Five star response, Thanks.
 
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