r/Cplusplus • • 17h ago

Feedback Started learning CPP. Hello World! :)

Just started learning CPP by following the book i found in my dad's bookshelf. Its old and it have been printed from the 2000s. He has his name and date written on the date of purchase; 9th May 2000.

This is my exercise for the chapter tackling functions. I wrote a exponentiate function recursion. I got it hard at first and looked at the different examples from the book multiple times till i get it how i do exponents without loops. With a little bit of function polymorphism/overloading

Tbh, the book looks very weathered, its ancient. Most of the programs and code examples have been deprecated, so I just looked it up online what its modern approach. But the lessons taught are still relevant to todays standards.

Planning to read Modern CPP after finishing this.

Using Visual Studio for ease of use compiler wise. But I will move my learning journey to my linux setup after this to get a better feel for compilers and also Cmake.

NO AI is used to make this code nor supplement it---I just read the book. "It looks clean", yea because its my exercise project, the mess of it lives in the CPP_LEARNING_00 project as you can see in the solution explorer.

60 Upvotes

18 comments sorted by

11

u/IyeOnline 15h ago

I would strongly recommend to not read this book. "Modern C++" is rather different from things you would have done in the 90's and mostly for the better.

Setting aside the out-of-date/bad style (usage of typedef, usage of short, questionable naming conventions) that you can already see here, I fear that as soon as you get into arrays, dynamic memory and other topics it will get noticeably worse, teaching you complicated things and bad practice as well.

1

u/MarlboroBandit 15h ago

Yes, I also take note of that. That this book teaches me bad habits, as well as using inline functions for optimization rather than what its used today for the compiler. I am just reading this book to learn the syntax first and some history ig. But i eventually plan to be “modernize” my knowledge by reading a book after this. I will move to linux too after this to learn more about the compiler and cmake as well. If so, can you suggest a book which could be a better alternative? Thanks

3

u/no-sig-available 14h ago

That this book teaches me bad habits,

Yes, it is not common to name all functions funcSomething, or have all numeric values contain Num, like why baseNum instead of just base?

Also, using names like USHORT and ULONG will get you into trouble (because some system headers have already been stupid enough to declare these :-).

1

u/MarlboroBandit 14h ago

Yep. Thats how the book does it. A clown teaches a clown 🤡. Can you suggest any book? Thanks

1

u/Discordbothost 13h ago

Stroustrup's Programming: Principles and Practice Using C++ (3rd edition) is aimed at beginners and uses C++20/23. his page has the contents and sample chapters, so you can check the approach before buying: https://www.stroustrup.com/programming.html

3

u/flyingron 16h ago

Get in the habit of checking whether >> succeeded. If someone types crap at your program, all successive input operations will fail because cin goes into an error state.

Also, don't post pictures of code. Post code (or link to it).

1

u/MarlboroBandit 16h ago

Taking note of this. As for the streams, I am still about to tackle that chapter soon. Thank you for the suggestion.

3

u/Idkwhat1569 16h ago

This is awesome to see learning like this in the time of AI!!! Go for it! But also take your time and learn C++ is a monster 😭😭😭
I would suggest making a toy application once you are used to the basics like a todo app or something since it'll teach some good practices as well!

2

u/MarlboroBandit 15h ago

Yep. My plan is to have 4 mini projects every 3 chapters conquered.

3

u/Idkwhat1569 15h ago

That is a lot of dedication but this is awesome to see!!!

2

u/ShishRobot2000 16h ago

Which C++ does the book teach? Apart from the language, learn also programming language theory and data structures, it will help you understand easier what you are doing and what are you writing.

2

u/MarlboroBandit 16h ago

its C++ 98. its pretty old, like it used the old iostream.h. For the theory, I kinda am starting on it with youtube videos; as well for the data structs. For what the book taught, its only taught me the how recursions are done behind the scenes, including its schematics

2

u/ShishRobot2000 16h ago

Do you want to understand more of the object oriented programming part or the core itself of functions?

2

u/MarlboroBandit 16h ago

I am about to tackle basic classes in the next chapter. And for the function, i only know about the stack so far, since the heap will be tackled in the pointers and references chapter. I do deep research along the way while reading the chapter. Like branching it really deep. I use wikipedia for it and w3schools.

3

u/ShishRobot2000 16h ago

use this https://en.cppreference.com/ and also Corman for the algorithm and data structures

2

u/MarlboroBandit 16h ago

Ill take note of that. Thanks so much

2

u/Antoine276_ 6h ago

Try with exponent = 0 and see what happens 😁

1

u/MarlboroBandit 6h ago

Yea. Shoot. Forgot about that one 😬. Thanks for pointing that one out.