Skip to content

Commit d7d5105

Browse files
minor edits and proofreading
1 parent c015960 commit d7d5105

20 files changed

+232
-268
lines changed

00_foreword.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ code is reduced to its essential function,
5050
as opposed to traditional black-box layering
5151
which merely hides information.
5252
Programs written this way also tend to be fast,
53-
which contributes to its reusability.
53+
which contributes to their reusability.
5454
If a component doesn't perform,
5555
there will always be some performance-sensitive application
5656
that can't use it.
@@ -145,7 +145,7 @@ this presentation will probably be difficult
145145
to follow.
146146
Try the first lesson.
147147

148-
**How similar is Alex's vision to the "modern C++" style?**
148+
**How similar is Alex's vision to the "modern C++" style?**
149149

150150
The emphasis on value types and templates over dynamically allocated
151151
objects with virtual members is similar,

01_data_structures.md

+17-18
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
## Reflections on Trusting Trust
55

66
[Ken Thompson][ken] did many wonderful things. Probably more
7-
than any programmer, he influenced the programming style which we have right
7+
than any programmer, he influenced the programming style which we have right
88
now. While he did not invent C, that was done by his friend [Dennis Ritchie][dennis],
99
he invented the programming style which underlies C.
1010
Dealing with pointers,
@@ -18,7 +18,7 @@ have to be abolished[^hoare-speech].
1818
The idea was that pointer is illegitimate thing.
1919
Language designers were fully convinced that
2020
even if you provide pointers nobody should call them pointers.
21-
They would call them something like [access types][access-types].
21+
They would call them something like [access types][access-types].
2222
They have to prohibit iterations, like you could never subtract pointers.
2323
[Niklaus Wirth][wirth], the designer of Pascal, was very certain that you should never allow
2424
subtraction between pointers.
@@ -40,7 +40,7 @@ So Ken made them practical[^minsky].
4040

4141
Then he did UNIX, this totally brilliant operating system on which we all rely.
4242
All of our livelihoods come from Ken, in one shape or form.
43-
Do you remember the [fortune cookie program][fortune]?
43+
Do you remember the [fortune cookie program][fortune]?
4444
One of the fortune cookies was: "it is all Ken's fault"[^fortune-quote].
4545
We have to remember that.
4646

@@ -50,7 +50,7 @@ Mind it, at that point as far as I know he
5050
barely knew the moves.
5151
There was total dominance by Russian chess playing
5252
program [Kaissa][russia-chess] and two or three years he builds this specialized hardware,
53-
totally revolutionizes the approach to just playing.
53+
totally revolutionizes the approach to just playing.
5454
Of course nobody remembers
5555
what Kaissa was.
5656
He is a guy who could enter in a
@@ -68,7 +68,7 @@ years of their collaboration not once they would attempt to do the same thing.
6868
They had this good sense to work on complementary things.
6969
Except once.
7070
Both of them needed to write an assembly program with about
71-
20 lines of code and continues Ken, "I checked it was character by character
71+
20 lines of code and continues Ken, "I checked, it was character by character
7272
identical".
7373
It sounds like mystical thing right, two people coming together,
7474
this is a Vulcan mind-meld (joke).
@@ -94,10 +94,10 @@ Imagine how wonderful it would be if you could understand what someone else wrot
9494

9595
[^fortune-quote]: I have been unable to find any reference to this quote.
9696
Some older fortune files
97-
such as [this file][plan-9-fortune] from plan-9 contain similar quotes,
97+
such as [this file][plan-9-fortune] from plan-9 contain similar quotes,
9898
such as "Maybe I should have screwed up"
9999

100-
[^dennis]: Alex: In my opinion Dennis wasn' at genius like Ken,
100+
[^dennis]: Alex: In my opinion Dennis wasn't a genius like Ken,
101101
but obviously first class.
102102

