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
4 answers
186 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 /...
user avatar
  • 131
1 vote
1 answer
105 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 ...
user avatar
  • 119
1 vote
1 answer
226 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 ...
user avatar
  • 19
0 votes
0 answers
18 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 - ...
user avatar
  • 231
-1 votes
1 answer
96 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 &...
user avatar
  • 115
0 votes
0 answers
44 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 ...
user avatar
2 votes
2 answers
151 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 "...
user avatar
  • 129
0 votes
1 answer
130 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, ...
user avatar
0 votes
1 answer
78 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 ...
user avatar
-4 votes
1 answer
86 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 ...
user avatar
  • 3
7 votes
6 answers
329 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. ...
user avatar
  • 187
2 votes
3 answers
375 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 ...
user avatar
  • 147
2 votes
2 answers
147 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 ...
user avatar
  • 209
31 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 ...
user avatar
  • 965
0 votes
2 answers
691 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,...
user avatar
-2 votes
2 answers
123 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 )...
user avatar
2 votes
3 answers
679 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 ...
user avatar
1 vote
1 answer
195 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 ...
user avatar
0 votes
2 answers
209 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 ...
user avatar
  • 161
-1 votes
1 answer
176 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({ ...
user avatar
  • 161
0 votes
0 answers
38 views

Should ad-hoc values live in the component as class members, or not?

Say we have a recipe website with a recipe-list component which loads onto itself cards of individual recipes: <ul class="recipe-list"> <li *ngFor="let recipe of recipes"...
user avatar
  • 167
0 votes
1 answer
88 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 ...
user avatar
-1 votes
3 answers
180 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 ...
user avatar
  • 117
0 votes
1 answer
281 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 ...
user avatar
  • 197
0 votes
5 answers
80 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 (...
user avatar
0 votes
1 answer
147 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 ...
user avatar
2 votes
2 answers
486 views

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

I am focosing on learning better design and wondered if this code is good or an antipattern? The function validate return true if data is correct, else it will throw an exception with a message to ...
user avatar
  • 53
4 votes
2 answers
291 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 ...
user avatar
  • 167
1 vote
1 answer
72 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 ...
user avatar
  • 121
-3 votes
1 answer
88 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 ...
user avatar
  • 103
3 votes
3 answers
370 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 ...
user avatar
  • 181
1 vote
2 answers
148 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 ...
user avatar
  • 41
6 votes
8 answers
813 views

Java instanceof and Clean architecture

It seems to me that there is a conflict between clean architecture and the recommendation not to use instanceof. Consider the following code: class ParentEntity { } class AEntity extends ParentEntity ...
user avatar
  • 199
0 votes
0 answers
32 views

best approach of passing arguments from usecases to repositories

I want to pass interface as a request in my use cases and repositories while following the clean architecture in flutter hence my method signature is as follows for usecases and respositories ...
user avatar
  • 121
0 votes
1 answer
100 views

Should I define a separate interface for clarity rather than implementing Supplier<T>?

Let's say you have to meet some prerequisites before doing something. For that, I think implementing Supplier<Boolean> is a great candidate since it's widely used, and quick to understand. But, ...
user avatar
  • 101
-3 votes
1 answer
103 views

Assumptions versus no assumptions - where do you draw the line? [closed]

In our line of work as software engineers, we can write code that assumes various things outside its scope or architectural boundary, in order to save performance, time, and on defensive coding ...
user avatar
0 votes
2 answers
85 views

Why doing more than one thing in a class is sometimes valid? [duplicate]

classes and method should do one thing like the code below: class A { public int a() { b(); } private int b() { c(); } private int c() { } } The code mentioned below I found it ...
user avatar
2 votes
2 answers
264 views

Should "add" methods return the update object? [Java - Clean Code & Best practices]

I'm following a course on Udemy and the teacher said that is a best practice return the update object in an add method. This is the example: public Recipe addIngredient(Ingredient ingredient) { ...
user avatar
  • 181
4 votes
3 answers
486 views

Steps to achieve the best code quality?

Currently I'm on a project where my objective is to obtain the best code quality. We have unit, integration & e2e testing. The e2e tests are written by the Business team in cucumber and these ...
user avatar
  • 148
-1 votes
2 answers
693 views

Clean Architecture, good approaches to avoid hard-coding the creation of entities on the Use Case

I have an Use Case that has an UseCaseInput (which is a parameter object of the use case) and an UseCaseOutput which is the output object, the UseCaseInput has lots of parameters in which will be used ...
user avatar
2 votes
3 answers
360 views

Versioning a function/method

While this might seem more like a piece of an easy task to others, it's honestly not easy for me. At this stage, I find myself wandering how best to version my functions/methods. What does this mean? ...
user avatar
  • 141
1 vote
1 answer
67 views

Adapt very different adapters to an Interface

I'm building a service to send push notifications to the user. At first, I designed an Interface for the push notification adapters, something like this: interface PushNotificationAdapterInterface { ...
user avatar
0 votes
2 answers
68 views

React: Ternary operator within component vs outside component

I have a pull request and this pr is being reviewed by co-worker. Context I'm using React and a specific component has ternary operator within component like below. const ExampleComponent = (): React....
user avatar
  • 121
0 votes
2 answers
77 views

Should we put behaviors (method) in constant class in Java?

Should we put behaviors (method) in constant class in Java? If not then why? Which clean code practice/principle I am breaking while doing that? public class TagConstants { public static final ...
user avatar
28 votes
7 answers
6k views

How does this switch statement do "multiple things"?

This doubt is about Switch Statements from Chapter 3: Functions of the book named Clean Code Here we have a function: public Money calculatePay(Employee e) throws InvalidEmployeeType { switch (e....
user avatar
10 votes
5 answers
2k views

What does "If a function does only those steps that are one level below the stated name of the function, then the function is doing one thing" means?

This doubt is about function doing one thing from Chapter 3: Functions of the book named Clean Code Here Uncle Bob is talking about this function: public static String renderPageWithSetupsAndTeardowns(...
user avatar
1 vote
1 answer
183 views

How to declare a lot of variables under line length restrictions?

I need a good approach to declare a lot of variables over a context. For exmaple in kubeflow, I need declare a pipeline with a lot components in order to do that, I use the following code: ...
user avatar
  • 369
0 votes
3 answers
81 views

Designing this module to support exchangeable drivers

We have a battery manager implementation which uses a fuel gauge driver and a charger driver. Currently both of these drivers are hard-references to the fuel gauge and charger driver we currently ...
user avatar
  • 95
41 votes
8 answers
6k views

Getting buy-in for cleaner and more structured code

I am at my company for half a year now and think that I have gotten a fair idea of their codebase. Initially I didn't dare to form strong opinions, but now I start to feel that the code could benefit ...
user avatar
1 vote
1 answer
282 views

Clean Code: two types of arguments

I read Robert Martin's Clean Code: Function chapter. In this chapter, the best number of arguments of function is single argument. So, it is good to abstract that argument and function should be ...
user avatar
  • 121

1
2 3 4 5
10