27:05 sorry for the nitpicking, but std::stack has the equivalent of your "peek", it's just named differently - "top". Sure, infiz uses raw pointer instead of reference as a return type, but you're modernising anyway 😅
That sent me through memory lane hahaha, VS6 was also my first C++ compiler acquired normally (I had a copy of some other compiler that someone gave me, couldnt manage to understand how to use it XD)
Even before you said Java out loud my brain had filled in the gap. I had a uni professor who taught Java before he taught C++, this code looks like something he would write. Memory leaks gallore in all the assignments because you weren't allowed to change his skeleton code.
Nice and you even kept it C++98! Creating pointers was so common back then. Did old C++ books even motivate when or when not to use pointers? I only remember pointers as a chapter in books. Best book I ever bought was Alexandrescu's Modern C++ Design. It truly was a game changer.
I certainly think that my initial C & C++ code, (started programming with these in early 2000s) heavily used pointers. When I got back to programming, 2019 time, I was surprised when reading up on heap vs stack that heap was preferred and faster than stack. I guess because C++ programming guides focused heavily on the use of pointers and all the dangers of using them that we kind of believed that we had to use pointers. Life is so much easier keeping everything on the stack.
This really brings me back to that time when I first started using C++. I too have a copy of VS6 from that time and one of the best features was having a local copy of MSDN. The first book I read on C++ didn't even mention templates since they weren't a standard language feature at that point. It was actually using templates and the STL, once they became a part of the standard, that convinced me to stick with C. I absolutely hated C++ for about a decade and a half, and it wasn't until seeing your videos and Rust that I started to like C++. While I don't use Windows anymore and would've used Vim to refactor this project, it was still a cool nostalgic trip seeing VS6 running.
I feel like I would've moved it to a modern platform before doing any of this refactoring. Also, core.autocrlf = false is the best setting. You don't need to mess with any .gitattributes files, checkout as-is, commit as-is, no weird CRLF mangling on windows. And man does this code need a formatting fix. I wish there were a universal opinionated formatter for c++ like there is with js with prettier/biome.
Nice! And you kept everything under VC6! I was wandering why you didn't use any auto for a while😅 A couple of things I would do differeny: - I would pass rational numbers by value all the time. It is just two int - I would use hidden friends for operator overloading (though maybe VC6 doesn't even support friend)
This is interesting, you could do elegant things in C++98 as well and you were not forced to new things then either, and memory leaks wasn't untraceable, that was just bad code. But newer C++ helps in so many areas. Yea I've been stuck in old 98 code for a while and have been able to improve a lot.
C++98 was THE NEW thing back in 1998. The whole code you wrote was cutting edge stuff anyways so not many people could even do it. What do you mean by it didn't force us to newer things?!
I was thinking the "having to maintain this project" would've meant you get to upgrade your tools and everything, but you're stuck to C++98. But now I get why application folders are so full of garbage. It's like two calculation function files and a main and it expanded to multiple folders with their own set of files and possibly copies.
You might not necessarily get to update your tools, but you might still have to maintain an old project. I wanted to show what is possible before upgrading your tools. I'll get back to the project at some point in the future and let the tools get upgraded.
I started with borland turbo c++ in i believe 95? I used borland up till 5.0 although I eventually switched to visual c++ 6 . I have projects from then that let me just say i cringe when i look at that code.
One technique for adding header guards to A.hpp without changing it, is to write B.hpp, a file with only two things, (1) header guards and (2) #include . Then, include only B in your test.
You can open them but you have to Migrate the project.. It won't compile anyway unless it's a very simple program. Guaranteed, there are problems. Then you will have to fix to get it to compile probably a lot
At 30:23 you ask yourself why you allocated a pointer to an int. The reason is that your old stack code held void *, so you needed a pointer to the heap not a pointer to a temporary on the stack. It's tough to follow all the things you do, because you move so fast, but I get it. Ya gotta keep us interested and a lot of this is just monkey work. ie any monkey at a keyboard could make these rote changes. Nice to see how far we have come though from "back in the days." My only other comment would be to add non existent copy constructors, assignment constructors and let the compiler show you where you are miss using the class, via the linker errors.
@39:23 why do you have 'break's after 'return's in 'switch' statements? You're doing a self-review before commit, which is a good practice (I wish some devs who I work with did it), but still you missed this obvious blunder. Also, I know how so many people with their "strong opinions" will come and tell me how I am wrong, but I think the first 'refactoring' thing that you should have done about this project, was to replace all tab-indents with space-indents. @39:55 lines 64 and 70 look just ridiculous. Not only they are indented poorly, but also use a mixture of tabs and spaces for indents. Ugh, yuck! 🤮
Hello, fellow space indentation user. Those are indeed tiny steps, and he could've done the first as a simple search and replace, which even VS6 had available. If it were me, I would've used Vim to refactor the project and downloaded a copy of gcc and checkout'd a period correct version. Then tabs to spaces would be an easy :%s/\t/ /g and done. But maybe that's just me that was thinking that.
@@anon_y_mousse tabs -> spaces is not as easy in this case, because a tab is such a 'unique' (by which I mean annoying) little character! 1 tab = 4/8/ constant spaces only when they appear at the beginning of the line (or are preceded by other tabs, that are at the beginning of the line). Otherwise, they just align at some tabstop interval, so can 'mean' anywhere from 1 to _n_ spaces (where _n_ is 4/8/ as mentioned above). VS60 did include the reformat feature, if memory serves, which would convert tabs to spaces (or vice versa) if the format style is configured to either use one or the other.
"NULL" is an undeclared identifier. That sure is something lmao
29:40 This is your brain on void* based polymorphism
would be nice to see the same codebase migrated to C++20
That is the next step
Actually 23 would be interesting.
Stay tuned!
C++ 11 is honestly all you need.
@@purpasmart_4831 all you need to get started :)
I would've been scared to submit this to github before fixing it first. Given all the memory leaks it could probably be classified as malware
leaks should be avoided but they are not dangerous
@@marcs9451but it sounds funny
27:05 sorry for the nitpicking, but std::stack has the equivalent of your "peek", it's just named differently - "top".
Sure, infiz uses raw pointer instead of reference as a return type, but you're modernising anyway 😅
Fair, but I also had my `pop` return the popped object, so it would have been one more thing to wrap/change.
That sent me through memory lane hahaha, VS6 was also my first C++ compiler acquired normally (I had a copy of some other compiler that someone gave me, couldnt manage to understand how to use it XD)
Even before you said Java out loud my brain had filled in the gap. I had a uni professor who taught Java before he taught C++, this code looks like something he would write. Memory leaks gallore in all the assignments because you weren't allowed to change his skeleton code.
Ugh
Great to see the code getting so much better, even in C++98! Can't wait for the next episode. Keep up the good work Jason. Regards, Niels.
Nice and you even kept it C++98!
Creating pointers was so common back then. Did old C++ books even motivate when or when not to use pointers?
I only remember pointers as a chapter in books. Best book I ever bought was Alexandrescu's Modern C++ Design. It truly was a game changer.
I certainly think that my initial C & C++ code, (started programming with these in early 2000s) heavily used pointers. When I got back to programming, 2019 time, I was surprised when reading up on heap vs stack that heap was preferred and faster than stack. I guess because C++ programming guides focused heavily on the use of pointers and all the dangers of using them that we kind of believed that we had to use pointers. Life is so much easier keeping everything on the stack.
This really brings me back to that time when I first started using C++. I too have a copy of VS6 from that time and one of the best features was having a local copy of MSDN. The first book I read on C++ didn't even mention templates since they weren't a standard language feature at that point. It was actually using templates and the STL, once they became a part of the standard, that convinced me to stick with C. I absolutely hated C++ for about a decade and a half, and it wasn't until seeing your videos and Rust that I started to like C++. While I don't use Windows anymore and would've used Vim to refactor this project, it was still a cool nostalgic trip seeing VS6 running.
I like the BGM in this video, nice music. And I liked the idea of cleaning up old code.
Thanks! :D (the music maker)
I feel like I would've moved it to a modern platform before doing any of this refactoring.
Also, core.autocrlf = false is the best setting. You don't need to mess with any .gitattributes files, checkout as-is, commit as-is, no weird CRLF mangling on windows.
And man does this code need a formatting fix. I wish there were a universal opinionated formatter for c++ like there is with js with prettier/biome.
Some projects don't even use the .clang-format in the project root folder....
What do you find lacking in clang format or uncrustify?
I tried to be explicit that I left it in the old tools to prove that we COULD DO BETTER even back then!
Nice! And you kept everything under VC6! I was wandering why you didn't use any auto for a while😅
A couple of things I would do differeny:
- I would pass rational numbers by value all the time. It is just two int
- I would use hidden friends for operator overloading (though maybe VC6 doesn't even support friend)
This is interesting, you could do elegant things in C++98 as well and you were not forced to new things then either, and memory leaks wasn't untraceable, that was just bad code. But newer C++ helps in so many areas. Yea I've been stuck in old 98 code for a while and have been able to improve a lot.
C++98 was THE NEW thing back in 1998. The whole code you wrote was cutting edge stuff anyways so not many people could even do it. What do you mean by it didn't force us to newer things?!
@@ohwow2074 I mean there were no IDE support, static analysis and linters suggesting newer and better ways of doing things. Sorry if I was unclear.
@@OlaInTheClouds you see it all as a disadvantage?
I really liked this format of code review!
I was thinking the "having to maintain this project" would've meant you get to upgrade your tools and everything, but you're stuck to C++98. But now I get why application folders are so full of garbage. It's like two calculation function files and a main and it expanded to multiple folders with their own set of files and possibly copies.
You might not necessarily get to update your tools, but you might still have to maintain an old project.
I wanted to show what is possible before upgrading your tools. I'll get back to the project at some point in the future and let the tools get upgraded.
Very instructive series
Now let's migrate to C++23! And everything must be constexpr. 🙂
Stay tuned!
Great refactor but any tips on reviewing this type of code uplift?
I started with borland turbo c++ in i believe 95? I used borland up till 5.0 although I eventually switched to visual c++ 6 . I have projects from then that let me just say i cringe when i look at that code.
I'll have to go look in the attic and see if I still have my Visual C++ 1.52 CD...
can you rewrite the entire thing in c++20/23?
Stay tuned!
Brilliant!
"I'm just pretending like it's very bad code"
You dont have to pretend :p
Hmm, this music reminds me of something else but I just can't seem to remember. Anyone else's bells ringing?
If you remember I'm interested to know! :D (the music maker)
I'm not a gamer, but it has a bit of an 8-bit video game vibe to it.
@@phredrix-we7kshaha yeah that was the idea XD the sounds are chosen to give that vibe
20:52 Please const the things! 😂
Oh waited for this vid :D
So great! I love the music...
One technique for adding header guards to A.hpp without changing it, is to write B.hpp, a file with only two things, (1) header guards and (2) #include . Then, include only B in your test.
18:40 My answers aren't wrong, but they aren't right either. 😂
Cannot you open .dsp/.dsw files from VS60 in modern Visual Studios?
You can open them but you have to Migrate the project.. It won't compile anyway unless it's a very simple program. Guaranteed, there are problems. Then you will have to fix to get it to compile probably a lot
@@Lalasoth he had to do a lot of fixes anyway. All while working in sub par dev environment, by today's standards.
start with scan-make
At 30:23 you ask yourself why you allocated a pointer to an int. The reason is that your old stack code held void *, so you needed a pointer to the heap not a pointer to a temporary on the stack.
It's tough to follow all the things you do, because you move so fast, but I get it. Ya gotta keep us interested and a lot of this is just monkey work. ie any monkey at a keyboard could make these rote changes. Nice to see how far we have come though from "back in the days."
My only other comment would be to add non existent copy constructors, assignment constructors and let the compiler show you where you are miss using the class, via the linker errors.
Tests! Start with the tests! Then you know the refactor is correct.
29:42 😂
damn, im early
Irritating music BTW
@39:23 why do you have 'break's after 'return's in 'switch' statements? You're doing a self-review before commit, which is a good practice (I wish some devs who I work with did it), but still you missed this obvious blunder.
Also, I know how so many people with their "strong opinions" will come and tell me how I am wrong, but I think the first 'refactoring' thing that you should have done about this project, was to replace all tab-indents with space-indents. @39:55 lines 64 and 70 look just ridiculous. Not only they are indented poorly, but also use a mixture of tabs and spaces for indents. Ugh, yuck! 🤮
I thought this episode was about writing tests, not refactoring and presumably subsequent episodes are about more refactoring.
Hello, fellow space indentation user. Those are indeed tiny steps, and he could've done the first as a simple search and replace, which even VS6 had available. If it were me, I would've used Vim to refactor the project and downloaded a copy of gcc and checkout'd a period correct version. Then tabs to spaces would be an easy :%s/\t/ /g and done. But maybe that's just me that was thinking that.
@@anon_y_mousse tabs -> spaces is not as easy in this case, because a tab is such a 'unique' (by which I mean annoying) little character! 1 tab = 4/8/ constant spaces only when they appear at the beginning of the line (or are preceded by other tabs, that are at the beginning of the line). Otherwise, they just align at some tabstop interval, so can 'mean' anywhere from 1 to _n_ spaces (where _n_ is 4/8/ as mentioned above).
VS60 did include the reformat feature, if memory serves, which would convert tabs to spaces (or vice versa) if the format style is configured to either use one or the other.
I can’t stand the music or whatever you call it. I’m out of here!😢
In my opinion, it fits the code.