Skip to main content

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

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 ...
Tali Luvhengo's user avatar
4 votes
1 answer
398 views

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 ...
bnsd55's user avatar
  • 141
10 votes
4 answers
3k views

I have the following code: public void moveCameraTo(Location location){ moveCameraTo(location.getLatitude(), location.getLongitude()); } public void moveCameraTo(double latitude, double ...
Tlaloc-ES's user avatar
  • 387
5 votes
1 answer
18k views

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 ...
user avatar
1 vote
2 answers
364 views

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. ...
Gil Sand's user avatar
  • 2,193
4 votes
2 answers
116 views

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 ...
user avatar
0 votes
5 answers
3k views

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 ...
ddreian's user avatar
  • 111
2 votes
4 answers
761 views

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 ...
findusl's user avatar
  • 142
6 votes
2 answers
4k views

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, ...
Christian Müller's user avatar
0 votes
1 answer
2k views

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: ...
Mickey's user avatar
  • 103
2 votes
3 answers
3k views

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 ...
MuhKuh's user avatar
  • 131
138 votes
17 answers
15k views

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 ...
Koray Tugay's user avatar
  • 1,595
9 votes
2 answers
285 views

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 ...
Qiulang 邱朗's user avatar
-1 votes
2 answers
636 views

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-...
schrödingcöder's user avatar
2 votes
3 answers
2k views

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 ...
Greenspud Coder's user avatar
0 votes
2 answers
145 views

I get to review code that often looks like this: class MyClass1 { constructor MyClass(initialiseParam1: Object) { // do something with initialiseParam1 } initialiseStep2() { ...
eddyP23's user avatar
  • 209
2 votes
1 answer
180 views

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 ...
LouizFC's user avatar
  • 31
20 votes
1 answer
14k views

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 ...
wise.potato's user avatar
0 votes
1 answer
2k views

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 ...
user204588's user avatar
0 votes
1 answer
144 views

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 ...
BambooleanLogic's user avatar
0 votes
3 answers
613 views

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 ...
Adam A's user avatar
  • 43
2 votes
6 answers
415 views

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 ...
Ferenc Dajka's user avatar
1 vote
0 answers
76 views

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 ...
Krupip's user avatar
  • 1,347
47 votes
8 answers
7k views

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 ...
EternalStudent's user avatar
6 votes
4 answers
8k views

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, ...
FedericoG's user avatar

1
3 4
5
6 7
11