Skip to main content

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
1 vote
1 answer
225 views

I'm learning Domain-Driven Design (DDD) and studying different architecture patterns, and I’ve come across two seemingly conflicting design philosophies around domain modeling. 1. Rich Domain Model ...
Penchala Yegu's user avatar
2 votes
2 answers
154 views

So I was reading Eric Evans DDD book and one point that was not clear to me is which Layer (in case of using Clean Code) should be reponsible to: define the interface contract for an Entity (...
Prometheus's user avatar
2 votes
3 answers
1k views

I'm programming a .NET WebApi application from services. What is the scope of an integration test within the following schema? Order creation scenario: Order is created -> stored in db -&...
Petr Klekner's user avatar
6 votes
7 answers
720 views

According to Why is Clean Code suggesting avoiding protected variables?, I know there are tons of reasons to avoid protected variables. However, there is a reason at the currently highest voted answer ...
wcminipgasker2023's user avatar
0 votes
2 answers
364 views

Which code style is preferred in Java? final boolean result = isCausedBy(e, ExceptionType1.class) || isCausedBy(e, ExceptionType2.class) || isCausedBy(e, ExceptionType3.class) |...
Andriy Makukha's user avatar
2 votes
1 answer
245 views

With the introduction of JEP 358 in Java 14, which provides more informative NullPointerException (NPE) messages, is it advisable to remove existing explicit null checks in cases where the null-check ...
ftb457932's user avatar
0 votes
1 answer
112 views

I am developing a hobby project utilizing an event sourced + event based architecture. In this application, I can allow my users to schedule automated calls in the system. Once the call has been done ...
alaboudi's user avatar
  • 285
2 votes
4 answers
205 views

Assume I have a value object in my application with random numbers for underlying values. These value objects will serve as attributes to my entity (aggregate root). In my specific case (just for ...
alaboudi's user avatar
  • 285
6 votes
5 answers
839 views

Suppose, I have some method that performs some job. In this example, it's going to be void, but it doesn't matter public void doSomething() { // doing something } But then, let's imagine, I got ...
Sergey Zolotarev's user avatar
2 votes
1 answer
174 views

I have a Spring Boot REST API that will copy content from one Amazon S3 bucket to another. The source and destination buckets are specified in the body of a POST request sent to the API. This works ...
Space Cadet's user avatar
35 votes
11 answers
13k views

As developers, we often face the challenge of balancing meaningful variable names with code readability. Long, descriptive names can make code harder to read, while short names may lack context. For ...
Shardul Vikram Singh's user avatar
0 votes
0 answers
107 views

I reproduced a small example of kerkour's Rust Clean Architecture on the Rust Playground. The code is just an example and the methods code makes no sense at all. This architecture leaks DB information ...
Fred Hors's user avatar
  • 139
2 votes
3 answers
242 views

According to https://softwareengineering.stackexchange.com/a/212130/432039, if a class asks another class for the state, and then call methods of that class, it is called "feature envy", eg: ...
wcminipgasker2023's user avatar
5 votes
1 answer
576 views

Using assimp I've created a function to load 3D models and it does everything I need and I don't plan to use another library or write something custom, however, I am curious how techniques such as ...
Konjointed's user avatar
3 votes
3 answers
170 views

Each table is on separate pages. Is it considered duplication (written in Angular)? The DevOps team ran SonarQube and detected the th tags as code duplication. How can I explain to them that it's not ...
Shlomi Levi's user avatar
-2 votes
1 answer
533 views

Say I have a class with a function do_thing that is comprised of multiple steps, which themselves segregate into functions (first_process and second_process). At what point would this be considered ...
Tim Kirkwood's user avatar
4 votes
4 answers
1k views

In a service daemon coded in Java, we have services for getting various objects. When we use these services forgetting an object, I wonder if the method should return the object and throw an ...
kommradHomer's user avatar
5 votes
1 answer
514 views

We're working an agile project and designing as we go on a new python commandline app / systemd service for some fancy in-house project. Right now, we're supposed to be adding an observability / ...
Peter Turner's user avatar
  • 6,985
-3 votes
2 answers
817 views

I am wondering if throwing an error in programming is good Idea at all ? While programming we throw error when something unexpected or invalid has occurred. But if we have thrown exception and it is ...
FaisalAhmed's user avatar
-1 votes
1 answer
251 views

I am currently writing a PHP / JavaScript application library, which I intend to use in the future for several other applications. The library includes functionality for handling a database, creating ...
user avatar
0 votes
1 answer
140 views

I need some guidance on how to send error responses to client from WebAPI controller for an update operation. I need to check if data is changed and if it has duplicate data. I have service class that ...
Sunny's user avatar
  • 945
1 vote
3 answers
483 views

I've been working at this company for about a year now. it's a growth company working in B2B. I'm one year out of university, with a major in computer science. I work in the web team, using an Angular ...
Jeremaia Scott's user avatar
0 votes
1 answer
278 views

I recently changed my job to a big MNC and the code I am exposed to is highly complicated, difficult to read and understand. Although it is divided in microservices and runs on local I have to keep ...
Surya Saini's user avatar
-2 votes
1 answer
124 views

About formatting Here are two scenarios in which the details of the formatting are described. How should in the clean code way, this be formatted Scenario 1: Dependent functions of dependent functions ...
user13047397's user avatar
0 votes
2 answers
404 views

According to Why is Clean Code suggesting avoiding protected variables?, I should avoid protected variables because of the reason : "closely related concepts should not be separated into ...
wcminipgasker2023's user avatar
13 votes
4 answers
5k views

Let's say that I have a class called Mission. This class is intended to represent a mission requested by a professor working in a faculty. Mission has a private enum field representing whether the ...
Mehdi Charife's user avatar
0 votes
3 answers
252 views

I know there are some questions about boolean flags: Is it wrong to use a boolean parameter to determine behavior?, Multiple boolean arguments - why is it bad? which indicates the following code is ...
wcminipgasker2023's user avatar
6 votes
2 answers
13k views

I am rewriting a streamlit app that is an interface to a laboratory management system (LMS). This means, that I have to make a lot of requests to that LMS through its python library (PyBIS). The way ...
Jan's user avatar
  • 251
3 votes
5 answers
254 views

At first I had the following logic of user creation: class UserService { constructor(userRepository, postRepository) {} createUser({user}) { this.userRepository.create(user); } } Then I ...
eugenedrvnk's user avatar
10 votes
2 answers
10k views

I am trying to improve the architecture for my React app project that has grown in size lately. I'm looking at Hexagonal architecture and Clean architecture, and I couldn't really see the difference ...
rickvian's user avatar
  • 119
-1 votes
1 answer
201 views

I have a rich client with quite complex domain logic and I want to keep the domain and presentation layer separated. How would you advice to intergrate the domain logic with the UI in this case. I ...
Liero's user avatar
  • 140
0 votes
1 answer
373 views

I'm looking for some best practices for readability (and clean code in general) for naming modules/classes within more extensive projects. More specifically, is it reasonable to add the package's name ...
Thomas Vanhelden's user avatar
0 votes
4 answers
222 views

I have the existing code provided below: if (!$existing_records && !$has_required_field) { return 'Skip Update, no records found'; } elseif (!$existing_records && $...
Muhammad Dyas Yaskur's user avatar
9 votes
4 answers
3k views

I'm writing this library in which the user can provide custom code defining the algorithm used for finding an optimal solution. In the papers that I have read, the targeted user thinks in terms of ...
Mehdi Charife's user avatar
37 votes
11 answers
13k views

This seems to be a commonly encountered and brought up code smell, and is a common feature in multiple coding design books which I wasn't fully able to understand. Say I have a function def ...
Utsav Dutta's user avatar
1 vote
1 answer
292 views

I'm and entry-level developer straight out of college. I am the only developer at this company. I feel the challenges I face are different to most people working with sub optimal or very poorly ...
mpAppProg's user avatar
19 votes
11 answers
6k views

Sometimes, I have a hard time deciding between two good code traits: debuggability and readability. The snippets below are an oversimplification, but they illustrate my pain. Example 1: if(...
AndrasCsanyi's user avatar
0 votes
2 answers
386 views

I have recently encountered this problematic method (minimal reproducible sample in C++ but this question aims to be language agnostic past the syntax): void MyObject::twice_bind_cycle() { _bind1()...
goober's user avatar
  • 117
0 votes
4 answers
360 views

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 ...
Siddharth Trikha's user avatar
3 votes
3 answers
1k views

Part of my current product uses GPT-4 with a prompt to extract information from plain text. As behaviour of large language models is inherently opaque and failure cases unpredictable, I was wondering ...
Armin's user avatar
  • 65
0 votes
1 answer
86 views

I have the following code in C that reads data off a char array and makes decisions on what variables should some pointers point to. char preset1[20]; char preset1Name[20]; int preset1Temp; int ...
HFOrangefish's user avatar
3 votes
1 answer
307 views

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, ...
Amal K's user avatar
  • 111
0 votes
1 answer
611 views

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 ...
Steve.NayLinAung's user avatar
-1 votes
1 answer
217 views

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 ...
elliot's user avatar
  • 11
1 vote
2 answers
844 views

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 ...
Lord Cat's user avatar
  • 139
1 vote
2 answers
645 views

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 ...
J. Lo's user avatar
  • 21
0 votes
2 answers
725 views

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" } ...
zhang's user avatar
  • 111
1 vote
0 answers
225 views

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 ...
z0mbieKale's user avatar
-1 votes
1 answer
149 views

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(...
elios264's user avatar
  • 167
2 votes
4 answers
456 views

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 ...
Gail's user avatar
  • 137

1
2 3 4 5
11