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.
536 questions
1
vote
1
answer
222
views
How should domain models be designed — rich domain models with encapsulated logic vs. anemic models with separate service/util layers?
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 ...
2
votes
3
answers
1k
views
Scope of integration tests
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
-&...
0
votes
2
answers
364
views
Which is better: a chain of OR statements or IF in a loop? (Java)
Which code style is preferred in Java?
final boolean result = isCausedBy(e, ExceptionType1.class)
|| isCausedBy(e, ExceptionType2.class)
|| isCausedBy(e, ExceptionType3.class)
|...
2
votes
1
answer
243
views
checkNotNull vs. JEP 358: Helpful NullPointerExceptions: Should we remove existing null checks?
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 ...
2
votes
4
answers
205
views
Where are random numbers generated in Clean/CQRS architected application
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 ...
2
votes
1
answer
174
views
Should I create another API to “move” content or modify my existing API that already does something similar?
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 ...
0
votes
0
answers
106
views
Is it really difficult to test these “Service” methods in this Rust Clean Architecture proposal? Is there some other catch I'm not considering?
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 ...
5
votes
1
answer
576
views
Confused on how abstraction and encapsulation is helpful
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 ...
-2
votes
1
answer
524
views
Defining functions inside vs outside a class
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 ...
5
votes
1
answer
512
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 / ...
-1
votes
1
answer
249
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 ...
1
vote
3
answers
481
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 ...
-2
votes
1
answer
124
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
...
13
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 ...
6
votes
2
answers
13k
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 ...
10
votes
2
answers
10k
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 ...
0
votes
1
answer
373
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 ...
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 ...
1
vote
1
answer
292
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 ...
0
votes
2
answers
383
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()...
3
votes
3
answers
1k
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 ...
3
votes
1
answer
306
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, ...
-1
votes
1
answer
217
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 ...
1
vote
2
answers
640
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 ...
1
vote
0
answers
224
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 ...