473,567 Members | 3,011 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Accelerated C++: [1,rows] Not so fast

I've finally gotten around to reading Accelerated C++ by Andrew Koenig and
Barbara Moo. There's a lot of good stuff in what I've read so far. Even
though it is _very_ basic, they present some concepts I have not
encountered elsewhere, or explain ones I have encountered in ways that add
to my understanding. There are a few points of style with which I take
issue, such as not consistently using braces around the body of an if or
loop, etc.

There is one point, however, I have to take exception too. They assert that
"...the number of elements in [0, rows) is obvious(i.e., rows -0, or rows)
but the number of elements in [1,rows[ is less so." If you agree with
these authors, please turn off the computer and reflect for a moment on
your preschool and kindergarden years. Hold up your hand and look at your
fingers. Remember? "One", "two", "three".... ? ;-)
--
"If our hypothesis is about anything and not about some one or more
particular things, then our deductions constitute mathematics. Thus
mathematics may be defined as the subject in which we never know what we
are talking about, nor whether what we are saying is true." - Bertrand
Russell

Jul 22 '05 #1
27 1929
"Steven T. Hatton" <su******@setid ava.kushan.aa> wrote in message
news:Xf******** ************@sp eakeasy.net...
There is one point, however, I have to take exception too. They assert
that
"...the number of elements in [0, rows) is obvious(i.e., rows -0, or rows)
but the number of elements in [1,rows[ is less so." If you agree with
these authors, please turn off the computer and reflect for a moment on
your preschool and kindergarden years. Hold up your hand and look at your
fingers. Remember? "One", "two", "three".... ? ;-)


Indeed -- People form bad habits early.

If you are in the habit of representing ranges by storing the first and last
element of the range, our experience from years of teaching is that you are
much more likely to run into trouble than you are if you form the habit of
representing ranges by storing the first and one past the last element.

Moreover, once you graduate from ranges of integers to ranges of iterators,
you no longer have a choice in the matter, because there is no way to
represent an empty range if you insist on referring to the last element
rather than one past the last.
Jul 22 '05 #2
Andrew Koenig wrote:

fingers. Remember? "One", "two", "three".... ? ;-)


Indeed -- People form bad habits early.

If you are in the habit of representing ranges by storing the first and
last element of the range, our experience from years of teaching is that
you are much more likely to run into trouble than you are if you form the
habit of representing ranges by storing the first and one past the last
element.

Moreover, once you graduate from ranges of integers to ranges of
iterators, you no longer have a choice in the matter, because there is no
way to represent an empty range if you insist on referring to the last
element rather than one past the last.


I don't disagree with what you're saying. I've never thought about the issue
from that perspective. I simply accepted that C and hence C++ works that
way because it's more consistent with the hardware representation. I know
I can get pretty disoriented if I start working with Mathematica after a
long period of exclusively working with C++. Mathematica starts indexing
at 1, sort of. The zeroth element of a List is 'List'.

I was really commenting on the impact that counting from 0 has on our
thinking. I worked with vectors an matrices for years in mathematics
before I started working with computers. Now the idea of indexing from 1
seems a bit foreign. I sometimes wonder if mathematics will every recover
from computer science.
--
"If our hypothesis is about anything and not about some one or more
particular things, then our deductions constitute mathematics. Thus
mathematics may be defined as the subject in which we never know what we
are talking about, nor whether what we are saying is true." - Bertrand
Russell

Jul 22 '05 #3
"Steven T. Hatton" <su******@setid ava.kushan.aa> wrote in message
news:Xf******** ************@sp eakeasy.net...
I've finally gotten around to reading Accelerated C++ by Andrew Koenig and
Barbara Moo. There's a lot of good stuff in what I've read so far. Even
though it is _very_ basic, they present some concepts I have not
encountered elsewhere, or explain ones I have encountered in ways that add
to my understanding.


One comment that I've come across many times is that it's hard going for
beginners, i.e., not basic enough, though I don't know what level it's
aimed at. I have not actually read it. The bookshops here don't have it.
They prefer to stock "Learn C++ in 30 seconds", or whatever it's called.

DW

Jul 22 '05 #4
"Steven T. Hatton" <su******@setid ava.kushan.aa> wrote in message
news:GO******** ************@sp eakeasy.net...

I've never thought about the issue
from that perspective. I simply accepted that C and hence C++ works that
way because it's more consistent with the hardware representation.


Neither have I. And I was quite impressed by the representation of an empty
range by [n, n). The book shows some fundametal but easy-to-ignore points.

--
ES Kim
Jul 22 '05 #5
"David White" <no@email.provi ded> wrote in message
news:lR******** *********@nasal .pacific.net.au ...
One comment that I've come across many times is that it's hard going for
beginners, i.e., not basic enough, though I don't know what level it's
aimed at. I have not actually read it. The bookshops here don't have it.
They prefer to stock "Learn C++ in 30 seconds", or whatever it's called.


Accelerated C++ covers more material in its 320 pages than many 1000-page
introductory books. It does so by not dwelling on unimportant details and
avoiding needless repetition. As a result, you have to read it thoroughly:
You can't just open it at random and expect that you'll be able to
understand whatever you see without first having read what precedes it.

On the other hand, if you do take the time to read it thoroughly, I believe
you will learn more in less time than if you were to use a more conventional
book. The reason is that one of its organizing principles is "Teach the
most useful ideas first." That is, at each point in the book, we present
the idea that we think will add the most to your programming skills beyond
what you have already learned up to that point.

Who is the intended audience? Someone who already has some programming
experience (not necessarily a lot), and who can figure out the mechanics of
writing and running C++ programs. I know that several people are using it
as textbooks in introductory college computer-science courses. It would
also be well suited for software developers who have never used C++ but who
have programmed in other languages.

I think it might even be useful for a complete novice, provided that there
was someone around to help as needed. I think it's a little steep for
self-study by a nonprogrammer.

Jul 22 '05 #6

"ES Kim" <no@spam.mail > wrote in message
news:cm******** **@news1.kornet .net...
"Steven T. Hatton" <su******@setid ava.kushan.aa> wrote in message
news:GO******** ************@sp eakeasy.net...

I've never thought about the issue
from that perspective. I simply accepted that C and hence C++ works that
way because it's more consistent with the hardware representation.


Neither have I. And I was quite impressed by the representation of an
empty
range by [n, n). The book shows some fundametal but easy-to-ignore points.


I find that notation to be rather silly. Something more like [] would be
better, in my opinion, except that of course we're dealing with takng that
representation and applying it to something real (assuming you can call C++
"real" :-)).
What does [n,n) mean, if translated into everyday language? It's the range
of integers starting at and including n, up to but NOT including n. Umm...
what??? The first part says to include n, and the second says to not
include n. Very weird.
It's obvious, as a programer, how that representation can be implemented in,
for example, a for loop. But it's no different, really, from saying
something like [100,-5]. That's just as "emtpy" as [n,n), isn't it?

