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
12
votes
6
answers
4k
views
Passing Objects vs. Primitives
What is the best practice when it comes to passing variables around? Is it better to pass objects (models) or is it better to pass primitives that will be required by the called method? What are the ...
4
votes
1
answer
398
views
Dynamic Object Abilities When Saving State
I have n classes that extends from a State class, the purpose of the State class is to manage the state of the extended classes. For each class we need to save it in the database, remove it and select ...
10
votes
4
answers
3k
views
is this way of calling a function a bad practice?
I have the following code:
public void moveCameraTo(Location location){
moveCameraTo(location.getLatitude(), location.getLongitude());
}
public void moveCameraTo(double latitude, double ...
5
votes
1
answer
18k
views
Declaring constants: one file or separate?
I currently have a small list (< 20) of constants that can be segmented into the following three parts:
- main script (tokens, log file location)
- database setup (username, passwords)
- API (API ...
1
vote
2
answers
364
views
How to find already existing code | How to arrange code in a way it can be found again [closed]
I'm refactoring the framework of our company, trying to fix the issues we had in the past.
We're a team of 6 developers, and we have various needs and issues in regards to tidying up our framework.
...
4
votes
2
answers
116
views
How are settings structured when they can be configured in diffferent ways?
Suppose of this question the following:
I'm in full control of this project
I'm writing a media player
Obviously, a media player will allow a user to adjust the volume, so I might have a class that ...
0
votes
5
answers
3k
views
Is using the Pair class a sign of primitive obsession code smell?
Let's say I use a Pair in this way:
Pair<Long, Date> signup = getSignup();
System.out.println("User with ID " + signup.getLeft() + " signed up on " + signup.getRight());
Is it a form of ...
2
votes
4
answers
761
views
Clean code vs clean git/jira history
I started reading the book Clean Code by Robert C. Martin and at the start I found this idea of his interesting, "Leave the code cleaner than you found it" adapted from the "Leave the campground ...
6
votes
2
answers
4k
views
Clean Code: Another question about boolean as function parameters [duplicate]
I had a discussion, if the code for calling information from a database can have a switch to show also deleted entries.
Simplyfied the code (C#) look like this:
void searchEntry(string searchValue, ...
0
votes
1
answer
2k
views
Java convention - Implementing two similar functions for two different objects
I have two classes, let's call them Foo and Bar. They both extend different classes (Foo extends X, Bar extends Y), which have some common ancestor "way up" the inheritance tree, something like this:
...
2
votes
3
answers
3k
views
Always return the parameter when it has changed inside the method?
When you have a method that is doing stuff and changes occur in the parameters, should you always return the changed object like this:
public SomeModel DoSomething(SomeModel someModel) {
[something ...
138
votes
17
answers
15k
views
How do I know how reusable my methods should be? [closed]
I am minding my own business at home and my wife comes to me and says
Honey.. Can you print all the Day Light Savings around the world for 2018 in the console? I need to check something.
And I am ...
9
votes
2
answers
285
views
fall-through switch for executing a sequence of steps
My program needs to execute a sequence of steps from start to end. But based on different input the start point will vary, e.g, some will run from the first step to end, some will run from the 2nd ...
-1
votes
2
answers
636
views
How to ensure separation and inward dependencies between architectural layers in Python?
Suppose a large-scale project is being developed in Python 3.7. Some layered architecture is chosen: "clean architecture", "onion" or "hexagonal". The Dependency rule in it only allows inward-...
2
votes
3
answers
2k
views
Convincing a development team to use a better design pattern [closed]
I recently joined a company where I was tasked with building a system for one of their clients. The work I've done is so far working well, but the most senior developer on the team who's been with the ...
0
votes
2
answers
145
views
Is there a coding style principle for making class usage consistent
I get to review code that often looks like this:
class MyClass1 {
constructor MyClass(initialiseParam1: Object) {
// do something with initialiseParam1
}
initialiseStep2() {
...
2
votes
1
answer
180
views
Is "equivalent" functions / methods readability worth its maintanability cost?
First of all, I am sorry if it is a duplicate, I could not think of any "correct" wording to search about this.
Second let me clarify: By "equivalent" I mean methods that are meant ...
20
votes
1
answer
14k
views
Access multiple entities in repository - clean architecture
I have a API call that returns a list of Payments, each Payment contains a User. I need to call it, save the results in the database, fetch all the payments and users and return them all to the ...
0
votes
1
answer
2k
views
Clean Architecture and MVC controllers + entities
In Uncle Bob's clean architecture, why can't MVC controllers call entities directly? It seems like since the controller depends on the inner layer, they should be able to call entities when needed. If ...
0
votes
1
answer
144
views
Simple but frequently throwing vs reasonable but rarely throwing vs complex but never throwing [duplicate]
A lot of code that's designed to convert or parse some data of type Foo into a Bar is written with the assumption that one wouldn't intentionally pass it invalid inputs. As such, it assumes that ...
0
votes
3
answers
613
views
Naming variable which describes that something is currenty in use
I'm creating a variable which should describe that an object is currently in use. Lets say we have a form with a password input, and I want to describe the state when someone is using that input.
Is ...
2
votes
6
answers
415
views
Main function's subfunctions should terminate main function
So if I have a big function I break it to smaller ones to increase readability.
If I have parts in my big function where I want it to return. I want my subfunctions to have the ability to make the ...
1
vote
0
answers
76
views
Applying an overloaded/templated function depending on the type of a QVariant
I'm trying to take a QVariant (in this case from a QProperty generated on a class) and based on the type, return a QWidget that allows for it to be edited appropriately.
a signature for the ...
47
votes
8
answers
7k
views
Why isn't encoding the names of arguments in function names more common? [closed]
In Clean Code the author gives an example of
assertExpectedEqualsActual(expected, actual)
vs
assertEquals(expected, actual)
with the former claimed to be more clear because it removes the need to ...
6
votes
4
answers
8k
views
Separation of application logic and domain logic in Clean Architecture
I'm struggling with the separation of logic between entities and interactors or Use Cases. If I design the entities with DDD principles, each entity would have methods corresponding to use cases, ...