Do you have nice examples of refactoring code?

I am looking for code samples that are good examples of how to refactor code. I would be the happiest if you could provide the code both before and after the refactorings. I am interested in any language, but Java and Python is preferred.

Why? I am planning to make a meetup on the topic and I would need a good base for it.

(I know that there are a lot of stuff out there like refactoring.guru, etc, but I am interested in real-life code samples! :) Also, I have a big bunch of code from our codebase, but I hope you might have even more interesting samples! )

Any help is appreciated! :)

Did you find this post useful? Show some love!

Here's a small Python function I refactored - you can see the steps I took: exercism.io/submissions/bd5ae82980...

And here's a good one in Ruby:
exercism.io/submissions/89e5c8c5c8...

This kata is a famous one :

github.com/emilybache/GildedRose-R...

Also, you can take a look at this one :

github.com/sandromancuso/trip-serv...

Java one is also explained in two blog articles here :

codurance.com/2011/07/16/testing-l...

is it about safe refactoring (with ide)
or refactoring to design patterns? if its the latter, I recommend going through Clean Code by Rob Martin and
Refactoring: Improving the Design of Existing Code by Kent Beck and Martin Fowler

Ben Halpern DEV.TO FOUNDER

Hey there, we see you aren't signed in. (Yes you, the reader. This is a fake comment.)

Please consider creating an account on dev.to. It literally takes a few seconds and we'd appreciate the support so much. ❤️

Plus, no fake comments when you're signed in. 🙃

I just wrote a post on refactoring some Go code to use interfaces. I outline the steps used to refactor this particular pattern: dev.to/chuck_ha/interfaces-in-go-3onc

I would also suggest reading sandimetz.com/99bottles/. It's a fantastic book that refactors code throughout the book and explains how to get there.

Someone at work asked me to refactor their 99 bottles code. I recorded the refactoring so they could see the process and how I think about it. Before is here and after is here. It's a pretty good demonstration of how I refactor.

(C#) I just made one that I found in StackOverflow. I implemented the code in a WebApi and it is working fine :D

stackoverflow.com/questions/333111...

Classic DEV Post from Mar 3

Tools you need to use in your react components development 

As a react developer, I believe that everyone who is working on a react project must develop all the components separately for taking advantage of that components philosophy behind this amazing front-end framework.

READ POST
Follow @elaziziyoussouf to see more of their posts in your feed.
Leonora Der
Java developer and Computer Science student from Hungary. #java #javascript #springboot #vuejs #css
Trending on dev.to
Biggest aha moment
#discuss
Resources for Getting into DevOps?
#help #discuss #devops
What is your personal project?
#personal #project #indiehacker #discuss
Who uses Telegram at work?
#discuss
5 Reasons You Should Write That Blog Post
#career #beginners
Code for Humans
#code #humans #codequality #readability
What are some good questions for a "State of the Web" survey?
#webdev #discuss
What is today's "goto"?
#discuss #learning #tips #history