Just my $0.02 (and as valueless as that is).

-Howard
Jul 22 '05 #7
Howard wrote:

"ES Kim" <no@spam.mail > wrote in message
news:cm******** **@news1.kornet .net...
"Steven T. Hatton" <su******@setid ava.kushan.aa> wrote in message
news:GO******** ************@sp eakeasy.net...

I've never thought about the issue
from that perspective. I simply accepted that C and hence C++ works
that way because it's more consistent with the hardware representation.


Neither have I. And I was quite impressed by the representation of an
empty
range by [n, n). The book shows some fundametal but easy-to-ignore
points.


I find that notation to be rather silly. Something more like [] would be
better, in my opinion, except that of course we're dealing with takng that
representation and applying it to something real (assuming you can call
C++ "real" :-)).
What does [n,n) mean, if translated into everyday language? It's the
range
of integers starting at and including n, up to but NOT including n.
Umm...
what??? The first part says to include n, and the second says to not
include n. Very weird.
It's obvious, as a programer, how that representation can be implemented
in,
for example, a for loop. But it's no different, really, from saying
something like [100,-5]. That's just as "emtpy" as [n,n), isn't it?

Just my $0.02 (and as valueless as that is).

-Howard


It's really standard mathematical notation for a set. There's nothing novel
to me in the notation itself. What I found a bit amusing was the idea that
it is easier to determine the number of elements in the set {0,1,2,...,n-1}
than in the set {1,2,3,...,n}.
--
"If our hypothesis is about anything and not about some one or more
particular things, then our deductions constitute mathematics. Thus
mathematics may be defined as the subject in which we never know what we
are talking about, nor whether what we are saying is true." - Bertrand
Russell

Jul 22 '05 #8
Andrew Koenig wrote:
I think it might even be useful for a complete novice, provided that there
was someone around to help as needed. I think it's a little steep for
self-study by a nonprogrammer.


I'm finding that it is fairly 'self-contained'. That is, it makes very few
assumptions about prior programming knowledge, and presents every necessary
concept as appropriate. Though it presents the material at a basic level,
it doesn't condescend to the reader. It also presents - as I previously
indicated - some ideas I haven't encountered elsewhere. I'm certainly
getting more from the book than simply a review of the material covered in
TC++PL(SE).

I suspect the hardest part of working through the book for a person with
little programming experience would be the challenge of figuring out the
mechanics of working with the particular implementation. IDE's can add a
lot of distracting content to even the simplest of programs, and the
g++(for example) command line interface is not what I would call intuitive.