103103
[^teaching-programming]: Alex: At Stanford there's one guy who knows, but he's an emeritus (Donald Knuth).
@@ -141,7 +141,7 @@ Part of what I am trying to do here is to start discussing
141141
little things like, how do we name variables?
142142
Why is it important? We want to get to the point where
143143
everybody writes a consistent code, recognizable code.
144-
This is why I'm I want to go slow and develop so that we
144+
This is why I want to go slow and develop so that we
145145
all agree[^conventions].
146146

147147
We have to start with a very very simple program. Most of you recognize it, right? [Hello World][hello-world].
@@ -268,18 +268,17 @@ That is a lot.
268268
One possible algorithm is using a lookup table.
269269
For example, one could allocate an array with `2^32` entries and count how many times integers are found only once.
270270

271-
272-
[^big-oh]: To say a function `f` is `O(g)` it's only required that `f` be bounded
273-
by a constant multiple for all inputs beyond some point.
271+
[^big-oh]: To say a function `f` is `O(g)` it's only required that `f` be bounded
272+
by a constant multiple for all inputs beyond some point.
274273
Formally, if `f(x) <= Ag(x)` for all `x > M`, where `A` and `M` are constant real numbers
275274
(see "The Art of Computer Programming" 1.2.11).
276275

277276
Alex will tend to say "order of" to distinguish `O(f)` from exactly `f`.
278277
In this section, Alex is observing that there is no requirement for `A` to be small.
279278

280279
[^headers]: Alex: You didn't use to need `#include <set>` when I first did STL.
281-
I had one gigantic a file called `stl.h`
282-
At that time people said it's utterly unacceptable to twenty thousand lines of code.
280+
I had one gigantic file called `stl.h`
281+
At that time people said it's utterly unacceptable, you have twenty thousand lines of code.
283282
If you think about it nowadays it appears to be very funny. Twenty thousand is nothing.
284283
That's why `stl.h` was replaced with a gazillion little headers.
285284
Sometimes I have no idea what they are.
@@ -289,7 +288,7 @@ That is a lot.
289288
Some of you think it was a great language.
290289
They carefully designed a bunch of algorithms which work on arbitrary sequences
291290
and one of the algorithms was called [`remove-duplicates`][clhs-duplicates] and it relied on equality.
292-
It actually would go through `N` times rremoving things.
291+
It actually would go through `N` times removing things.
293292
They did not sort.
294293
They use equality.
295294
It did work and it worked exceptionally well for most of the applications.
@@ -365,15 +364,15 @@ Miracles are not possible.
365364
If you ask somebody to create a very
366365
complex data structure that's what you're going to get.
367366
You're going to get problems with node allocation.
368-
You are going to problems with rebalancing.
367+
You are going to get problems with rebalancing.
369368
You're going to get problem with whatever these advanced data
370369
structures do.
371370
These problems are going to get worse and worse.
372371
You're going to get a [cache miss][cache] on every step through the set.
373372

374-
As our computers become faster, faster, and faster they're getting slower and
373+
As our computers become faster and faster and faster they're getting slower and
375374
slower and slower[^slower].
376-
Meaning that going to the main memory is very slow.
375+
Meaning that going to the main memory is very slow.
377376
You want to have locality of reference. You want all your
378377
data that you are working on in the local cache. If you have a huge set or map it's not
379378
going to be like that.
@@ -407,7 +406,7 @@ You need a `set` only if you need a thing which does not move things around.
407406
As long as something gets into a `set` and it is not erased the pointer, it is fixed.
408407
For example, him sitting in this chair is in the `set`.
409408
As long as he's in this set he will not move from his chair.
410-
You could find him constant time.
409+
You could find him in constant time.
411410
It's a very useful thing except most people do not use set for that.
412411

413412
[^slower]: This performance description is based on several trends in computer architecture.

02_regular_types.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ You might think you can just put any type in a map,
7979
but actually there are requirements on the type,
8080
certain properties which are required for these containers to function.
8181

82-
Let, us think about what my task was when I started working on the C++ STL.
82+
Let us think about what my task was when I started working on the C++ STL.
8383
It was to define standard data structures which will work for any reasonable subset of types.
8484
What is a reasonable subset of types?
8585
This is a little bit tricky but it's of paramount importance.
@@ -93,7 +93,7 @@ even more important than `int`.
9393
It has to work for pointer.
9494

