Re: 2D array of pointers

From: Chris \( Val \) (chrisval_at_bigpond.com.au)
Date: 04/06/04


Date: Wed, 7 Apr 2004 00:19:19 +1000


"Leor Zolman" <leor@bdsoft.com> wrote in message
news:kvq270djmjncb650e3s1b8m1ea25i99gpp@4ax.com...
| On Tue, 6 Apr 2004 00:16:27 +1000, "Chris \( Val \)"
| <chrisval@bigpond.com.au> wrote:
|
| >
| >"Leor Zolman" <leor@bdsoft.com> wrote in message
| >news:b040701820osoi325f2j969nd3vmbi2dt6@4ax.com...
| >| On Sun, 4 Apr 2004 23:23:47 +1000, "Chris \( Val \)"
| >| <chrisval@bigpond.com.au> wrote:

Hi Leor.

| >| >You know you should be using vectors Leor :-).
| >| >
| >| > std::vector<std::vector<Node*> >
| >| > TwoD( n, std::vector<Node*>( n ) );
| >| >
| >| >Cheers.
| >| >Chris Val
| >|
| >| I swear, Chris, I can't tell for sure if you're being serious or not, even
| >| with the smiley.
| >
|
| Hi Chris,
| Before I respond, let me assure you I wasn't "offended" in the least, I
| just didn't understand what you were trying to tell me. Your elaborate
| post below certainly helps me to know where you're coming from.

Excellent - I'm glad you were not offended, although I
initially thought you were :-).

| I just happen to have a slightly "older school" view of the role of the
| STL; the weighting of the factors that contribute to choosing between the
| use of built-in arrays and vectors is probably slanted more toward arrays
| for me than it is for those who "grew up" with the STL. I'm open to
| persuasion, though, or at least gradual shifting of the weights...

Sure, I understand that - Now I have to work on my
persuasion skills :-).

| >After all, it’s not like you have never suggested the
| >use of a vector over a plain ol array before is it ?
|
| I probably have, but I know I've never suggested a "2D" vector such as the
| one you wrote above. I fully concede that there may be folks to whom this
| kind of thing has now become an everyday idiom, but I'm not yet among them.

Sure, that's fine, and I guess it is not easy to change
the way one has been programming for a long time, but
there can be much satisfaction to be gained, particularly
when your job can be made easier.

| >| The entire "use a vector instead of an array" thing is
| >| encroaching upon Religious Issue status;
| >

| >Would you put the same argument forward, that the OP was
| >asking about gets(), and that we should respect that, and
| >not offer an alternative ? I very much doubt it.
|
| Well, gets is a bit easier to discard from your programming
| repertoire than arrays are.

To someone who understands the consequences, yes, but to
a newbie - no, an array can be placed in the exact same
category. Newbie's(and even some seasoned programmers),
can easily overlook and overwrite memory they don't own :-).

What I'm trying to say, is that vectors abstract this danger
away from the programmer to a much greater degree than what
a plain ol array can, essentially allowing the programmer to
write programs more robustly, than that of using arrays.

| >I’m really trying hard to understand why you posted such a
| >response ? - Maybe I should change my name to 'Scott' to
| >avoid such responses <g>.
|
| "Scott"? I don't get it...

Don't worry, it was my poor attempt at humour <g>.

| anyway, my visceral response to your vector definition
| was horror, so I really wanted to know where you were
| coming from.

That's why I thought you were upset with my response.

| Again, at this point I think you know I respect and appreciate your
| contributions to the newsgroups, so I recognized there was something here I
| personally need to get a handle on and took the initiative to begin getting
| it.

Oh, gee thanks - Likewise to you :-).
I always enjoy reading your posts.

| >I have posted here on many occasions(with my primary intent
| >to help people as much as my knowledge allows), and I have
| >myself been advised many times over to use vectors over arrays
| >in almost every circumstance, where I have posted a solution
| >using raw pointers for example – This is fair game, and at the
| >end of the day, it is only helping the OP to learn from other
| >methodologies or tools available within the framework of C++.
| >
| >| if someone posts a C++ question
| >| employing arrays, even when vectors would /clearly/ represent a more robust
| >| and intuitive implementation (the latter from /our/ perspective, not
| >| necessarily the OP's), how do you know the OP doesn't have a perfectly good
| >| reason for choosing the array over the vector?
| >
| >Well, I’m glad you agree, that the vector solution is far
| >superior –
|
| Well, at this point I'd certainly still choose a 2D array over a nested
| vector for fixed-size dimensions. For dynamic dimensions the case for
| vectors is a whole lot stronger, but not necessarily a foregone conclusion
| yet (at least not to me. But let's not get into a debate on that in this
| thread.)

:-).