Of course they could use Emacs... :o vi? My own opinion is that a person
would be well served by fetching Cygwin - or installing an operating system
- and learning to work with their compiler from the command line. I'd
suggest TextPad (ShareWare) as an editor if they are restricted to a
Windows environment.

One advantage I got from using KDevelop when I started programming in C++ is
that it created my header/source file pairs in a useful way.
--
"If our hypothesis is about anything and not about some one or more
particular things, then our deductions constitute mathematics. Thus
mathematics may be defined as the subject in which we never know what we
are talking about, nor whether what we are saying is true." - Bertrand
Russell

Jul 22 '05 #9
"Howard" <al*****@hotmai l.com> wrote in message
news:8d******** ***********@bgt nsc05-news.ops.worldn et.att.net...
I find that notation to be rather silly. Something more like [] would be
better, in my opinion, except that of course we're dealing with takng that
representation and applying it to something real (assuming you can call
C++ "real" :-)).
What does [n,n) mean, if translated into everyday language? It's the
range of integers starting at and including n, up to but NOT including n.
Umm... what??? The first part says to include n, and the second says to
not include n. Very weird.
The notation has many years of usage in mathematics. I didn't invent it.
It's obvious, as a programer, how that representation can be implemented
in, for example, a for loop. But it's no different, really, from saying
something like [100,-5]. That's just as "emtpy" as [n,n), isn't it?


Yes it is. However, the number of elements in [m,n) is n-m; the number of
elements in [m,n] is n+1-m (assuming zero in both cases if the count is
negative). The "+1" is the source of untold off-by-one errors in programs.
Jul 22 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2353
by: Simon Wittber | last post by:
LGT is a lightweight wrapper over pygame and PyOpenGL which simplifies 2D sprite creation, translation, scaling, rotation and animation for those of us who want a higher level abstraction of OpenGL and the graphics hardware. Features include: * Any dimension texture loading * Sprite strip based animated sprites * Constant co-ordinate...
0
1431
by: Magic1812 | last post by:
Magic Software invites you to join us this coming Tuesday (January 13th, 2004) at 12:00 EDT / 17:00 GMT for a FREE live Webinar: Title: Accelerated Application Integration and Information Sharing Date: January 13, 2004 Time: 12:00 PM EST / 17:00 GMT Presenter: Lee Sutton
0
1513
by: Magic1812 | last post by:
Magic Software invites you to join us this coming Tuesday (January 13th, 2004) at 12:00 EDT / 17:00 GMT for a FREE live Webinar: Title: Accelerated Application Integration and Information Sharing Date: January 13, 2004 Time: 12:00 PM EST / 17:00 GMT Presenter: Lee Sutton
17
2139
by: Joe Van Dyk | last post by:
This is my answer to problem 5-10 from Accelerated C++. I'd appreciate any comments (regarding style, efficiency, standards, etc) you fellows have. The resulting program seems reasonably fast, searching through a dictionary of 300,000+ words in 3 seconds on my PowerBook G4. // Write a program that finds all the palindromes in a...
2
1746
by: Adam | last post by:
In my MYISAM table I have an index (Index_A) on 2 fields (Field_A, Field_B). There are millions of rows in the table. The cardinality of Index_A is 53. I think a query to count the number of rows that match a pair of values for Field_A and Field_B should execute blindingly fast (in the index count the number of leaf nodes for the B-Tree node...
7
12050
by: Egor Shipovalov | last post by:
I'm implementing paging through search results using cursors. Is there a better way to know total number of rows under a cursor than running a separate COUNT(*) query? I think PostgreSQL is bound to know this number after the first FETCH, isn't it? On a side note, why queries using LIMIT are SO terribly slow, compared to cursors and...
5
24508
by: jeff | last post by:
i am using ms access as my database i can successfully delete a single record from a table using : targetRow.Delete() Try reportDataAdapter.Update(reportDataSet, "table1" ) reportDataSet.AcceptChanges() Catch ex As OleDbException reportCompanySitesDataSet.RejectChanges()
14
3080
by: Pete | last post by:
Is anyone familiar with this book? Exercise 6-1 of Accelerated C++ asks us to reimplement the frame() and hcat() operations using iterators. I've posted my answers below, but I'm wondering if I'm off track here. First of all, the book has been brisk but reasonable up to chapter 5, and then suddenly, it exploded. I had to grit my teeth...
2
3430
by: nekiv90 | last post by:
Greetings, How can 'rows read' from a DB2 CALL statement incur so many reads? I would expect it to be zero. Could someone enlighten me on this? Thanks! Here is output from executing event monitor on STATEMENTS: 68) Statement Event ...
0
7688
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7590
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7905
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8115
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7960
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5216
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
2093
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1205
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
930
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.