9595
To understand all this, we're going to become a little bit theoretical.
96-
None of this stuff actually works unless you understand at least a
96+
None of this stuff actually works unless you understand at least a
9797
little bit of theory.
9898
We will call such reasonable types `Regular`.
9999
What we will do is formally define a set of operators that all `Regular` types must have,
@@ -221,7 +221,7 @@ a copy, the original and the copy are equal.
221221
`!=` should always behave like: `!(a == b)`.
222222
My very strong point is that the semantics of
223223
inequality (`!=`) is absolutely and totally bound to the semantics of equality (`==`).
224-
You should not even be able to have a situation where they have different semantics.
224+
You should not even be able to have a situation where they have different semantics.
225225
But, the standards committee disagrees with me on that.
226226
They say that you could have equality be equality and
227227
inequality be multiplication operator.
@@ -237,7 +237,7 @@ So even the paradigm of a member is the wrong paradigm.
237237
They are symmetric.
238238

239239
[^smart-pointers]: This is likely a reference to how [`std::shared_ptr`][cpp-shared-ptr] behaves
240-
which provides a form of automatic memory management.,
240+
which provides a form of automatic memory management.
241241

242242
## Total orderings
243243

@@ -255,7 +255,7 @@ to `TotallyOrdered`.
255255

256256
`<` must obey the following [mathematical properties][total-order]:
257257

258-
**Axiom 1:** Anti-reflexive: `!(a < a)`
258+
**Axiom 1:** Anti-reflexive: `!(a < a)`.
259259

260260
**Axiom 2:** Transitive: If `a < b` and `b < c` then `a < c`.
261261

@@ -265,15 +265,15 @@ to `TotallyOrdered`.
265265

266266
In the same way that the semantics of `==` is related to `!=`,
267267
we can see the semantics of `<` must be totally bound to the semantics of equality.
268-
But furthermore, `<` is related to four other operations which must also be defined:
268+
But furthermore, `<` is related to three other operations which must also be defined:
269269

270270
1. `<` less than
271271
2. `>` greater than
272272
3. `<=` less than or equal to
273273
4. `>=` greater than or equal to
274274

275275
If you provide them then they have to have natural meaning.
276-
For example, `!(a < b)` should be `a >= b` otherwise the world
276+
For example, `!(a < b)` should be `a >= b` otherwise the world
277277
perishes.
278278

279279
Later we will talk more about orderings, and define several different

03_singleton.md

+12-15
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
## Learning C++ isn't as hard as it appears
55

66
I talked to someone and he said "I have been programming in C++ for about eight years, but I never learned C++".
7-
That is a very common thing.
7+
That is a very common thing.
88
He was just honestly admitting something which happens to be the case for most people.
99
Most of us never learn programming languages.
1010
I never learned C++ I was just very
@@ -71,7 +71,7 @@ Why do I need template? Because we want to write something which takes one type
7171
another type.
7272
Let's forget C++ for a second.
7373
Mathematically speaking we want to write a type function: a thing which takes a type in
74-
and generates new types.
74+
and generates new types.
7575
The `template` is the mechanism in C++ for doing just that.
7676

7777
There are of course other type functions, even type functions in C.
@@ -135,7 +135,7 @@ There is no reason to write to it before you first deallocate.
135135
Another way to think about it is to help preserve an invariant.
136136
There is some condition we need to assure that the values cannot change.
137137

138-
For `singleton`, we pick struct because it's less typing.
138+
For `singleton`, we pick `struct` because it's less typing.
139139
*We should find the most minimal way of saying what we want to say*.
140140

141141
[^communist]: Alex: Don't be so eager with making members of classes private.
@@ -280,10 +280,10 @@ I am showing you how you could program differently.
280280
If you program in an object-oriented way then many good things might happen.
281281
I don't know what they are but you are not going to be efficient.
282282
Bjarne used to joke that object
283-
oriented systems are those that slow graphics.
283+
oriented systems are those that have slow graphics.
284284

