Questions tagged [clean-code]

The term "clean code" is used to describe computer programming code that is concise, easy to understand, and expresses the programmer's intent clearly. Questions with this tag relate to the process of writing clean code, or refactoring old "dirty" code to be clean code.

Filter by
Sorted by
Tagged with
0 votes
0 answers
25 views

Android, are seperate state update functions a DRY violation?

In my ViewModel I’ve implemented couple of functions to manipulate the state of my UI. It quickly becomes bigger and bigger and I wonder if these functions violate the DRY principle? I could wrap it ...
  • 1
1 vote
1 answer
76 views

Composite repositories: minimizing dependency injections

I have an application with dependency injection that consumes a REST API. The API calls are abstracted into entity-specific repositories. Some of the repositories are: HttpNotebookRepository, ...
  • 91
0 votes
1 answer
50 views

Separating Application (Business Logic) Layer to Multiple Module Layers in Clean Architecture

Currently, I'm designing the Project based on Clean Architecture composing with 4 layers: Domain Application Infrastructure Presentation Since the project is pretty huge, I'm now considering to ...
-1 votes
1 answer
71 views

What is point of having certain microservices making another API call in the same service

I was going through an old, largely untouched part in my company’s codebase and found one API. It does the following things. A POST API with path host/entities/trigger which fetches a list of entity ...
  • 11
1 vote
2 answers
62 views

Best practice for updating object fields (with values calculated in methods)

What's the cleanest and most coherent way to assign a new value to an object field when the calculation of that value is outsourced to another method? The most obvious way would just be to update the ...
  • 139
1 vote
2 answers
333 views

Software Design: Decoupling when highly dependent on a third party library

As part of an university project I am currently working on an eeg-biosignal classifier. While the project itself doesn't really focus on design ("anything that works") I am trying to learn ...
  • 21
0 votes
2 answers
149 views

Is there some easy way to refactor deeply coupled python code

I recently took on a long ago python project which has some weird code style that I can't pinpoint. e.g. # this is a params and value package? opts={ infile="xxx", outfile="xxx" } ...
  • 11
1 vote
0 answers
101 views

Typescript Clean Architecture: How to tackle use case that needs multiple repositories?

I am implementing clean architecture in my new back-end project and getting stuck with a particular use case. I have a CreatePhysicianUseCase what is responsible for creating a new physician user in ...
0 votes
0 answers
40 views

Hosting/Imbedding Angular Application in ASP.NET MVC Application

Currently, I am working on an existing project, my team creates a new Angular-based application with the usage of some Angular modules that are developed in the company, in addition, there are some js ...
  • 124
-1 votes
1 answer
94 views

Using helper libraries to improve readability and conciseness of code vs adhering to native functions

currently in my place of work I'm headbutting with some coworkers from other teams (but same repo), since they are in a line of thinking where they prefer this: const connectionList = Object.values(...
  • 167
1 vote
4 answers
267 views

Looking for a sanity check, do you alphabetize your code? Is that even a thing? [closed]

I'm currently working with a group of developers (as outside contractors) on an existing codebase (in kotlin) and the lead dev (the client) is blocking merging of pull requests (GitHub) because ...
  • 127
1 vote
3 answers
79 views

Separating network logic from business logic

I am creating a simple P2P file sharing system, where one peer can send some Objects (e.g., String, custom objects, etc...) to another peer. The peer, that receives the Object, can then manipulate it, ...
2 votes
2 answers
178 views

Should I abstract function calls with duplicate arguments?

I have an intuition, that I'd like to read what others have talked about. To me, it seems fairly intuitive that when you have a function which is called multiple times with the same arguments, it ...
1 vote
3 answers
347 views

Const function that change other objects' states

Is it a good idea to mark a function const from clean code perspective if it change other objects' states? I'd like to know what is the experience with this or is it considered a bad practice for any ...
  • 119
0 votes
1 answer
131 views

Where to create repository instances?

I've several repositories. To make them testable, I add the ORM session in the constructor. class Repository: def __init__(session): self.session = session def save(object): self.session()...
  • 143
0 votes
3 answers
505 views

Optimizing a string to enum converter [closed]

I have built a string to enum converter, which converts a known set of strings that it receives into enum, in order to satisfy a function pointer. Some of you may recognize some elements of this ...
3 votes
5 answers
2k views

