Skip to main content
Share Your Experience: Take the 2024 Developer Survey

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
2 votes
1 answer
64 views

throwing an exception or returning Optional

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

How does one add observability to python code without affecting code quality?

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,915
-3 votes
2 answers
354 views

Is throwing an error in programming is good Idea at all? [duplicate]

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
81 views

Best practices for organising PHP files?

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 ...
Brian Smooner's user avatar
0 votes
1 answer
101 views

Return response from controller or raise exception from service

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
  • 931
1 vote
3 answers
413 views

Is low code quality and lack of testing the norm in B2B software development?

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
155 views

How to deal with very complex codebase? [duplicate]

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
81 views

Clean code: formatting rules, dependent functions, multiple calls [closed]

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
298 views

Does Clean Code suggest avoiding all base class instance variables (include private instance variables)?

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
12 votes
4 answers
5k views

Is there a clean way to model methods that only make sense depending on the current state of the object?

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
196 views

Is "the boolean value is from dynamic loaded data (eg:user input, database)" a reason to use boolean parameter?

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
3 votes
2 answers
4k views

How can I nicely pass on a class instance in python?

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
  • 203
2 votes
5 answers
157 views

Add new condition or create a separate method?

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
6 votes
2 answers
2k views

Key difference between Hexagonal Architecture vs Clean Architecture?

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
-1 votes
1 answer
136 views

How to integrate business logic from Domain layer with UI

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
139 views

Should you add the name of the package to the module/package name in Python? [closed]

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
199 views

Should we create a new function for every multiple conditions?

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

Is it okay to have misleading struct and function names for the sake of encapsulation?

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
11k views

Multiple boolean arguments - why is it bad?

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
252 views

Working with a poorly written piece of software as an entry-level developer with no support or documentation [duplicate]

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
18 votes
10 answers
6k views

Code readability and debugging

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
274 views

How to refactor this tightly-coupled method and (mostly) preserve its encapsulation?

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
281 views

Object matching using generic method? [closed]

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
893 views

How to write effective automated tests when building GPT4 powered software?

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
76 views

Avoiding repeating code when assigning pointer addresses based on branch

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
167 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, ...
Amal K's user avatar
  • 101
0 votes
1 answer
371 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 ...
Steve.NayLinAung's user avatar
-1 votes
1 answer
171 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 ...
elliot's user avatar
  • 11
1 vote
2 answers
242 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 ...
Lord Cat's user avatar
  • 139
1 vote
2 answers
548 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 ...
J. Lo's user avatar
  • 21
0 votes
2 answers
328 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" } ...
zhang's user avatar
  • 111
1 vote
0 answers
172 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 ...
z0mbieKale's user avatar
-1 votes
1 answer
107 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(...
elios264's user avatar
  • 167
1 vote
4 answers
322 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 ...
Gail's user avatar
  • 127
1 vote
3 answers
134 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, ...
Simone Brigante's user avatar
2 votes
2 answers
231 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 ...
Thiago Pereira Maia's user avatar
1 vote
3 answers
1k 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 ...
66Gramms's user avatar
  • 129
0 votes
1 answer
218 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()...
Mr. B.'s user avatar
  • 143
0 votes
3 answers
2k 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 ...
HFOrangefish's user avatar
4 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 ...
HFOrangefish's user avatar
1 vote
2 answers
910 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 ...
Amdguez's user avatar
  • 41
0 votes
1 answer
599 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 ...
DarkTrick's user avatar
  • 207
2 votes
4 answers
3k 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 /...
Pitto's user avatar
  • 141
1 vote
1 answer
414 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 ...
YozNacks's user avatar
  • 119
1 vote
1 answer
955 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 ...
CheeseS's user avatar
  • 19
-1 votes
1 answer
1k 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 &...
JetLeg's user avatar
  • 1
3 votes
2 answers
522 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 "...
SadClown's user avatar
  • 139
0 votes
1 answer
1k 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, ...
Andrew Stephens's user avatar
0 votes
1 answer
186 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 ...
Carlos Figueroa's user avatar
-4 votes
1 answer
706 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 ...
nirega's user avatar
  • 3

1
2 3 4 5
11