285285
As time progresses, `++` is getting faster and faster and virtual function is getting slower and slower.
286-
Their spread is growing and we're not going to address
286+
Their spread is growing and we're not going to address
287287
any parts of C++ in this course which slow the computations.
288288

289289
If you want to learn about virtual I'm sure there are lots
@@ -395,7 +395,6 @@ They were not copyable and you couldn't pass them as arguments.
395395
Then they fixed it.
396396
They said, "we'll just copy the bits" and things would work.
397397

398-
399398
Equality is defined for all built-in types; `int`, `double`, `short`, `char`, pointers, etc.
400399
So, if you have a struct, why can't you generate an equality that uses those?
401400
Two things are equal if all their members are equal.
@@ -404,7 +403,7 @@ It's a sensible rule a compiler could do.
404403
I never managed to ask Dennis Ritchie about it.
405404
But, I asked probably the second best person on the subject, [Steve Johnson][johnson], because
406405
he actually implemented all these assignments for structures and things like that.
407-
Steve told me, "it was very hard because the bits in the padding might not be equal.
406+
Steve told me, "it was very hard because the bits in the padding might not be equal.
408407
If you compare bit by bit things which have equal members, but not equal bits in the padding, it will not work"[^padding].
409408

410409
But, why should you compare bit by bit?
@@ -506,13 +505,12 @@ but expect nothing from them.
506505
Understand how all the other operators are defined in terms of `<`.
507506
Contemplate it.
508507
It's really important.
509-
It is mathematics, but that's mathematics every programmer should be able to do .
508+
It is mathematics, but that's mathematics every programmer should be able to do.
510509

511510
[ip-quote]: https://en.wikipedia.org/wiki/Robustness_principle
512511

513512
### Specifying concepts
514513

515-
516514
Now let's talk about what kind of type `T` could be.
517515
Because we implemented all these operators,
518516
`T` could be `SemiRegular`, `Regular`, or `TotallyOrdered`.
@@ -529,7 +527,6 @@ In `singleton` we add a comment to describe this:
529527
It's a good example of a **disjunctive concept**.
530528
`T` could be any of them.
531529

532-
533530
You might wonder how `==` will work, if you plug-in only a type `T`
534531
which is only `SemiRegular`.
535532
In C++, things don't have to be defined unless they are used.
@@ -569,8 +566,7 @@ Why did these Bell Labs guys introduce such a thing?
569566
Were they mad?
570567
It was because they were lazy.
571568
They couldn't do it elegantly because they didn't
572-
have
573-
[function overloading][overloading].
569+
have [function overloading][overloading].
574570

575571
In C++ we have `sqrt(int)`, `sqrt(double)`, etc
576572
You can pass `int`, or `double` and it does the right thing.
@@ -620,10 +616,10 @@ But, it did.
620616

621617
`std::cin` is convertible to a pointer.
622618
If it fails, it returns `null` with type `void*`.
623-
Since it is convertible to a pointer, you can apply one
619+
Since it is convertible to a pointer, you can apply one
624620
more conversion and convert this pointer to a Boolean.
625621
Then you could convert it to an integer.
626-
So `std::cin` becomes zero and you shifted by forty two positions.
622+
So `std::cin` becomes zero and you shifted by forty-two positions.
627623
Isn't that beautiful (joke)?
628624

629625
The problem is they fixed this problem by
@@ -634,8 +630,9 @@ So they had to break the rule.
634630
Explicit conversions are not going to be called implicitly, unless
635631
they are in `while`, `if`, and other conditions which people used for input streams.
636632
So, the entire type system is screwed up (technical term), to work around some
633+
ancient design feature.
637634
The end of the story is avoid implicit conversions.
638-
Never rely on them it's impossible to avoid them.
635+
Never rely on them, it's impossible to avoid them.
639636
Even if you declare everything explicit there is still a
640637
context in C++ where implicit conversion will be done.
641638
You should never rely on one type

0 commit comments

Comments
 (0)