C++ Weekly - Ep 407 - C++98 Code Restoration

Поділитися
Вставка
  • Опубліковано 11 січ 2025

КОМЕНТАРІ • 70

  • @sinom
    @sinom Рік тому +25

    "NULL" is an undeclared identifier. That sure is something lmao

  • @flowname
    @flowname Рік тому +30

    would be nice to see the same codebase migrated to C++20

    • @christer8964
      @christer8964 Рік тому +1

      That is the next step

    • @ohwow2074
      @ohwow2074 Рік тому +2

      Actually 23 would be interesting.

    • @cppweekly
      @cppweekly  Рік тому +12

      Stay tuned!

    • @purpasmart_4831
      @purpasmart_4831 3 місяці тому

      C++ 11 is honestly all you need.

    • @flowname
      @flowname 3 місяці тому

      @@purpasmart_4831 all you need to get started :)

  • @mgostIH
    @mgostIH Рік тому +8

    29:40 This is your brain on void* based polymorphism

  • @IndellableHatesHandles
    @IndellableHatesHandles Рік тому +24

    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

    • @marcs9451
      @marcs9451 Рік тому +1

      leaks should be avoided but they are not dangerous

    • @kodirovsshik
      @kodirovsshik Рік тому

      ​@@marcs9451but it sounds funny

  • @pkrysiak
    @pkrysiak Рік тому +5

    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 😅

    • @cppweekly
      @cppweekly  Рік тому +4

      Fair, but I also had my `pop` return the popped object, so it would have been one more thing to wrap/change.

  • @mjKlaim
    @mjKlaim Рік тому +7

    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)

  • @trcwm
    @trcwm Рік тому

    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.

  • @kinershah464
    @kinershah464 Рік тому +4

    I like the BGM in this video, nice music. And I liked the idea of cleaning up old code.

    • @mjKlaim
      @mjKlaim Рік тому +5

      Thanks! :D (the music maker)

  • @christer8964
    @christer8964 Рік тому +7

    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.

    • @axelBr1
      @axelBr1 Рік тому +1

      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.

  • @not_ever
    @not_ever Рік тому +1

    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.

  • @anon_y_mousse
    @anon_y_mousse Рік тому

    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.

  • @LesleyLai
    @LesleyLai Рік тому +2

    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)

  • @FryGuy1013
    @FryGuy1013 Рік тому +6

    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.

    • @bryce.ferenczi
      @bryce.ferenczi Рік тому

      Some projects don't even use the .clang-format in the project root folder....

    • @not_ever
      @not_ever Рік тому

      What do you find lacking in clang format or uncrustify?

    • @cppweekly
      @cppweekly  Рік тому +2

      I tried to be explicit that I left it in the old tools to prove that we COULD DO BETTER even back then!

  • @Yupppi
    @Yupppi Рік тому +1

    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.

    • @cppweekly
      @cppweekly  Рік тому

      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.

  • @hbobenicio
    @hbobenicio Рік тому

    I really liked this format of code review!

  • @Lalasoth
    @Lalasoth Рік тому +2

    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.

  • @OlaInTheClouds
    @OlaInTheClouds Рік тому +1

    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.

    • @ohwow2074
      @ohwow2074 Рік тому

      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?!

    • @OlaInTheClouds
      @OlaInTheClouds Рік тому +1

      @@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.

    • @ohwow2074
      @ohwow2074 Рік тому

      @@OlaInTheClouds you see it all as a disadvantage?

  • @kuberannaganathan5244
    @kuberannaganathan5244 10 місяців тому

    Great refactor but any tips on reviewing this type of code uplift?

  • @garrymarshall6331
    @garrymarshall6331 Рік тому

    I'll have to go look in the attic and see if I still have my Visual C++ 1.52 CD...

  • @simogasp
    @simogasp Рік тому +2

    Now let's migrate to C++23! And everything must be constexpr. 🙂

  • @Skaaaaal
    @Skaaaaal Рік тому

    Very instructive series

  • @GautamSharma-un3cr
    @GautamSharma-un3cr Рік тому +2

    can you rewrite the entire thing in c++20/23?

  • @sqw33k
    @sqw33k Рік тому +2

    Hmm, this music reminds me of something else but I just can't seem to remember. Anyone else's bells ringing?

    • @mjKlaim
      @mjKlaim Рік тому +1

      If you remember I'm interested to know! :D (the music maker)

    • @phredrix-we7ks
      @phredrix-we7ks Рік тому

      I'm not a gamer, but it has a bit of an 8-bit video game vibe to it.

    • @mjKlaim
      @mjKlaim Рік тому +1

      @@phredrix-we7kshaha yeah that was the idea XD the sounds are chosen to give that vibe

  • @garyp.7501
    @garyp.7501 10 місяців тому

    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.

    • @cppweekly
      @cppweekly  10 місяців тому

      Tests! Start with the tests! Then you know the refactor is correct.

  • @ysakhno
    @ysakhno Рік тому

    Cannot you open .dsp/.dsw files from VS60 in modern Visual Studios?

    • @Lalasoth
      @Lalasoth Рік тому

      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

    • @ysakhno
      @ysakhno Рік тому +1

      @@Lalasoth he had to do a lot of fixes anyway. All while working in sub par dev environment, by today's standards.

  • @MenaceInc
    @MenaceInc Рік тому +1

    "I'm just pretending like it's very bad code"
    You dont have to pretend :p

  • @6754bettkitty
    @6754bettkitty Рік тому

    20:52 Please const the things! 😂

  • @6754bettkitty
    @6754bettkitty Рік тому

    18:40 My answers aren't wrong, but they aren't right either. 😂

  • @srnissen_
    @srnissen_ Рік тому

    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.

  • @DarKOscillator08
    @DarKOscillator08 Рік тому

    Oh waited for this vid :D

  • @PedroOliveira-sl6nw
    @PedroOliveira-sl6nw Рік тому

    Brilliant!

  • @jbs.
    @jbs. Рік тому

    start with scan-make

  • @fritzmarkTheWrong
    @fritzmarkTheWrong Рік тому

    So great! I love the music...

  • @6754bettkitty
    @6754bettkitty Рік тому

    29:42 😂

  • @ysakhno
    @ysakhno Рік тому +1

    @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! 🤮

    • @not_ever
      @not_ever Рік тому

      I thought this episode was about writing tests, not refactoring and presumably subsequent episodes are about more refactoring.

    • @anon_y_mousse
      @anon_y_mousse Рік тому

      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.

    • @ysakhno
      @ysakhno Рік тому

      @@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.

  • @EmperorPear
    @EmperorPear Рік тому

    damn, im early

  • @ClaytonAAlves
    @ClaytonAAlves Рік тому

    Irritating music BTW

  • @HansJMicheelsen
    @HansJMicheelsen Рік тому +2

    I can’t stand the music or whatever you call it. I’m out of here!😢