[snip]

| I guess a big dilemma for me is my reluctance to take questions at too much
| beyond face value, even though this would be the one group where giving
| "extra" information would, as you've pointed out, be the most likely to be
| appreciated. I'm personally an "incremental" learner; I do best when
| focusing on one thing at one time. If I ask a question about something, I
| appreciate when the answer is to the question I've asked. It's not that I
| wouldn't appreciate suggestions regarding alternate approaches to the
| problem, but I'd be confused if there weren't a clear delineation made
| between the direct answer to my question and the rest of it. Where we
| perhaps disagree is how the array/vector dichotomy (or is it one?) fits
| into this picture.

Yes, I can understand this point of view to an extent,
but in the spirit of public newsgroups, there is almost
always another alternative presented - if not me, then
surely someone else.

At the conclusion of any thread, the OP(s) usually have
a smorgasbord to choose from <g>.

[snip]

| >As far as assumptions go though, there was really none
| >on my part – I merely pointed out an alternative to the
| >OP, whilst at the same time(hoping you would understand
| >what the smiley was there for), querying why you did not
| >offer such a solution ?.
|
| Well, this exchange right here will probably have an effect on how I answer
| similar questions in the future, although I can't predict at this point
| precisely what that effect might be ;-)

Cool, I'll lock in adaptors for next week :-).

| >| For someone (you?) going in with
| >| the attitude that "wherever an array is being used, a vector would be
| >| better", the baseline assumption set may be different than mine. So be
| >| it...
| >
| >Well this is just a matter of opinion(and an assumption
| >on your part really :-))
|
| Hey, I /did/ put the question mark in there, didn't I? ;-)

Oh, yeah <g>.

[snip]

| >Having said that, you also know very well that in C++,
| >vectors are always recommended over plain ol arrays,
| >purely for the advantages they offer over and above a
| >standard array, and I’m sure if I go through the google
| >archives, I will *certainly* find your name right along
| >side this kind of advice.
|
| I very much doubt you'll find me saying "vectors are always recommended
| over arrays", because such a thought had never even crossed my little
| Luddite mind, AFAICR.

Well, that's not exactly the words I hoped you were
looking at. I was suggesting more along the lines of:
  "this kind of advice".

Should I check :-).

| >Usenet is a very difficult place to express your feelings
| >given it's textual nature, and sometimes things are not as
| >they seem.
|
| No disagreement there!
|
| >
| >Having said that, I’m sorry if you feel in some way offended
| >by my response to you(I can assure you, that it was not my
| >intention to offend you or anyone else for that matter),
|
| Of course not, and none taken. Again: I really needed to
| know where you were coming from.

Good, I'm glad I didn't offend you.

[snip]

| > Lastly, the sooner we make people aware of the available
| > alternatives(and the modern approaches to programming with
| > the C++ Standard Library), the less often we'll end up
| > seeing badly formatted(and correcting), poorly written code.
|
| And I shouldn't complain; it would mean more people would have
| good reason to be using STLFilt ;-)

It might also mean that you could eventually work on some
code written by others, that is much easier to maintain,
by slowly eradicating old habits, and instilling new
ones into upcoming programmers :-).

Cheers.
Chris Val



Relevant Pages

  • Re: newbie: capabilities of c++ in numerical computation
    ... >>1) Does object oriented programming introduce significant overhead as ... I personnaly think that arrays of doubles are better at low ... fortran or c library routines from your code. ... >>calling fftwlibraries? ...
    (comp.lang.cpp)
  • Re: Overloaded Methods called with null
    ... The rules are not for general programming, per se, but ... NullPointerExceptions are obtuse to the Java newbie, I agree, but the ... Using Lists instead of arrays and initializing arrays with ...
    (comp.lang.java.programmer)
  • Re: How do *you* use arrays?
    ... I too am quite conservative David, but it seems my conservitism manifests ... The fact is, as you mentioned, all computing is based on arrays at some ... > Designing a course of instruction is similar to designing a ... >> the fundamental concept of arrays in a GENERALIZED and BASIC programming ...
    (microsoft.public.access.modulesdaovba)
  • Re: Structured Coding
    ... concepts (such as arrays and strings). ... I only have my own "learning" experience to base my ... Programming C# assumes some experience with a related language ...
    (comp.lang.cobol)
  • Re: How do *you* use arrays?
    ... I am a professional developer, and I was a professional teacher ... Designing a course of instruction is similar to designing a ... > the fundamental concept of arrays in a GENERALIZED and BASIC programming ...
    (microsoft.public.access.modulesdaovba)