How Do I Approach Rewriting an Old Codebase?

Sdílet
Vložit
  • čas přidán 6. 06. 2024
  • How do I rewrite an existing project? If I cannot avoid a rewrite, what things do I need to be careful of? What pitfalls are there when starting over after years of development? These are the questions we will answer in today's episode of Dev Questions.
    Website: www.iamtimcorey.com/
    Ask Your Question: suggestions.iamtimcorey.com/
    Sign Up to Get More Great Developer Content in Your Inbox: signup.iamtimcorey.com/

Komentáře • 85

  • @Antonio-lt1sp
    @Antonio-lt1sp Před rokem +3

    As always, bringing content right when I need it

  • @williamorozco4001
    @williamorozco4001 Před rokem

    Awesome! Thank you man!, a lot of clarity.

  • @datboi1861
    @datboi1861 Před rokem

    This video could not come soon enough. I've been tasked to rewrite an old codebase and it is intimidating af.
    Thanks, Tim!

  • @olinzknihytovi
    @olinzknihytovi Před rokem +1

    You are a wizard, Tim. Rewriting an old codebase is the task I am solving right now.

  • @lebeluet
    @lebeluet Před rokem +1

    Your are totally right manager are not the end user. When I worked on an application update project, I realized that there are 2 types of users: those who consult the information and those who update the data. I would say that we should not neglect their opinion of the latter first because they are the ones who are the recurring costs related to the application.

  • @jdr8364
    @jdr8364 Před 10 měsíci

    wow i need this, its actually my current job to port a old codebase to an MVVM design pattern

  • @edwardmay9851
    @edwardmay9851 Před rokem +2

    Great advice! We are just beginning the process of rewriting an old WinForms app. It's all biz logic intertwined in form code behinds with data read directly from DataSet and DataTable objects. I agree, we're not touching the DB too much, keeping old stored procs, but using Dapper to translate them into more proper business objects. I want to try Alberto Brandolini's Event Storming techniques to come up with a more DDD design by engaging with the domain experts on how users actually use the system.

    • @Luke-me9qe
      @Luke-me9qe Před rokem

      Just a quick heads up: event storming is a great method to get to know the environment beyond the borders of your software as well. With all the pros and cons. Just don't get lost in it 😉

    • @IAmTimCorey
      @IAmTimCorey  Před rokem

      Thanks for sharing!

  • @odumahojorma
    @odumahojorma Před rokem +1

    In recent past I've had to rewrite a webform app from my early dev days. Had and the sqldatacontrol and objectdatasource and Ajaxcontroltookit. lol. There was no upgrade path for that one. It was painful but worth it at the end.

  • @lizard450
    @lizard450 Před rokem

    lulllzzz ... so I joined my company a few years ago... just about to launch our new "product" ... and it was a rewrite of a failed rewrite. The new rewrite was essentially DOA .. so I basically started "rewriting" it. Used the same DB, and did it piece by piece. While we were adding new features resolving bugs etc. etc. kept chipping away at it... called it "refactoring". So far so good, but yeah bold strategy cotton.. glad it worked out for me haha.

    • @IAmTimCorey
      @IAmTimCorey  Před rokem

      That can be hard, but sometimes succeeding even a little where others have failed can make you look like a rockstar. Looks like you've done even better than that.

  • @Anton-Os
    @Anton-Os Před rokem

    Thanks!

  • @petervo224
    @petervo224 Před rokem

    I have never successfully re-written an old code base, but through the attempts, it's true as what you say. Furthermore, the older the code base, the more time and effort to analyze it before rewrite (and the fastest way is like you said, talking to end-users or developers maintaining the system).
    However, I think we should try re-writing your own code base, preferably those not delivered to any Production or business (e.g. your side projects or proof of concepts). I rewrite whenever I feel the direction of the source is not what I expect (e.g. existing tests too fragile; refactoring takes too much time despite having the tests) and review the base principles of the source. To make such rewriting more motivating, I create a perk tree (like in RPG games) which acts as a map that can be revised and reused, making each iteration of rewriting faster and in better direction (and also giving sense of achievement). For example, to achieve/complete [User Register] module, I need to complete [Password] model (in my early iterations, it is the [User] model containing the password fields, but later I edit the perk tree to separate them). And before [Password] model are [User] model, [Relation] function (to establish relationship between [User] and [Password] tables), and [Hashing] function (not supposed to store passwords in plain text, right?)

    • @Luke-me9qe
      @Luke-me9qe Před rokem

      And that's the background story of some of the frameworks out there. At least that's what started mine (closed source unfortunately)

    • @IAmTimCorey
      @IAmTimCorey  Před rokem

      Thanks for sharing!

  • @toadman5184
    @toadman5184 Před rokem +3

    Excellent advice. I try to approach rewriting in the same way I improve my own code which is: how can I simplify this, now I know what it's meant to do?

    • @Astral-Projector2389
      @Astral-Projector2389 Před rokem

      This, for every year that goes by i tend to think everytime. How can i do this easier and more readable. I don't want fancy syntax nor gatekeeping. My goal is to make a beginner being able to read my code and understand it.

    • @IAmTimCorey
      @IAmTimCorey  Před rokem

      Thanks for sharing.

    • @toadman5184
      @toadman5184 Před rokem +1

      @@Astral-Projector2389 Exactly. Keeping the ego out of the code is always beneficial.

  • @PelFox
    @PelFox Před rokem

    Incremental migration with a proxy is the way to go. Add tests for each uppgraded part as the legacy apps usually have zero.

  • @phillismable6303
    @phillismable6303 Před rokem +1

    Rewriting an old codebase can be a daunting task, but with a structured approach, it can be done successfully. Here are some steps you can take to approach rewriting an old codebase:
    Evaluate the existing codebase: Take a close look at the existing codebase and identify its strengths and weaknesses. Determine which parts of the codebase are salvageable and which parts need to be rewritten.
    Define goals and requirements: Define the goals and requirements for the new codebase. What are the features and functionality that are needed? What are the performance and scalability requirements?
    Plan the rewrite: Plan the rewrite in detail. Break the rewrite down into smaller tasks, such as refactoring existing code, writing new code, and testing. Estimate the time and resources required for each task.
    Choose the right technology: Consider using new technologies that may make the codebase easier to maintain and more scalable. Evaluate whether it makes sense to use a new programming language, framework, or toolset.
    Create a new architecture: Design a new architecture that meets the requirements and goals you have defined. This may involve creating a new data model, API, or system architecture.
    Rewrite the code: Begin rewriting the codebase, starting with the most critical components. Use the new architecture you have designed and consider best practices such as modular design, clean code, and version control.
    Test and iterate: Test the new codebase thoroughly, and identify any bugs or performance issues. Iterate on the codebase, making changes and improvements until it meets the requirements and goals you have defined.
    Deploy and maintain: Deploy the new codebase and monitor it closely to ensure it meets the performance and scalability requirements. Maintain the codebase over time, making changes as needed to keep it up to date and secure.
    Remember that rewriting an old codebase is a significant undertaking, and it's essential to take a structured and methodical approach to ensure a successful outcome.

    • @IAmTimCorey
      @IAmTimCorey  Před rokem +1

      I find that for any application of any size, knowing how to build new code that interfaces with the old code is really important. Trying to do it all at once is almost certainly a recipe for disaster.

    • @phillismable6303
      @phillismable6303 Před rokem +1

      @ghost mall exactly I was proving a point as quite a few of us have noticed patterns, I made a comment about google and Reddit being able to answer questions and there are way to many filler videos on some of the other videos. where Tim’s power comes from actually teaching coding in his easy to learn fashion, I pick topics up faster from him then any of the other channels. I really love his tutorials and learned so much from them all. But like I said people are starting to comment about speed watching them, about the number of times we get the same line respoken 3,4,5 times in different ways which just makes the video drag. I get it that not everyone has English as there first language as I live in the UK and our minorities are now our majorities, but answering questions, draggy videos, filler vids just aren’t worth subscribing anymore for. Like I said it isn’t just me saying this, and Reddit has a thread about it, which is an interesting read.

  • @MrSoloDev
    @MrSoloDev Před rokem

    I just finished a contract with a client in the ecommerce space that literally built a distributed monolith over 15+ years. They are at a point where adding new capabilities is impossible to do within a reasonable time frame and the root cause are:
    1) Power struggles that alienated all the knowledgeable and skillful employees. They are stuck with a bunch of C grade developers.
    2) Architects failing to realize that API is not an architecture (point to point APIs everywhere calling each other and depending on each other, big spaghetti)
    3) A legacy of components with no unit tests and no documentation on integrated and end to end QA tests. It's all in people's head and most of those people are gone.
    Managers: "I don't care what the excuses are, just get it done or we'll get someone else that can".
    Doesn't matter what strategies you take to tip toe around legacy code. You just end up adding to the existing chaos.
    It doesn't work when the fundamentals aren't there.
    If Elon Musk bought them off. He'd fire all the developers, the managers, the execs and build back from the ground up.

    • @IAmTimCorey
      @IAmTimCorey  Před rokem

      Managing legacy applications is really hard in the best of cases. The thing is that most applications are legacy applications and those that are redone to make them "right" will be almost as much of a mess as the thing they replaced when they get completed.

  • @benjamininkorea7016
    @benjamininkorea7016 Před rokem

    Here's my approach-- see how I used to code, hit my head against my desk a few times to lessen the pain, and then quickly and efficiently write more modern, better code. The only thing I don't do, for the most part, is change anything in my databases.

  • @MrSurfsAlot
    @MrSurfsAlot Před rokem +3

    I started at my new job February 22 and I rewrote a massive web forms application for financial data. I have spent many more hours than eight hours a day on this but it has been an awesome learning experience and when I realized I was going to be able to successfully do it, it became extremely fun. Used blazor server

    • @IAmTimCorey
      @IAmTimCorey  Před rokem +4

      Awesome!

    • @benjamininkorea7016
      @benjamininkorea7016 Před rokem

      I also migrated from Webforms to Blazor Server. Started with some of Tim's videos on Blazor, tbh-- never looked back. Finally, a web framework that I actually ENJOY working with.

  • @Any1SL
    @Any1SL Před rokem

    Depends on how different the abstractions are going to be from the existing ones.

    • @IAmTimCorey
      @IAmTimCorey  Před rokem

      That's one consideration, but there are a LOT more.

  • @redcrafterlppa303
    @redcrafterlppa303 Před rokem

    5:18 my problem is that I'm rewriting my application because of the data storage solution. It's messy slow and inappropriate for the grown data mass. I wanted some small ui changes but they where reimplemented relatively fast and the ui is done. What's missing and I'm struggling is my local database solution. As it's an archiving Software that part is really important to get right. 😅

    • @IAmTimCorey
      @IAmTimCorey  Před rokem

      Yep, data is really important to get right and moving data locations is tricky to do well.

    • @Luke-me9qe
      @Luke-me9qe Před rokem

      If a lightweight nosql is an option: try LiteDB. If SQL is mandatory: sqlite. I like those and DBs up to a few hundred MBs are great for those. Consider my comment is subjective and my opinion, please.

  • @ric_silva_a
    @ric_silva_a Před rokem

    you could make a video on how to integrate payment methods in an asp net core app. like with paypal and stripe

    • @IAmTimCorey
      @IAmTimCorey  Před rokem

      Thanks for the suggestion. Please add it to the list on the suggestion site so others can vote on it as well: suggestions.iamtimcorey.com/

    • @ric_silva_a
      @ric_silva_a Před rokem

      @@IAmTimCorey voted, thank you for all the content!

  • @cheronecom
    @cheronecom Před rokem +1

    it depends ;)

  • @petropzqi
    @petropzqi Před rokem

    In a huge project ATM. It all goes downhill, old system is better then the new one. It's like textbook example on bad practices. Waterfall, desig set last summer. Front-end and backend not talking. We have next to no acceptance test. Thing breaks we can't even update entities...

    • @IAmTimCorey
      @IAmTimCorey  Před rokem

      It sounds like optimism overrode good planning and best practices.

  • @antoniusivan8767
    @antoniusivan8767 Před rokem

    My manager ask me to separate large complex monolithic .net framework to eks , I can use .net 6. How I approach this thing tim? Thx before

    • @IAmTimCorey
      @IAmTimCorey  Před rokem +1

      Do you mean AKS (Azure Kubernetes Service)? If so, that is a MASSIVE undertaking. I would recommend not taking such a large leap all at once. Monoliths are absolutely fine. The performance issues are almost certainly not because it is a monolith. Just moving your existing code to .NET 6/7 would be an immediate performance improvement. Microservices also will not reduce complexity. They will ADD complexity. So if you are trying to reduce complexity, moving to AKS is not the way to do so.

    • @IAmTimCorey
      @IAmTimCorey  Před rokem

      I would see if you can put the data factory behind an API if you cannot replace/upgrade it. If you can get it in an API, you can upgrade the rest of your project to .NET 6 and then just call the API when needed.

  • @natureshamy
    @natureshamy Před rokem +1

    Holy shit just yesterday I was thinking how to sell a rewrite of an old app at my new job jajaja.
    Must be a sign or something.
    Edit: It was a sign. After watching the video I no longer want to rewrite the app. 😅

    • @IAmTimCorey
      @IAmTimCorey  Před rokem +1

      I'm glad the video was timely. Hopefully it helps you make the best decision for your situation.

  •  Před rokem

    I have one thing to say... I've been programming in C# for the last 2 years or so. I decided that I should upgrade from classic asp, that's been my main programming language since forever. I'm old and it's getting hard to learn new things...
    Well, I have to testify that the Classic ASP (wich has A LOT of limitations) is quite faster than dotnet core.
    For everyday tasks such as reading a huge dataset and print it to a webpage, ASP classic is a lot fastar than any C# implementation and it takes much less resources. BUT it lacks of many modern resources, such as JSON support to say the least...

    • @PelFox
      @PelFox Před rokem +1

      Sounds a bit odd since all data says core is more cpu and memory efficient while also being more performant and cross platform.

    • @IAmTimCorey
      @IAmTimCorey  Před rokem +1

      I believe this is an apples and oranges comparison. You can absolutely have a faster experience in ASP.NET Core than in ASP classic. However, the additional features with ASP.NET Core can add overhead. For instance, if you get a list of 5000 records in Blazor Server, the display to the screen will be slower than ASP Classic. The reason, though, is because Blazor Server will be monitoring each of those 5,000 objects and their internal properties for changes so that it can update the screen. ASP Classic cannot do that. If you turn that off in Blazor, you can display a LOT more records a LOT faster.

    •  Před rokem

      @@IAmTimCorey I'm comparing two very diferent techs doing the very same job. Listing records to a html page. Asp Classic does it faster and with less memory usage. And I'm not even talking about EF Core... I tested with Microsoft.Data.SqlClient.. I'm not saying that it is BETTER to use ASP classic. I'm saying that for this task, it's faster and less mem usage. And you can test yourself if you want...

    •  Před rokem

      @@PelFox just tested. I made a select of 200 records using asp classic and a console app with System.Data.SqlClient
      The asp script executed the task in 1175 miliseconds.
      The console app in 3112 ms

    • @IAmTimCorey
      @IAmTimCorey  Před rokem +1

      I'm curious to know a couple of things. First, how many records do you intend to display on the screen (and why lots on the web)? Second, what ASP.NET Core project type are you using to display the records? Razor Pages would probably be the best option, but I'm wondering if that is what you are doing.

  • @omaewamoushindeiru1108

    I tried to do that but they fired me :(

  • @mistercoder1583
    @mistercoder1583 Před rokem

    Coderush, sonarlint, writing UT, and lots and lots of #warning and [obsolete]

    • @IAmTimCorey
      @IAmTimCorey  Před rokem +1

      That might work for a library, but a UI project will take more than that.

  • @milosacimo
    @milosacimo Před rokem

    Oh it's easy. You don't approach it, you run away :)

  • @biscuitbakerful
    @biscuitbakerful Před rokem

    first

  • @Andreas-gh6is
    @Andreas-gh6is Před rokem

    How do you rewrite an existing C# project? Hopefully with another language...

    • @IAmTimCorey
      @IAmTimCorey  Před rokem

      Careful, your inexperience is showing.

    • @IAmTimCorey
      @IAmTimCorey  Před rokem +4

      Couple things here. First, I'm not sure what you are comparing to, but C# isn't 10-20 times as verbose to do things. Sure, you can make it that way, but that's true of any language. For example, I have an API I wrote with full CRUD actions and OpenAPI documentation for a table that is less than 50 lines of code total. You can get an API down to just three lines of code if you want. However, code is meant to be read by humans. Trying to play code golf isn't something you should do in the real world.
      Second, vendor lock-in? .NET is open-source, cross-platform, and has a 20+ year track record. I'm not sure what you want from a codebase, but that's about as good as it gets.
      Third, you don't need expensive developers to write C#. However, junior developers are...junior. That's true no matter the language.

    • @odumahojorma
      @odumahojorma Před rokem +1

      @@Andreas-gh6is I totally disagree. Bad code can be written in any language, A company can pick a framework or language based on their staff strength. Having a preference for one language doesn't mean the other is bad. People say php is easy but I never liked the syntax. Doesn't take anything away from the language.

  • @maxthecat4632
    @maxthecat4632 Před rokem +1

    There is a lot of money to be made rewriting systems that have been written in India. Doing this has paid off my mortgage and stuffed my pension full of money.

    • @IAmTimCorey
      @IAmTimCorey  Před rokem

      I'm glad you've been able to succeed in this field.

  • @anarhistul7257
    @anarhistul7257 Před rokem

    The delete key. You're welcome!

    • @IAmTimCorey
      @IAmTimCorey  Před rokem +1

      That's a great way to free up about 40 hours a week for you.