Re: trouble creating array of objects

From: Jumbo (pcrcutitout1000011_at_uko2.co.uk)
Date: 12/05/03


Date: Fri, 5 Dec 2003 14:10:23 -0000


"Gavin Deane" <deane_gavin@hotmail.com> wrote in message
news:6d8002d0.0312050433.2689328c@posting.google.com...
> "Jumbo" <pcrcutitout1000011@uko2.co.uk> wrote in message
news:<1070567051.579443@news.minx.net.uk>...
> > "Gavin Deane" <deane_gavin@hotmail.com> wrote in message
> > news:6d8002d0.0312041056.4bc555bf@posting.google.com...
> > > "Jumbo" <pcrcutitout1000011@uko2.co.uk> wrote in message
> > news:<1070456535.760343@news.minx.net.uk>...
> > > > "Gavin Deane" <deane_gavin@hotmail.com> wrote in message
> > > > news:6d8002d0.0312030426.6c2da3ce@posting.google.com...
> > > > > "Jumbo" <pcrcutitout1000011@uko2.co.uk> wrote in message
> > news:<1070368078.78862@news.minx.net.uk>...
> > > I'd also be interested to know _why_ efficiency is such a concern. If
> > > you personally enjoy the challenge of absolutely maximising runtime
> > > efficiency then that's obviously your choice. But that approach often
> > > won't be relevant to other people learning the language, unless they
> > > happen to be learning because they enjoy the same challenge.
> >
> > It's not so much that it is of so much concern it's more a point of
> > awareness.
> > I can appreciate the view that vectors are an ease to use I just don't
see
> > the point in introducing them unecessarily as this is their only benefit
(
> > ease of use ) and it does not give the person who is learning any more
> > understanding of dynamically allocated 2D Arrays.
>
> Depending on your objective, ease of use (including the fact that the
> library does not need to be re-debugged every time you use it) might
> be the most important criterion. Professionally, it almost always will
> be. How quickly you can write clear, maintainable, correct source code
> is what it's all about. Someone learning towards a career in
> programming would want to take that approach. Someone learning for any
> other reason could have completely different priorities. But a common
> desire is to spend as little as possible time debugging, by getting as
> much right in the first place. The standard library can help you do
> that.
Fair enough
>
> > > For someone learning C++ to program professionally, the sooner they
> > > understand that runtime efficiency should rarely be a major concern,
> > > the better off they will be. And many people programming as a hobby
> > > are more interested in getting correct programs up and running as
> > > quickly as possible, to get a feeling of making progress. For anyone
> > > falling into either of these groups, your argument about needing to
> > > know how a vector works simply doesn't apply. That is why people in
> > > this newsgroup are at pains to point out that your concerns about
> > > vectors (and the standard library in general) may well not translate
> > > to other people's requirements.
> >
> > You shouldn't be programming professionally if you are using STL without
> > understanding templates.
>
> I'm considering someone learning _towards_ a career in programming.
> Learning how to use of the library will be a priority, so I believe
> there is benefit in simply stating that you declare a vector of ints
> as vector<int> early on and leaving it at that. What the <int> syntax
> really means can come in a later lesson. How to write template classes
> (as well as how to declare and use dynamically allocated arrays and
> how to avoid shooting yourself in the foot with them) will come later
> still.

how can you shoot yourself in the foot with this?
int* intArray = new int[5];