Alternatives to if-else on data reading

I have some code on Arduino (so, written in C++) that receives a String through the UART terminal, reads the String, then decides what String to print back and how many things to print depending on ...
1 vote
2 answers
212 views

Modules Design and Communication Between Them

I'm trying to design a monolithic application following DDD and clean code. Lets say I have Users, User Types, Products, Product Types and Purchases. I want to implement using different modules. At ...
  • 31
0 votes
1 answer
454 views

Clean Architecture for React App: Component / View / Page

Abstract I'm trying to figure out a solid, scalable, clean and practical architecture for react projects. As a a playground I have a project with two Screen and a JSON server. When I try to apply a ...
  • 207
2 votes
4 answers
849 views

Code smell java:S115 - Constant names should comply with a naming convention

In my Java 11 / Spring Boot codebase I have enums that don't respect the convention to have all uppercase constants because when we move to frontend the data there has to be camelCase (or even random /...
  • 141
1 vote
1 answer
169 views

What to name class that applies methods of another class?

This is a pretty vague question, but, sometimes, I'm not very good at naming specific tasks, but I know it's very important and I don't want to name it something ungood. I have the following file ...
  • 119
1 vote
1 answer
432 views

How to avoid argument drilling when subdividing functions?

As suggested by Uncle Bob in his book "Clean Code", I am actively trying to keep my functions small and readable. However, I often encounter arguments drilling when I try to refractor a big ...
  • 19
0 votes
0 answers
25 views

Mapping data that were input to one module, to input to of module

Lets say we have typical trivial CRUD app: user sends data controller catch the request and map it controller sends data to service for processing structure: - api - request - ...
  • 231
-1 votes
1 answer
499 views

Clean code about constants in Python

My question regards to constants in Python. Which is more "convenient" or "acceptable" among software engineers in general: Putting classes of constants in another file called &...
  • 115
0 votes
0 answers
45 views

Refactor conditional multiple AND OR operations? [duplicate]

I have a piece of code where two objects (incoming request object and a profile object) are to be checked for matching conditions. So the first method is as below where I check whether the profile ...
3 votes
2 answers
273 views

What is the alternative to checked exceptions in API/interface design?

Despite checked exceptions being generally bad practice and anti-pattern, I find one feature very useful: having list of checked exceptions part of function signature. Checked exceptions are "...
  • 139
0 votes
1 answer
462 views

Clean code and SOLID principles in WPF/MVVM view models?

I'm currently reading "Clean Code" by Robert Martin (which I should have read years ago), and it's given me a bit of a wakeup call, especially regarding keeping methods and classes small, ...
0 votes
1 answer
91 views

Verbs in Use Case name "Create User" [closed]

I'm struggling on how to name classes for use cases. Because I know that is "bad" to use verbs in classes names(Uncle Bob) but at the same time names of use case classes should explain what ...
-4 votes
1 answer
182 views

Pass a value to a class via a constructor or a method? [closed]

I'm newbie in Java and I have question. Pass a value to a class via a constructor or a method? public class HelloWorld{ public static void main(String []args){ TextModifyFirstVersion ...
  • 3
7 votes
6 answers
390 views

Can Data Abstraction Violate the Interface Segregation Principle?

I'm reading Clean Code In Chapter 6, Objects and data structure First talk about Data Abstraction: Hiding implementation is not just a matter of putting a layer of functions between the variables. ...
  • 187
5 votes
4 answers
2k views

How to model 1 to many relationships in DDD (Domain Driven Design)

I think I am struggling to model a relationship between 2 entities. I am trying to do so in a way that promotes DDD and captures business semantics. The following is my business context: I am ...
  • 203
2 votes
2 answers
210 views

Should you create your own Interface for all (most/many) Api Calls? (Adapter)

I am currently reading Clean Code by Robert C. Martin and in Chapter 8: Boundaries one can find this paragraph: We wanted to tell the transmitter something like this: Key the transmitter on the ...
  • 239
32 votes
6 answers
7k views

Do inline expressions obstruct readability of code?

Currently, I'm reading "Code Complete" by Steve McConnell, 24.3 chapter "Specific Refactorings". I've become kind of confused with 4th paragraph, that looks like: Move an ...
  • 995
