Monday, July 31, 2017

The Little Lesson of C++ Horrors

Dear readers, it is a particular pleasure to welcome you, or welcome you back, with another of those so called 'Chapter Summaries'. I was very interested in the topic of this chapter, because this is the heart and soul of almost any program or game: They interact with files in one way or other. When starting out with it, I was also curious as to which Challenges this chapter would offer me, and how challenging the Programming Challenges would be.

Well, as it soon turned out, the Challenges in this chapter would be very difficult to solve. In some few cases it was an endless chain of errors, mistakes, bad design decisions, numerous - 'Oh, no ... PLEASE ... I do not want to start over again ...' moments. This was in part due to the nature of the problems to be solved, but also mainly due to a heatwave so temperatures would be as high as 39°C. At some occasions I didn't even manage to write a single blog-post, asking for apology for making a mistake, or giving an explanation as to why I had to delete an already submitted code, without constantly trying to write 9.5 instead of 12.5 or 9.6 instead of 12.6. It was so bad that it has taken almost 10 minutes to get it right.

But the real horror would wait for me until the final moments before uploading the code written for Programming Challenge 12.16. Imagine this, all there was left to do was to switch some parts of code around, I was watching Полина Гагарина - Кукушка (OST Битва за Севастополь) over at youtube at that moment, (Polina Gagarina - Cuckoo (OST Battle for Sevastopol))


A moment later a BSOD would appear on my screen, and the PC restarts. The IDE was open, the progress wasn't saved, and when the reboot process was complete, and the IDE re-opened, guess what happened? A dialog appeared asking whether the project should be restored. Of course, restore it for me Visual Studio, go ahead, do! Then my heart stopped, as instead of having the code last saved 10 minutes or so ago before the BSOD happened, a text-file opened. An empty text-file. All work was gone, hours and hours of work wasted? No, lucky me, I was wise enough to upload some backups setting me back an hour or so, so not much was lost. Still it hurt. 

Trying to solve the main problem of this challenge, which was to find a way to delete a record from a file, working hours upon hours to make code 'look good', to make it 'feel right', then this? Also this should be one of the best programs after all the disaster of code I uploaded for some of the Challenges before that ... It just wasn't right. 

Even though I'm not altogether happy, as I think many of the codes could have been more polished, more complete, better written, more sophisticated than they are, not all about this lesson and its Challenges was all bad. For instance the  Inventory Program Challenge. Even though I had to change the code and re-upload it, it was probably one of the ones I most enjoyed solving. Themed around Perry Rhodan, which some of my German and Austrian visitors might be familiar with, makes it something special, or more personal than it would otherwise have been.

Anyway, I got past all the challenges, one in particular with the help of a dreamincode.com member, who was so very kind as to provide a complete code example I was able to draw inspiration from. I've been very lucky to receive so much input, and the patience of that particular community member. All the others I had to overcome by myself. Something I can be a little proud of. 

So, what comes next? Of course! Another lesson! But there is more to come than just a lesson about Classes in C++ to come. I will probably make a switch from the 8E version of Starting out With C++ From Control Structures through Objects to 9E which I bought half a month ago. The main difference will probably be in the number of Programming Challenges to be solved, and of course the lessons themselves have been updated in numerous spots. Speaking of which, since there are some new Challenges to be found in the earlier chapters, I will solve those and upload the result. 

Now it is time to take a little rest. As always I would like all those among you who found the way to this humble blog a great time, and I hope you found what you came here looking for. To my fellow learners, I hope you'll soon be able to finish this lesson if you haven't already, without to much horror and trouble lying in wait for you ... As for me, I will be back soon, with more code, more horror-stories, and probably more gray hair on my head than I am able to count.

No comments:

Post a Comment