>
> Even when you get your first programming job, there will hopefully be
> more experienced programmers around you. Your skills in using the
> library will be more immediately important than whether you are able
> to reimplement it if you choose to. If that does become necessary, the
> nature of the task means it will not be given to someone very junior
> and inexperienced without careful oversight and guidance. Modern
> commercial C++ (that's pure C++, not C++ "as a better C") programs do
> not often contain explicit arrays (multidimensional or otherwise).

Depends what you get a job as.
If you are programming for windows you might never use STL.

I don't know what your on about with 'modern commercial C++ deosn't contain
explicit arrays' can you please explain this?
>
> > And if your programming purely as an interest then there no need to get
> > involved with advanced STL classes whilst going through your learning
curve
> > until you have reached the point where you are ready to learn templates.
>
> Again, depending on your viewpoint and objectives, you could equally
> well argue that there is no immediate need to get involved with
> advanced explicit memory management and the issues that surround it,
> when the library provides a way to hide the detail and the problems
> from you and get your programs working quickly and easily.

Using pointers and new is not advanced memory management it's the language
basics.
You seem to think it's a good idea to hide the language basics surely this
is not a good way to learn.
Hiding anything isn't going to do anyone any favours.

>
> There is no need to think of the language and the library as separate
> entities. If a feature is implemented in the library rather than the
> language, that in now way implies that it is necessary to understand
> all the core language features used to implement that library feature
> before you use it. That's why the library was invented.

Why was the library invented?

> It's not just
> for experienced programmers, everyone can use it straight out of the
> box. And it allows to you program at a higher, more abstract level.

But what's the point in programming at a higher more abstract level when
your supposed to be learning the basics?
Why don't you just learn Java if that's what your looking for?

> You worry about the fact that you're trying to store and retrieve
> entries in a phone book for example, without being concerned about
> _how_ the computer actually does any of that. (OK maybe a list or a
> map might be more appropriate than a vector for a phone book, but I
> hope you get the idea).
The only idea I am getting is that you're saying that you want to learn C++
programming but you don't want to concern yourself with how the computer
does any of the processing?
>
> It takes experience (and the ability to use a profiler) to correctly
> identify those situations where the implementation of the standard
> library is not suitable for your needs. So there needn't be any hurry
> to teach how it works internally.

What's a profiler?
There's no hurry to use the STL at all. It's of no benefit in the learning
process.

>
> > I
> > say advanced template classes but I mean that the use of cout and cin
for
> > example is necessary to aid learning but they do not use explicit
template
> > initialisation, the moment you introduce explicit template
initialisation
> > syntax the programmer is going to want to understand what this is all
about,
> > otherwise they will be confused by it.
>
> I think you need to change "will be confused" to "might be confused".
Nope. Whether they think they are or not, they will be confused by this
syntax if they do not understand templates.

> Many people will be quite happy (or, at least, content enough to
> continue with the course) to be told "When you want a vector of ints,
> you write vector<int>. Why you do that is a bit complex, but we will
> be covering it later in the course. For now, you can just use it and
> it works". After all, they've probably already taken things like
> #include and using namespace std; on faith.

Yes but the only reason this is done with #include is so they can output
text to the screen.
And namespaces are fairly easy , you can fit that into the learning curve
any morning.
>
> > To learn from the ground up is conventional learning and works well why
> > change it ?
>
> Learning can be very different for different people. That is why
> teaching is so hard and a good teacher is invaluable.
>
Yup it can be difficult and there's a lot to fit in especially if your
learning from scratch.



Relevant Pages

  • Re: Cpp Considered Harmful
    ... you just parse the template and show the user code ... > that a tool, to be at all effective in modern programming, has to do near ... > much easier than they can parse the underlying language itself. ... > resulting from the preprocessor, it merely has to preprocess it. ...
    (comp.lang.cpp)
  • Re: Opinions on intro lisp books
    ... But Lisp is a little different, ... Some languages support one style of programming better than they ... Even if that weren't the case, I'm not sure that a language being a ... I don't believe that learning to program in CL requires more theory ...
    (comp.lang.lisp)
  • Re: Newbie (Followup)
    ... level language (as I believe I will end up learning more). ... know a little bit including the basics of pointers, ... Alas I am forced to learn a "language" that deviates from even the most basic principles of programming (from what I have seen so far/ ...
    (comp.lang.c)
  • Re: AspectJ: solution to Javas repetitiveness?
    ... The only real benefit of university in learning those languages ... Every language I have learned since I have learned ... fundamentals of good programming from a good teacher. ... Incidentally I am just teaching myself Ruby. ...
    (comp.lang.java.programmer)
  • Re: Newbie
    ... language (as I believe I will end up learning more). ... little bit including the basics of pointers, arrays,data ... my programming life changed dramatically! ...
    (comp.lang.c)