Skip to main content

All 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, ...
Saurav K's user avatar
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 ...
Justin Xu's user avatar
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) = ...
c-an's user avatar
  • 4,160
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() { ...
MAXIMAN's user avatar
  • 165
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 ...
KhoDis's user avatar
  • 151
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: ...
john doe's user avatar
-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 ...
sskoryi's user avatar
  • 11
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)) ...
Raul's user avatar
  • 3,101
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() {}...
Raul's user avatar
  • 3,101
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 ...
Jordi Verheul's user avatar
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 ...
Conchi Bermejo's user avatar
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 ==...
nikan's user avatar
  • 21
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: ...
user avatar
-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 ...
Victor Molina's user avatar
-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? ...
Martin Zeltin's user avatar

15 30 50 per page
1
2 3 4 5
9