Questions tagged [refactoring]
Refactoring is a disciplined technique for restructuring an existing body of code, altering its internal structure without changing its external behavior.
747
questions
-1
votes
1
answer
79
views
ReactJS hook vs utility function
Should we use utility functions in react or should everything be components and hooks?
I had this scenario:
Utility function for formatting money.
const formatMoney = (value) => value == null ? '' :...
-1
votes
0
answers
60
views
How to become better at predicting refactoring outcome? [closed]
Seems like even after years programming, one may occasionally fall on seemingly simple code which in reality is tricky code that isn't as easily refactorable as it seems in first instance...
Here's an ...
0
votes
2
answers
131
views
Is it still "feature envy" if the state to make decision or the action to take after asking the state involves other classes to participate?
According to https://softwareengineering.stackexchange.com/a/212130/432039, if a class asks another class for the state, and then call methods of that class, it is called "feature envy", eg:
...
-4
votes
1
answer
93
views
Refactoring the testing code inside a big switch code block
The main logic of my function is a switch case, with the default case being the abnormal case.
function main(input) {
let result = process(input)
switch (result): {
//normal cases
case ...
2
votes
1
answer
125
views
Refactoring Processor classes
I am writing some python 3 bioinformatics software and was wondering about the best way to write it in an OOP format. I am pretty sure a lot of my classes are violating the SRP principle, but I'm not ...
0
votes
1
answer
164
views
Our php codes base has 6 different ways to do INSERT … ON DUPLICATE KEY UPDATE, how do I fix it?
Our php codes base has 6 different ways to do INSERT … ON DUPLICATE KEY UPDATE. It happened over years because the php framework is evolving and my team members come and go, although I won't say we ...
2
votes
1
answer
253
views
To hide side effects or not?
Only loosely related to the title.
In my code I often encounter functions such as this one (e.g. from a pet project – a Discord bot written in Python – but seemingly a ubiquitous and reoccurring issue)...
4
votes
5
answers
365
views
Does testing the public surface of a class test the behavior of code or the way it is written?
A follow up question to How do unit tests facilitate refactoring without introducing regressions?.
I said that integration tests test the behavior of the code, while unit tests, being tied to ...
0
votes
4
answers
184
views
How to eliminate repetition in three subclasses: each defines an identical method that does almost the same thing, but with a different return type
TLDR:
I have three subclasses, each inherits from the same parent class, each defines an identical method that does almost the same thing, except that each of these methods has a different return type....
-1
votes
2
answers
280
views
What process to get away from a 10+ years old frontend?
there is an app with lets say, 75 years worth of development in it. The frontend is a bit a chaos, there is jquery, there is vuejs (vue 2 of course), there is a lot of server side rendering with over ...
23
votes
7
answers
6k
views
Sufficient conditions for refactoring
I've found that many codebases in large companies degrade over time, only adding new features and never improving the design of the codebase. Gradually, these codebases degrade to what is considered &...
0
votes
1
answer
104
views
Return response from controller or raise exception from service
I need some guidance on how to send error responses to client from WebAPI controller for an update operation. I need to check if data is changed and if it has duplicate data. I have service class that ...
1
vote
1
answer
135
views
Refactoring to nested functions inside methods (JavaScript)
I've been reading Refactoring (2nd) by Martin Fowler. In the first chapter, he shows an example of refactoring a function where he extracts other functions from it and places them inside that function ...
1
vote
1
answer
132
views
Monolithic Database to Microservices, but with Radical Data Model Changes
We are finishing up a long (over 1 year) project to retire our monolith. We have been moving pieces of functionality into microservices guided by domain driven design.
So far we have been leaving the ...
4
votes
3
answers
244
views
How do you handle instantiating a large number of interconnected component objects?
I'm currently refactoring our instance startup code, which is currently a 2,000 line mud method. The issue is that that method needs to create a large number (>50) of components/service objects, ...