All Questions
Tagged with refactoring coding-style
134 questions
-1
votes
1
answer
97
views
I want to add retry logic and. refactor the code in the python socket connect code
I have the below Python code which checks whether the ssh host is up or not:
`for hostname ,ipaddr in host_dict.items():
if tcp_conn.tcp_port_is_open(ipaddr, constants.TCP_PORT, ...
1
vote
0
answers
91
views
Refactor validation with return if statement
I have lots of method and on each method I have to do a validation. Currently, my code look like this and it works fine.
@Service
public class UserService {
@Autowired
private UserValidation ...
1
vote
1
answer
119
views
How can I refactor complicated method with views in Activity or Fragment?
I am learning Clean Code and Refactoring. And my project has many long method with view access, something like this.
private fun updateStatusFragmentUI(statusData: StatusListData.StatusData) =
...
2
votes
2
answers
1k
views
Where to put Laravel validation that is not related to column
For example, I have an HTTP request that handles some entity creation (let it be Role)
And validation looks like this:
class CreateRole extends FormRequest
{
public function rules()
{
...
0
votes
2
answers
199
views
Is there a short elegant way to write variable providing with exception?
So, I want to write these kind of things for my code, but there's too much code for one variable. How can I use modern Java for solving this problem shorter or cleaner? Moving it in the separate ...
1
vote
2
answers
154
views
avoid cheecking arguments correctness inside the function body
I recently noticed a function written earlier in our code base which I'm certain is logically incorrect. Function is written in TypeScript and its body goes like this:
const getUserInitials = (user: ...
-1
votes
1
answer
96
views
How to make this code more clear and flexible?
The task is to calculate money cost based on passed distance.
Here is tariff plan:
1-100 kilometres evaluates to 105 USD
100-300 km evaluates to 55 USD
300-any evaluates to 30 USD
If passed distance ...
2
votes
1
answer
109
views
Javascript - Refactor (if statement, spaghetti code) using map
I have the following code:
for (const element of elements) {
try {
// eslint-disable-next-line no-await-in-loop
const { a, b, c, d, e } = await func(element.id);
if (tokens.includes(a)) ...
0
votes
1
answer
491
views
Javascript (Node.js) - Refactoring a long function
I have a function, which is associated with a specific concept "Notifications".
After creating a module "Notifications.js", I have written the following:
function Notifications() {}...
0
votes
0
answers
189
views
Javascript files are automatically changed by eslintrc.json
In visual studio 2015 we have a solution with c# and javascript files. For the javascript files, we use a .eslintrc.json file for code conventions. However, everytime I build the solution, these files ...
0
votes
2
answers
293
views
Javascript (React.js) - Refactor a switch-case
I am creating a tab navigator which listen to my database and renders 5 different icons, one of them with a badge.
Currenlty, I am making this with a switch-case, to avoid returning the same component ...
0
votes
2
answers
160
views
How I write a clean condition from a "complex" combinations of conditions with && or ||
For example, a have two statement conditions:
First, something similar to
const condition1 = value === '' && value1 === '' && value2 === '' && valu3e === '' && value4 ==...
3
votes
1
answer
11k
views
Design Patterns for dependent sequential validation
I have three validators each sequentially dependent on the previous. I might use all three or only the first two or only the first one. E.g.
Validator 1: Checks whether user exists
Validator 2: ...
-1
votes
1
answer
68
views
(Node.js) Splitting JS class into modules
I have a class "Firebase" in which I write all the functions (that involve this service) used in my server side.
At first, the code was pretty clean and clear, as there were not a lot of ...
-1
votes
3
answers
295
views
How to refactor a long function?
I have a function that prepares a receipt output. But since it has all kinds of conditions it ends up being very long and difficult to understand..
How would one go about refactoring this? Any ideas?
...