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

แชร์
ฝัง
  • เผยแพร่เมื่อ 22 พ.ย. 2024

ความคิดเห็น • 70

  • @sinom
    @sinom 11 หลายเดือนก่อน +25

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

  • @mgostIH
    @mgostIH 11 หลายเดือนก่อน +8

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

  • @flowname
    @flowname 11 หลายเดือนก่อน +29

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

    • @christer8964
      @christer8964 11 หลายเดือนก่อน +1

      That is the next step

    • @ohwow2074
      @ohwow2074 11 หลายเดือนก่อน +2

      Actually 23 would be interesting.

    • @cppweekly
      @cppweekly  11 หลายเดือนก่อน +12

      Stay tuned!

    • @purpasmart_4831
      @purpasmart_4831 2 หลายเดือนก่อน

      C++ 11 is honestly all you need.

    • @flowname
      @flowname 2 หลายเดือนก่อน

      @@purpasmart_4831 all you need to get started :)

  • @IndellableHatesHandles
    @IndellableHatesHandles 11 หลายเดือนก่อน +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 11 หลายเดือนก่อน +1

      leaks should be avoided but they are not dangerous

    • @kodirovsshik
      @kodirovsshik 10 หลายเดือนก่อน

      ​@@marcs9451but it sounds funny

  • @pkrysiak
    @pkrysiak 11 หลายเดือนก่อน +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  10 หลายเดือนก่อน +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 11 หลายเดือนก่อน +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)

  • @not_ever
    @not_ever 11 หลายเดือนก่อน +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.

  • @trcwm
    @trcwm 10 หลายเดือนก่อน

    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.

  • @christer8964
    @christer8964 11 หลายเดือนก่อน +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 11 หลายเดือนก่อน +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.

  • @anon_y_mousse
    @anon_y_mousse 10 หลายเดือนก่อน

    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.

  • @kinershah464
    @kinershah464 11 หลายเดือนก่อน +4

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

    • @mjKlaim
      @mjKlaim 11 หลายเดือนก่อน +5

      Thanks! :D (the music maker)

  • @FryGuy1013
    @FryGuy1013 11 หลายเดือนก่อน +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 11 หลายเดือนก่อน

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

    • @not_ever
      @not_ever 11 หลายเดือนก่อน

      What do you find lacking in clang format or uncrustify?

    • @cppweekly
      @cppweekly  10 หลายเดือนก่อน +2

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

  • @LesleyLai
    @LesleyLai 11 หลายเดือนก่อน +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)

  • @OlaInTheClouds
    @OlaInTheClouds 11 หลายเดือนก่อน +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 11 หลายเดือนก่อน

      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 11 หลายเดือนก่อน +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 11 หลายเดือนก่อน

      @@OlaInTheClouds you see it all as a disadvantage?

  • @hbobenicio
    @hbobenicio 11 หลายเดือนก่อน

    I really liked this format of code review!

  • @Yupppi
    @Yupppi 11 หลายเดือนก่อน +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  10 หลายเดือนก่อน

      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.

  • @Skaaaaal
    @Skaaaaal 11 หลายเดือนก่อน

    Very instructive series

  • @simogasp
    @simogasp 11 หลายเดือนก่อน +2

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

    • @cppweekly
      @cppweekly  11 หลายเดือนก่อน +2

      Stay tuned!

  • @kuberannaganathan5244
    @kuberannaganathan5244 9 หลายเดือนก่อน

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

  • @Lalasoth
    @Lalasoth 11 หลายเดือนก่อน +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.

  • @garrymarshall6331
    @garrymarshall6331 11 หลายเดือนก่อน

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

  • @GautamSharma-un3cr
    @GautamSharma-un3cr 11 หลายเดือนก่อน +2

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

    • @cppweekly
      @cppweekly  11 หลายเดือนก่อน

      Stay tuned!

  • @PedroOliveira-sl6nw
    @PedroOliveira-sl6nw 11 หลายเดือนก่อน

    Brilliant!

  • @MenaceInc
    @MenaceInc 11 หลายเดือนก่อน +1

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

  • @sqw33k
    @sqw33k 11 หลายเดือนก่อน +2

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

    • @mjKlaim
      @mjKlaim 11 หลายเดือนก่อน +1

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

    • @phredrix-we7ks
      @phredrix-we7ks 11 หลายเดือนก่อน

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

    • @mjKlaim
      @mjKlaim 11 หลายเดือนก่อน +1

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

  • @6754bettkitty
    @6754bettkitty 11 หลายเดือนก่อน

    20:52 Please const the things! 😂

  • @DarKOscillator08
    @DarKOscillator08 11 หลายเดือนก่อน

    Oh waited for this vid :D

  • @MichaelSchulzDaFritzmark
    @MichaelSchulzDaFritzmark 11 หลายเดือนก่อน

    So great! I love the music...

  • @srnissen_
    @srnissen_ 11 หลายเดือนก่อน

    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.

  • @6754bettkitty
    @6754bettkitty 11 หลายเดือนก่อน

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

  • @ysakhno
    @ysakhno 11 หลายเดือนก่อน

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

    • @Lalasoth
      @Lalasoth 11 หลายเดือนก่อน

      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 11 หลายเดือนก่อน +1

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

  • @jbs.
    @jbs. 11 หลายเดือนก่อน

    start with scan-make

  • @garyp.7501
    @garyp.7501 8 หลายเดือนก่อน

    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  8 หลายเดือนก่อน

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

  • @6754bettkitty
    @6754bettkitty 11 หลายเดือนก่อน

    29:42 😂

  • @EmperorPear
    @EmperorPear 11 หลายเดือนก่อน

    damn, im early

  • @ClaytonAAlves
    @ClaytonAAlves 11 หลายเดือนก่อน

    Irritating music BTW

  • @ysakhno
    @ysakhno 11 หลายเดือนก่อน +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 11 หลายเดือนก่อน

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

    • @anon_y_mousse
      @anon_y_mousse 10 หลายเดือนก่อน

      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 10 หลายเดือนก่อน

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

  • @HansJMicheelsen
    @HansJMicheelsen 11 หลายเดือนก่อน +2

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

    • @dmitriidemenev5258
      @dmitriidemenev5258 10 หลายเดือนก่อน

      In my opinion, it fits the code.