Most voted "refactoring" questions
Refactoring is a disciplined technique for restructuring an existing piece of code, altering its internal structure without altering its external behavior. Use this tag for conceptual questions about refactoring, not for help with refactoring a specific code.
Learn more…33 questions
Sort by count of
-
24
votes7
answers59028
viewsRefactoring function to remove punctuation, spaces and special characters
I have this function already too old to "clean" the contents of a variable: Function function sanitizeString($string) { // matriz de entrada $what = array(…
-
14
votes6
answers1877
viewsCode refactoring to convert GPS coordinates into DMS format into an array
The user can enter GPS coordinates in two ways, Decimal Degrees or Degrees, Minutes, Seconds: ┌─────────────────────────────────┬─────────────────────┐ │ DMS (Degrees, Minutes, Seconds) │ DD…
-
12
votes4
answers172
viewsRewriting vs Incremental Improvement?
In the place where I work I am implementing new features in a legacy system. The system in question was written around 2008. Some problems encountered in the system: Database tables with 90+ columns…
-
9
votes3
answers388
viewsRefactoring of a java class
I have a Java class that contains 1756 lines (obviously not all code, has blank lines, many comments and some commented code in case it is needed in the future) I’m implementing the structure MVC…
-
8
votes5
answers436
viewsRefactoring: When is a method "too big"?
I’m with a project that "recovers" certain information from an HTML page, makes a parse with the help of Beautiful Soup and return the values in the form of Dictionary, so that in another method I…
-
7
votes4
answers714
viewsTrying to condense conditional with three possibilities
The problem is to present a result flexing to the plural if necessary, or "no": Let ni>=0 (number of items): switch(true){ case $ni==0: $html = ' (nenhum)'; break; case $ni==1: $html = ' (1…
-
6
votes1
answer307
viewsPHP code refactoring to provide image with specific size
The code below aims to provide an image with specific measures to minimize its size and thus optimize the web-site loading. Problem The image takes more than 1 second to be provided, making it a…
-
5
votes1
answer235
viewsCreation of Table of Games
I wrote this code to organize the teams that will face each other in the Cup: <script> var dados = { "grupo1" : [ {"selecao" : [{"nome":"brasil"},{"resultado" : [{"a":0},{"a":4},{"a":2}]}]},…
-
5
votes3
answers1142
viewsAdapt query to create VIEW that returns sum of count of two Subqueries
Of agreement with the documentation, Mysql does not allow the use of Subqueries in the FROM when the consultation is a view: Subqueries cannot be used in the FROM clause of a view. Resulting in the…
-
5
votes2
answers163
viewsHow to enumerate bad Smells in a software?
I am working on a relatively large system (considered unworkable rewriting effort) PHP that implements in a certain way the MVC architectural pattern and that has (under a higher point of view)…
-
5
votes1
answer557
viewsIs it recommended to manipulate rules with "Try-catch"?
We can manipulate errors in various ways, but the one that will use less code and time of the programmer is the try, present in almost all object-oriented languages. But, when should be used try,…
-
4
votes1
answer164
viewsHow to add a class to multiple cached elements at once?
In jQuery, we can add CSS classes to multiple elements, but with the element already cached in a variable, as we can perform the same operation? Example: // adicionar classe a ambos os elementos…
-
4
votes3
answers157
viewsRefactoring function to collect constants with a certain prefix
I have a function that aims to locate and group in a matrix the constants that are declared corresponding to a certain prefix: Function: function get_constantsByPrefix($prefix) { foreach…
-
4
votes3
answers271
viewsGet List Help (Code Refactoring)
I have a class with 2 attributes: public class Classe(){ private String conteudo; private String tipoConteudo; getters...setters.. } So I have a Arraylist with 3 or more objects of this class, as I…
-
4
votes2
answers220
viewsAlternative to create a new method in a String object?
I have the following situation: I have a txt file of defined positions (type CSV, CNAB, etc) to process and extract values. For the purposes of understanding, follow the code I made and it’s working…
-
3
votes1
answer377
viewsDefine multiple variables in one row only
I would like to parse a single line and break a string into several variables. In string which I will parse, the default is that each field is separated by a comma. In several lines, the code to do…
-
3
votes1
answer157
viewsDatabase query refactoring with multiples FIND_IN_SET()
I have the following query to find related topics by a set of ID’s that are not the topic to be viewed: SELECT press.image, press_i18n.title, press_i18n.slug FROM press INNER JOIN press_i18n ON (…
-
3
votes1
answer58
viewsCheck that process is running without bumping into the 15-character limit
With the following code we check if a process is running: #!/bin/bash #Verificar se processo abc está em execução if pgrep "abc" >/dev/null 2>&1 then printf "Está em execução.\n"…
-
3
votes1
answer173
viewsHow to Refactor Legacy JS to Implement Unit Tests?
I have a Wordpress site with many JS files that have not been structured to be tested - they have not been written as modules that can be imported nor is there a app.js that loads them all as a…
javascript unit-testing refactoring jasmine jestasked 6 years, 5 months ago Ricardo Moraleida 4,005 -
3
votes1
answer57
viewsHow can I refactor this vuex Mutation?
I have the following scenario: I’m manipulating the object namespaced questions, within it exists list and news, want to create a mutation that adds a key value pair in questions within those two…
-
2
votes3
answers400
viewsRefactoring with eclipse
By itself the eclipse already has the necessary for refactoring or you would indicate some tool to attach to the eclipse editor and use it more accurately?
-
2
votes1
answer161
viewsRefactoring Python code
How do I improve this code? import random import string import requests from django.core.management.base import BaseCommand, CommandError from django.core.exceptions import ValidationError from…
-
2
votes1
answer253
viewsWhen should a utility class become an injectable dependency?
I often write small utility classes to solve some minor problem in my code. For example (I will use Spring for DI): @Service class PessoaService { public PessoaResponse converter(Pessoa pessoa, Long…
java spring unit-testing dependency-injection refactoringasked 6 years, 10 months ago Dherik 10,372 -
1
votes3
answers173
viewsAre there any techniques to apply maintenance in the code?
Besides applying high cohesion and low coupling, how to handle codes like this? They may even be legible but this excess of logical operators, I do not see it possible to refactor even with…
-
1
votes3
answers121
viewsHow can this be improved? (It’s just a little game)
I tried to make this game based on the Magic Cards. As I am still learning, that’s how I managed to do it. I would like to see other versions to know how I could have done and what I did of "wrong".…
-
0
votes0
answers28
viewsErrors to Refactor view html.erb
I got template ready (just for practice) but I’m trying a lot of difficulties to refactor it: CSS/JS are not compiling (I tried to go to css and js files and switch to the image folder path to…
refactoringasked 9 years, 2 months ago Moisés Lima 1 -
0
votes2
answers148
viewsCode refactoring in C
I was trying today to create a simple program and C with some colleagues and one of the questions was: No else if it would really be necessary to put the validations precoAtual >= 30 and…
-
0
votes1
answer68
viewsSwap operator + for - in refactored method
The Code below has the goal of making a move on an object on the Y axis of an object following the mouse (the code works), see that the code within the if and of else if are equal except by the…
-
0
votes0
answers99
viewsRefactoring a database using VIEWS
I have the task of refactoring a database and would like to know if VIEWs are viable for the task. My strategy is to create a VIEW imitating the new structure of the supposed table, at least the…
-
0
votes1
answer49
viewsWays to Refactor Long Forms?
I am having a very great frustration in creating new forms within my team’s project. We handle patient information, which means a lot of information. When we create the components of Forms for each…
-
0
votes1
answer44
viewsRefactor code using LINQ in C#
I need to refactor this method in C# and replace these 3 foreach with something smaller using LINQ: public List<Ponto> Filtrar(IQueryable<Ponto> pontosFiltrados, List<Usuario>…
-
-3
votes1
answer28
viewsHow to organize a Mysql table efficiently and scalably?
I am doing a refactoring in a system that has several with many tables that have many columns, that is, up to 148 columns in a table, how to refactor such table? This is the table CREATE TABLE…
-
-4
votes1
answer165
viewsI’m trying to apply object orientation to a Java program
I’m trying to apply object orientation to this program and I wanted to start with the exchange of these ifs, does anyone have any hint of what to put in place? import java.util.*; public class…