0 votes
2 answers
700 views

Is this a case where 'else' is inevitable?

I am writing some code that enables / disables a certain kind of hardware function. To enable it on, I have to call some methods, and to disable it, some others. Of course I want this code to be clean,...
-2 votes
2 answers
128 views

Guidance on naming methods that check data quality and then executes logic [closed]

I'm writing boolean methods that do a data quality check and then performs logic. such as isRecordValidAndIsUserPrivilaged. these methods checks the record validity, and then checks the user's access )...
2 votes
3 answers
4k views

Are 10,000 lines of code in a file "too much"? [closed]

I am a junior iOS developer and here at work I find huge files with sometimes over 10,000 lines of code. Is it a good practice to put this many lines in a single file? Or is it too much. Is there any ...
1 vote
1 answer
280 views

Circular references with generic classes

I'm trying to create an interaction system for a game I'm developing with Unity and C# and I've been struggling with it for a while now. It consists of interactors and interactables. The idea is that ...
0 votes
2 answers
479 views

Sharing logic / services across modules in "clean" architecture [closed]

I am trying to implement a layered architecture consisting of; Controller, Service, Repository, Entity. Each module has at least some of the above layers. I am often finding that modules need to share ...
  • 181
1 vote
1 answer
530 views

How to use external validation libraries for entities in a "clean" architecture?

I would like to make use of a external library to parse the core domain entities. Doing this in a naive way it would look like the following: import { z } from 'zod'; const Audience = z.object({ ...
  • 181
0 votes
1 answer
179 views

Clean code: Register listeners inside class handling events, or outside?

I'm writing a Java program with a custom event manager, which is of course the observer pattern. Should the calls to add event listeners/handlers be in the classes that listens/handles the events ...
-1 votes
3 answers
200 views

How to improve coding while/though working? [closed]

How could I improve my coding skills aka skills in coding while being in a job? My job is mainly coding and so, my coding should be better and better over time. But the struggle is: There are always ...
  • 117
0 votes
1 answer
293 views

Is there a reason why you shouldn't use 'integration variables'?

I tend to create a variable whenever I need an uncircumstantially same value as to that of an earlier value more than once (the values are not happening to be the same by chance rather they actually ...
  • 197
0 votes
5 answers
103 views

best practice for error handling between PAM_SUCCESS and PAM_AUTH_ERR macros

We have two exit code code PAM_SUCCESS(0), PAM_AUTH_ERR(7). If we wanna return 0 or 7 when we compared password with our password in following code which code is better that this code ? if (strcmp (...
0 votes
1 answer
163 views

Designing functions with separation of concern in mind

Is there a name related to the pattern shown in the code that follows? Or is there writing/thinking on the [design of] code shown that suggests it is an anti-pattern? In general, I'm curious if this ...
5 votes
2 answers
1k views

Is returning true or throwing an exception good or bad code practice?

I am focusing on learning better design and wondered if this code is good or an anti-pattern? The function Validate() returns true if the data is correct, else it will throw an exception with a ...
  • 83
8 votes
2 answers
705 views

Should function names describe their parameter types?

If you wish to perform the same action using different parameters, you can either make differently named functions: public Apple findAppleById(long id){ return repo.findById(id); } public Apple ...
  • 207
1 vote
1 answer
80 views

What is the best approach to use a common variable in multiple method in a request in laravel [closed]

I have a $c variable that is calculated at the beginning of the request. After calculating this several nested methods use it as a part of their job. Is it better that I pass down the $c variable to ...
  • 121
-3 votes
1 answer
171 views

Whats the purpose of use-case and data-sources?

I have a question about where should I get the info required for making an api call. Let's say I have this : Presenter --> Use Case --> DataSource --> Api Ok now to do my api call, I need a ...
  • 103
3 votes
3 answers
396 views

Is a good practice reuse HTTP codes to encode something else?

As we know HTTP codes are used in HTTP response. Usually with this code we can have an idea about what happened. For example if I make a get request and I obtain a 404 I can figure out that the ...
  • 191
1 vote
2 answers
211 views

Granularity of a Method

I have a general design question. Suppose I have a List: List<String> list = new ArrayList<>(); list.add("Str 1"); list.add("Str 2"); list.add("Str 3"); I ...
  • 41

1
2 3 4 5
10