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
2 answers
207 views

hexagonal architecture vs clean architecutre

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
95 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
  • 141
-1 votes
1 answer
75 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
189 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
10k 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
237 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
195 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()...
youngson's user avatar
0 votes
4 answers
278 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
667 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
73 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
0 votes
0 answers
30 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 ...
deja's user avatar
  • 1
2 votes
1 answer
122 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
  • 91
0 votes
1 answer
200 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
112 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
85 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
426 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
219 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
141 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
0 votes
0 answers
47 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 ...
genichm's user avatar
  • 124
-1 votes
1 answer
102 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
291 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
108 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
201 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
712 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
154 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
1k 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
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 ...
HFOrangefish's user avatar
1 vote
2 answers
456 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
528 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
2k 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
283 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
651 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
808 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
0 votes
0 answers
47 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 ...
Siddharth Trikha's user avatar
3 votes
2 answers
378 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
756 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
119 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
410 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
7 votes
6 answers
411 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. ...
hamid_c's user avatar
  • 187
6 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 ...
alaboudi's user avatar
  • 213
2 votes
2 answers
283 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 ...
SirHawrk's user avatar
  • 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 ...
CoderDesu's user avatar
  • 1,005
0 votes
2 answers
706 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,...
Bart Friederichs's user avatar
-2 votes
2 answers
132 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 )...
PartOfTheOhana's user avatar
4 votes
3 answers
6k 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 ...
Noob_iOS_Dev's user avatar
1 vote
1 answer
385 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 ...
Wojtek Wencel's user avatar
0 votes
2 answers
673 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 ...
dendog's user avatar
  • 191
1 vote
1 answer
740 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({ ...
dendog's user avatar
  • 191

1
2 3 4 5
11