I decided to read a Herbert Schildt book I had (C/C++ Programmer's Reference) and made me realize that the books we need to avoid may still be worth reading. For example, I have read several books, but never seen this in any of them until I read that book:
1 2 3 4 5 6 7 8 9 10 11
#include <iostream>
usingnamespace std;
int main()
{
for (int a = 1, b = 20; a <= 20; a++, b--)
{
cout << a << " : " << b << endl;
}
return 0;
}
Yes this is a pointless thread, but I'm bored and can't think of anything to code :P.
Nothing, but it lends to the fact that even crappy "avoid at all costs" books are worth a read. So many books push the for(int a = 1; a <= 20; a++){for(int b = 20; b >= 1; b--){}} that none ever cover other possible ways of doing it. That is the point of my post, just saying no matter how bad a book is, it still can point out interesting things that are good as they point out what can be done as well as make obvious what shouldn't be done.
Your first example isn't another way of doing what your second example does. They don't do the same thing at all. The first one runs 20 times, the second one runs 400 times.
for(int i = 1; 1 <= 20; ++i) {
std::cout << i << " : " << ( 21 - i ) << std::endl;
}
You can expect to see my book on shelves in 3 years. Thank you.
As seen above this example is reliant only on one variable so it would redundant to use a second for loop. I actually don't see how you can do this using 2 for loops tbh.
So yah this: for(int a = 1; a <= 20; a++){for(int b = 20; b >= 1; b--){}} won't give you the same output.
Never said the output was the same. I should have been more accurate. Books push for(;;){} and for(;;){for(;;){}} but have never showed it was possible to put more than the normal single variable, evaluation, and action in every for loop.
The for(int a = 1; a <= 20; a++){for(int b = 20; b >= 1; b--){}} was just to stress the singe initialization (int a = 1 or int b = 20), single evaluation (a <= 20 or b >= 1), and the single action (a++ or b++). Never meant to imply they did the same.
Everyone has a different definition of good books so it is impossible to ever answer that question. I know a few programmers who got started by reading the SAMS Teach Yourself series and consider them good books. Some consider anything by Bjarne to be terrible. Cprogramming.com has a list of books that allegedly get you from beginner to expert, yet I've seen some on this site say to avoid most of them. I consider them all good as they are all great ways of learning both good and bad ways to do things and how to recognize both ways. So according to my definition, no I haven't read all the good books as I don't have the money to buy them all.
#include <string.h>
/* reverse: reverse string s in place */
void reverse(char s[])
{
int c, i, j;
for (i = 0, j = strlen(s)-1; i < j; i++, j--) {
c = s[i];
s[i] = s[j];
s[j] = c;
}
}
My comment was rhetorical; it was based on your statement:
I decided to read a Herbert Schildt book I had (C/C++ Programmer's Reference) and made me realize that the books we need to avoid may still be worth reading.
About 6 years ago I read one of Mr. Schildt's books for Java, it was a horrible book, but it was useful for me, because it got me (as a complete non-programmer) over my initial fears; and showed me that I could eventually master the skill of programming and teach myself. In my opinion that is all his books are good for (helping complete noobs get over their fears), as soon as they are read they should be thrown away and not used again.
Why it may be useful for complete noobs to read a Dummies book, a SAMS book, or one of Mr. Schildt's books--anyone with even modest experience is wasting their time because there is a plethora of good books available. And I was surprised among experience programmers at the amount of agreement there is on what books are worth reading.
Please don't take offense because no offense was intended.
Rhetorical questions and sarcasm are hard to gauge on the net. Sadly, good or not, too many books will help you get into programming, but once you are done you can only program simple applications and not a whole lot more. There are only two good books I have that are recommended by most programmers and sites: The C++ Programming Language Special Edition and Optimizing C++ otherwise the other books are just ones I bought looking for something to make me not feel so lost when I program.
Schaum's out lines Programming with C++ is amazing. Give it a shot. I'm fond of this series. Not only in programming but with other stuff like math and physics. I wonder why they stopped publishing more in new programming languages like C#.
I learned from the tutorial on this site and by actually, you know, programming. A good habit you should get into is copying every piece of code you see and understanding how it works. Also, never copy and paste code if you're trying to learn about it. Always write it out manually (you can copy and paste it into your text editor and then write it out though).
This. So many people get stuck up just reading about new concepts and asking questions "Will X work if I supply Y?" when all they need to do is actually program and figure out for themselves. Only way to learn IMO.
You can't really start programming without reading something, but yeah, you can't learn it just by reading about it. Like any skill, you have to actually practice it.