Join us in building a kind, collaborative learning community via our updatedCode of Conduct.

Questions tagged [refactoring]

Refactoring is a disciplined technique for restructuring an existing body of code, altering its internal structure without changing its external behavior.

0
votes
1answer
19 views

Rewriting jQuery fadeIn into Javascript

I am currently using jQuery inside a Javascript function. For practice purposes I am trying to use vanilla Javascript throughout my entire project. However I cannot figure out how to rewrite the ...
1
vote
2answers
40 views

Can I rename a C# symbol from the command line?

Visual Studio has a "Refactor Rename" feature where I can right-click any type or member and rename it, and it will update all references within a project or solution to match. Is this functionality ...
1
vote
2answers
71 views

Ruby method for values from all associations

This method works, but I'm sure the performance could be greatly improved. Also, I'm realizing how fun and awesome it is to take smelly code like this, and rubify it. But I need a little more help ...
0
votes
4answers
31 views

Best way to find matching id's in an array of objects?

if I have this array of movie ids movies=[28, 14, 100, 53, 37]and this array of objects.genres=[{id: 28, name: "Action"},{id: 10770, name: "TV Movie"},{id: 53, name: "...
1
vote
1answer
34 views

Change logger level depending on status

Let's say we have some method sending email messages with status level of the message:void sendEmail(Level level, String message) {...}The levels can be of three types: enum Level {...
0
votes
0answers
28 views

Python: wrapper to hide multiple class instances for backward compatibility

I have the following situation. Consider a Foo, that had one Bar. Therefore, a class has been implemented for Bar, and Foo had a member bar, and all could be used like this:class Bar:def ...
0
votes
2answers
45 views

How to refactor two for loop using map method

I'm using swiftyjson library and I wrote this to retrieve urlImage. for (_, value) in json["assets"] {for item in value.arrayValue {let urlImage=item["urlImage"]....
0
votes
1answer
28 views

Visual Studio / Resharper Extract Interface to break god object

I'm trying to break a large object into smaller interfaces. Example: public class SomeService{readonly GodObject _god; // <-- Replace this with an Interfacepublic SomeService(...
0
votes
6answers
60 views

Refactoring a rigid code to eliminate if-else statement of checking instanceOf

Good day everyone,I have a question regarding to refactoring a piece of code. The classes are structured as:abstract class Aclass A1 extends class Aclass A2 extends class Aclass A3 extends ...
0
votes
0answers
11 views

Can macros be applied for all errors in IntelliJ?

We have several autogenerated files, that are being referenced extensively in our project. Any time the field names are modified, say changing the case of the field name, all the references are broken....
3
votes
4answers
55 views

Refactoring a sequence of methods

I have a sequence of methods that I need to run sequentially, using the result of each method as a parameter in the next. However, I also check that the result of each method is "good" before calling ...
0
votes
0answers
19 views

Swift: Looking for Advices to Eliminate Code Duplication in CollectionView Layout Change

I am looking for best practice suggestions to eliminate code duplication.I have several different CollectionView Layouts LineUps to change the position of players onto a football field.I can ...
0
votes
3answers
41 views

In which way I can write down for-loop with List in Java?

Is it possible to use Lambda expression or better way to write down the for-loop?public TaskDTO convertToDTO(Task task) {for (int i=0; i < task.getPrecedingTasks().size(); i++)...
0
votes
1answer
25 views

new props type react component syntax, make stateful class component from JS function

Consider this react Component code syntax which include prop-type:import PropTypes from 'prop-types';class MyComponent extends React.Component {render() {const children=this....
1
vote
3answers
70 views

Refactorisation of an if Block

In the following code I have 2 if block.A, The first return the error when the object is null.B, the second will try to send the object and if it' fails then return and error. It should be executed ...
3
votes
1answer
93 views

Design pattern to refactor code with nested if else and switch statements

I have to refactor a bulky existing code. Gone through a lot of similar questions on SO and other sites, still confused. If anyone can put some light or any idea will be of great help.There are 5 ...
0
votes
1answer
20 views

How to change eval statement to es6 syntax?

I have this function with an eval function, it's working fine evaluating the function defined in the string with the expected 'value', but do not understand why the variable between quotes 'value' is ...
1
vote
1answer
42 views

Thread-safe Factory pattern without control over Derived classes

Say I have a class 'Car' with a complicated tree of subclasess. Each class has a unique id. I have a management class that keeps track of pointers to all cars and can look them up based on the id. ...
1
vote
0answers
38 views

Splitting linq code into smaller methods: type definition noise

I make extensive use of linq for my calculation code (accounting-related). Because of common 'rule' that method body should not exceed 1 screen, I decided to split my lengthy linq-based method into ...
-1
votes
1answer
36 views

Refactoring design: abstract/interface/none?

First, have a look at my UI since it'll help you understand the problem:You'll understand that by selection one of the other, you end up with a set of similar actions with the same goal, but ...
1
vote
1answer
35 views

How to decide whether one class is a cohesive part vs dependency of another class (In terms of unit testing)?

Right now I'm working on a project that was not disigned with unit testing in mind (I'm new to unit testing btw). Since inside of StartWorking() method I create a new instance of WorkYear and call ...
1
vote
0answers
28 views

refactoring Rxjs observables using functions that make semantic sense and reduce mess

I want to refactor a chain of observables so that thay make semantic sence, my code looks close to thishttp://Ajax call that gets the users datathis.getUser.pipe(flatmap((user)=>{//...
0
votes
0answers
12 views

Can I run Python 2.7 and Python 3.6 builds on same installation of anaconda? How?

I currently have a Python 2.7 build of anaconda. But I'm facing issues following some other Python 3.6 codes. So, I am looking for a solution by which I can keep both versions of anaconda running in ...
1
vote
1answer
30 views

In VS Is there a way to change all derived classes method arguments at once?

Basically the title. But I will provide an example in case I didn't word it correctly.public abstract class A{public abstract void Method(Foo foo);}public class B : A{public override ...
0
votes
0answers
27 views

Automated refactor of MyEnum.MyValue.ToString() to nameof(MyEnum.MyValue)

All throughout our legacy codebase, we use syntax like:MyEnum.MyValue.ToString()to get the string value "MyValue" frompublic enum MyEnum{MyValue,...}Per this, I would like to ...
0
votes
2answers
32 views

Clean way to push results of multiple methods into an array

I have the following Ruby code, which calls the same function multiple times with different arguments, and pushes the results into a common array.people_relations=[]people.zip(people_addresses)....
2
votes
2answers
89 views

Fixing repetitive methods in ruby

I'm writing an API in ruby on rails, and I find that my methods are extremely repetitive. This is how almost all of my methods look like. They all follow a similar structure; I just grabbed one of my ...
0
votes
1answer
46 views

Nested Group by LINQ to Nested object

I am unable to solve this problem with the LINQ Query.So we have the table structure of Book as follows:LibraryId || LibraryName || ShelveId || ShelveName || Cost || Name || ForeName || StuffI ...
2
votes
2answers
71 views

C - Refactoring multiple OR in an if statement conditional

In an example like this, is there a nicer/better way to refactor all of the conditionals?if (memberStatus==bronze || memberStatus==silver || memberStatus==gold) {return 1;}return 0;
-1
votes
1answer
41 views

Refactoring classes: not able to move common codes of member function in derived classes back to the base class

I am trying to implement a C++ matrix library (https://github.com/statslabs/matrix) according to Ch29 "A matrix design" of book "The C++ Programming Language". And find that I am not able to move ...

153050per page
angop.ao, elkhabar.com, noa.al, afghanpaper.com, bbc.com, time.com, cdc.gov, nih.gov, xnxx.com, github.com,