Questions tagged [refactoring]

Refactoring is a disciplined technique for restructuring existing code, altering its internal structure without changing its external behavior. Open-ended questions about refactoring your code are off-topic for Stack Overflow, however they may be appropriate for Code Review.

Filter by
Sorted by
Tagged with
-5 votes
1 answer
74 views

Move timestamp to the next Monday 10:01 AM [closed]

I've been battling ChatGPT for hours now and can't get satisfied with this simple algorithm in TypeScript. function computeUpcomingNotificationTimestamp( currentTimestamp: number = Date.now(), ...
Slazer's user avatar
  • 4,814
1 vote
2 answers
39 views

Optimize Searching method in File at Python

I am trying to optimize the method below. It is the core of my project(as the % of time in the method is close to 95%). It reads a line of file and if the tid is in the line it returns the first ...
gybonel's user avatar
  • 13
-1 votes
0 answers
28 views

UnityEngine.GameObject

I have a problem in Unity, more specifically in visual studio, I changed something, I don't remember what it was, I think it may be some refactoring but I don't remember anything, but it is a problem ...
Jesús Huerta's user avatar
2 votes
2 answers
42 views

Is there a generic way to make deep recursive functions work without changing system recursion limit?

We have a Python codebase containing quite a lot recursive functions, they may run into deep recursions and break the recursion limit with default Python interpreter settings. We have used sys....
freeswan's user avatar
-1 votes
4 answers
137 views

Refactoring Java Code: Eliminating or Streamlining a Boolean Variable Outside a For Loop

I am struggling with the following problem in my code: boolean target = false; for (Item item : list) { if (item.boolA || target == true) { if (item.boolB) { target = false; } else if (...
devdevdev's user avatar
-1 votes
0 answers
28 views

Idiomatic way to filter a `Vec` of version identifiers to only include latest version for each minor release [closed]

I have a Vec<String> of all available versions of a particular piece of software (Godot), named VERSIONS in code below, where each version can be either "major.minor" or "major....
pew's user avatar
  • 35
0 votes
0 answers
25 views

Refactoring Python Code in Function Calculating Jaccard Index

I have created a function that calculates the Jaccard index for a specific category and term. The function is supposed to find all the document ids that are connected to the term,category and then by ...
gybonel's user avatar
  • 13
1 vote
2 answers
67 views

PowerShell rename refactor (F2) does nothing in VS Code

Pressing F2 when editing a PowerShell file does nothing in VS Code. (for other languages like C#, Python rename refactor (F2) works fine) What I've tried: completely uninstalled MS PowerShell ...
g.pickardou's user avatar
2 votes
3 answers
108 views

How to make this awk script less boilerplate?

Suppose I've got a log file like this (1st column is a timestamp): 1699740442177 Start A 1699740442177 Start B 1699740442255 Start C 1699740442261 Finish B 1699740442337 Finish C 1699740442337 Finish ...
Michael's user avatar
  • 41.3k
1 vote
2 answers
39 views

How do I detect the usage of a ContextManager in Python?

I am trying to refactor the following: with MyContext() as ctx: ctx.some_function() ...into something more like this: with MyContext(): some_function() How can I detect in the body of ...
JeremyEastham's user avatar
0 votes
1 answer
33 views

How to refactor two xml files in Android into a reusable component?

I have two different xml files in an Android project that are very similar -- they both specify an ImageView and a TextView -- the only difference is that they have a different text and image source ...
Gomes's user avatar
  • 35
0 votes
0 answers
8 views

Refactoring without configuring project

I have c++ project in old IDE that does not support refactoring. I decided to use refactoring with Visual Studio Code. I have opened SRC folder that contains headers and cpp files. Find references and ...
vico's user avatar
  • 17.3k
0 votes
1 answer
42 views

How can I handle more than 100 cases neatly on typescript?

By writing down the type of batch in .env, the goal is to be able to process all batches with one program. The purpose of wanting to process batches with one program is because I do not want to ...
Giuk Kim's user avatar
  • 181
0 votes
6 answers
92 views

Refactor code to reduce retardancy by reducing number of code lines

private bool IsValidPhoneAnnuitent(List<PhoneAnnuitant> annuitant) { if (annuitant is not null && annuitant.Count() > 0 && annuitant[0].Person is not null) return ...
jansy's user avatar
  • 11
1 vote
2 answers
62 views

Refactor code by reducing multiple "OR" condition

if (policyNumber.StartsWith("CM")) return "POLICIES"; else if (policyNumber.StartsWith("W002")) return "ANNUITY"; else if (policyNumber.StartsWith("...
jansy's user avatar
  • 11
0 votes
0 answers
48 views

To do list using react is not working, unable to split logic using custom hooks and multiple compontents

I am trying to split my code for a to do list into diferent components, it was working before i split it up, but after its not working. i am also trying to separate the logic into a custom hook and ...
Ismael Perez Gonzalez's user avatar
0 votes
0 answers
76 views

why is import alias in next js 12 not working?

Here is my CompileOptions: { "compilerOptions": { "target": "es5", "lib": ["dom", "dom.iterable", "esnext"], "...
codeVibek's user avatar
  • 114
0 votes
0 answers
59 views

How to refactor in spyder?

I have been looking at how "refactor" in Spyder IDE (5.4.3), that is rename a variable and all occurrences of it in the script. I only found very old similar topics (5 years old and older ...
Antoine's user avatar
  • 27
1 vote
1 answer
53 views

How to rearrange Kotlin named arguments in Android Studio?

Is there a way (like ⌥ + ⌘ + l ) to reformat named arguments in Android Studio to ensure they match the order specified in the function's declaration. For example: fun sum(a: Int, b: Int, c: Int) { ...
tramp_tw_12677's user avatar
2 votes
1 answer
45 views

React - best practices on sharing functions across components

When following best practices in React, what is the best way to share functions across components? A simple example I have right now is a date formatter that just takes a DateTime and converts it to a ...
Roy's user avatar
  • 33
0 votes
0 answers
36 views

When moving and refactoring a file, Pycharm displays Error Cannot Move message

I tried to move a textfile to a new directory using F6 and drag and drop. The IDE displays the following error: Error Cannot Move I expected to move the file successfully into the new directory. How ...
Zayd's user avatar
  • 1
1 vote
1 answer
60 views

How can I refactor to reduce no of lines

'If' and 'else if' share almost similar code expect on which the forEach is called. Tried using a function to place same lines of code in them. But have trouble calling them (maybe because it is a ...
So25's user avatar
  • 63
0 votes
1 answer
59 views

Rectifying inconsistent return points

I have a zillion-line method somebody else wrote that I want to refactor using PhpStorm. Let's say that in highly abbreviated form, its basic structure looks something like this: myMethodName($input){ ...
Viscountess of the Junkyard's user avatar
0 votes
0 answers
31 views

Maintain Useful commented codes in separate class in C#

I have a useful commented codes in every classes as below which are used for future references .Is there is any alternative way to effectively maintain commented codes in difference class and can be ...
jansy's user avatar
  • 11
1 vote
1 answer
167 views

Refactor an Object that expects one thing to expect many things

I am working on updating a Go codebase. Our company has a central data store, fictionally called DataStore, that you can publish to or read from various datasets or schemas. Our particular code base ...
wubbalubba's user avatar
0 votes
1 answer
88 views

Complex React Table Component with Row Selection Causing Scroll Jump – Looking for Optimization Suggestions

I'm currently working on a complex React table component which is giving me some performance and usability issues. The primary concern is that, when selecting rows, the scroll position of the table ...
Luiz Gustavo's user avatar
1 vote
0 answers
59 views

How do I refactor JavaScript code to TypeScript when it uses Object.create to define its public interface?

I'm working on some legacy code I didn't write, trying to refactor it to typescript. Some of the patterns confuse TS type inference and usually TS shrugs and says, "Your guess is as good as mine, ...
Daniel Kaplan's user avatar
0 votes
1 answer
18 views

Name for technique of running two versions of code to ensure they are compatible?

I am looking for a name to call this pattern that I have seen when maintaining legacy codebases. Short version: Run two versions of a function side-by-side, comparing results in the program itself, to ...
Liam's user avatar
  • 20k
0 votes
0 answers
37 views

Is there a way to optimize a triple nested loop for accessing and object

I need to build a application to extract data from multiple JSON-Files and store it into a Database. The File looks like this and parsed results in a highly nested object. To explain, i need to go ...
Julius's user avatar
  • 21
1 vote
1 answer
36 views

Suggestion needed to remove duplicate class, without changing #define depends on that class static object

There is a duplicate class implementation in two projects, which are using C++. When i tried to merge the minor differences of both into a single class, i faced a blocker as the #define's in the ...
ShIvA SaI's user avatar
1 vote
1 answer
59 views

Replacing CLR Types with c# alias types in an enitre Codebase

I'm looking for a way to easily replace all CLR-Type references in a codebase with a few thousand files with their respective alias types, specifically: "Int64" => "long" &...
Raptor22's user avatar
  • 311
0 votes
0 answers
19 views

terraform module upgrade and manage 'plan differencies'

I defined a module that has all the related grafana, resources. And used this module in many root modules. But there was some misconfiguration of the 'grafana provider version' and I changed all of ...
dykim123.kim's user avatar
0 votes
0 answers
42 views

Angular & RxJS - Seeking suggestions on the best practices & code refactor

I created a mini app which shows the Continent & the Country selections. just to practice RxJS concepts. (You can checkout to ng-conf/learn-rxjs-01 branch on https://stackblitz.com/edit/stackblitz-...
Angular animal's user avatar
1 vote
1 answer
140 views

How can I do refactoring of CDK code using TypeScript?

I have created a CDK stack and put all my code inside (S3 bucket, Lambda etc.); the code is also in production, so I am not able to delete anything or lose any data and logs. I want to refactor that ...
bytebridger's user avatar
0 votes
0 answers
63 views

Rename dynamic references in Python files using VS Code

Is there a way to rename dynamic references when refactoring Python files in VS Code? E.g., consider the following example: class Test: def __init__(self, x): self.x = x def test(cls): ...
Bob's user avatar
  • 428
0 votes
1 answer
44 views

SwiftUI - common view with "binding" variable

I have main ImportDataView with List of few pickers. Pickers are similar but I need to use different "selection". Each Picker is in separate var (some View) of ImportDataView extension. Is ...
Serhii R's user avatar
1 vote
1 answer
72 views

How to create an instance of a generic class with its builder?

I am writing some code where I have many Child... classes which inherit a Parent class like ChildA, ChildB, etc. I am using Lombok's @SuperBuilder annotation to generate builders for all these classes....
DashwoodIce9's user avatar
0 votes
1 answer
77 views

Checkstyle for unused member variables?

Need the checkstyle configuration for unused member variables. There exists a checkstyle like below, but's just for local variables. <module name="UnusedParameterCheck"/> ( Needed a ...
Nidhi Kri 4-Yr BTech Metallurg's user avatar
0 votes
0 answers
49 views

Auto-implement abstract methods in Java with Visual Studio Code

I have an abstract class which is being extended by 100 classes. I add another abstract method to the abstract class. How can I implement a stub method into all subclasses at once?
e v e r n i t e's user avatar
0 votes
1 answer
46 views

Avoiding a method to repeatedly add values to a map on different calls

I have a service class that has a method : @Service class MService { private Map<String,String> map=new HashMap<>(); public List<File> genMetFiles(String ver){ . . . buildMap(ver); ...
pensee's user avatar
  • 415
0 votes
0 answers
46 views

how to correctly use base64 from another file

I would like to explain my problem of the day currently i am in an html file and i am using an img in it I reduced the size of the base64 to not spam ^^ <img src="data:image/png;base64,...
Neff's user avatar
  • 199
0 votes
0 answers
26 views

How can I avoid a reported conflict when moving an explicit interface implementation into a derived class in ReSharper?

Given the following code namespace MyNamespace { class MyExampleDerived : MyExampleBase { public int MyAnswer() { return 42; } } class ...
Andrew Grimm's user avatar
0 votes
1 answer
43 views

Validating user inputs on service methods in a cleaner way

In a project, we use service methods, there, we have to validate certain required inputs for our business logic to work: public void exampleMethod(final UserDto user, String sthElse) { if (user....
Kaue's user avatar
  • 15
1 vote
1 answer
41 views

Symfony 3 - Refactor controller action [closed]

I’m working on a Symfony 3 project wher I discovered a very long controller action (like 1k lines and lany different treatments inside) that I want to refactor by cutting it into several other ...
FreeZaxe's user avatar
0 votes
1 answer
46 views

Is there a preferred method to reorganise C header files in a project?

I have been given a medium-sized but complex C project (about 200,000 lines in total) which contains around 100 .h files and nearly as many .c files. Many of the .h files correspond to equivalent .c ...
Wilseus's user avatar
0 votes
0 answers
27 views

Improve Readability of Nested Foreach Loops - Should I Create Separate Methods?

I have a piece of code in my C# project that involves nested foreach loops. While it works as intended, I find it difficult to read and maintain due to its complexity. I'm wondering if it's a good ...
chatay's user avatar
  • 151
0 votes
0 answers
49 views

Refactoring old JS. Migrate from legacy JS to webpack. Do I even need bundler or stay vanila JS?

For example, I have files: /js/common.js and /js/jqextend.js. Most of legacy JS files have such architechture: ;var common = (function() { functionName = function () { } })(); ...
Geckon01's user avatar
1 vote
1 answer
83 views

Name of this repeated definitions replaced by overloaded functions code smell/refactoring pattern

I had a set of functions which were doing repetitive things + something more. (This is a simplified code snippet) static class Configuration { String site; List<Category> categories; } ...
yadav_vi's user avatar
  • 1,287
0 votes
1 answer
37 views

refactoring an if/else if block within a javascript map

Is there a way to refactor this function "expandCols" and clean it up? I feel like the if/else if block within the map can be cleaned up but I'm brain farting. The function below lives in a ...
new_coder's user avatar
0 votes
2 answers
93 views

How to simplify this Rust code with nested `match` with guards returning `Result`s?

Is there a simpler way of writing this Rust code? For full context, see this PR. impl FromArgValue for FlakeRef { fn from_arg_value(s: &str) -> std::result::Result<FlakeRef, String> { ...
Sridhar Ratnakumar's user avatar

1
2 3 4 5
159