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
-3
votes
0answers
25 views

How VIPER design looks like for login flow and chat flow for chat like app in iOS?

I am developing a chat like app, and I am new to VIPER architectural design. I am stuck at the beginning of the implementation and app has to show login module if user has not Signed IN/UP, if user ...
0
votes
1answer
65 views

Simple tic-tac-toe GUI in Common Lisp: Avoid using Continuation Passing Style?

I've made a simple Tic-Tac-Toe game in Common Lisp using the Ltk library. One of the things I wanted to do was to support CPU vs CPU, human vs human, human vs CPU, and CPU vs human. Also, possibly ...
2
votes
1answer
52 views

Right approach to make code depending on a date

I am currently reviewing a PR where we want to enable a feature based on some suscription date of a user such as: let featureEnabled = false if (user.createdAt > MONETIZATION_DATE) { ...
0
votes
1answer
81 views

Cyclomatic complexity vs repeated code

we've a python function that can be achieved in 2 ways 1st method def complexity_1(x, y): if 2 == x and 3 == y: a=3 b=4 c = a + b elif 2 == x and not 3 == y: a =...
1
vote
1answer
167 views

Clean Code: How much architecture code should be written if architecture is supposed to be fluid

I watched a video series from Uncle Bob on Clean Code. He makes a few points on architecture which I both agree with but I believe could have clarification. From Uncle Bob: The Interactor is ...
0
votes
1answer
61 views

Preferred architecture for tree stuctured data (Angular/Typescript)

After reading some of "Clean Architecture" I got the idea that perhaps I should reconsider the way I have architected a chart of accounts/accounts object in an accounting program. I have ...
-3
votes
2answers
94 views

Naming conventions for set/unset method parameter

I have some class MyClass which has two methods: Lock(){} Unlock(){} For some reasons, the two methods are to be unified into one, with an additional parameter for indicating the action. What should ...
1
vote
3answers
95 views

Where to validate user input - Constructor, Validation object, or Factory method?

Let's say your application takes in a user request and you don't trust the front-end validation (because you never trust the front-end validation). In your controller or other handler, you want to ...
-4
votes
1answer
40 views

Message Strings in Backend

Its ok to have hardcoded strings on backend? Example: Log.e("Error connecting to the database") The text "Error connecting to the database" should be hardcoded there? Or should it be in a separated ...
-3
votes
2answers
59 views

How do I organize my REST API codes along with the codes for generating the website?

Using github as an example, www.github.com is the website people visit and api.github.com is the REST api server programs will visit. But they probably share some codebase and in my case they share a ...
5
votes
2answers
391 views

Is it a bad practice for a unit test to “trust” the other?

Assume I have the following two functions: function storeObject(object) { // Connect to database // Prepare query // Execute query } function retrieveObjectWith(id) { // Connect to ...
0
votes
1answer
54 views

How to handle input validation in microservices for duplicated data

What would be the best practice of handling input validation in microservice? Especially for the duplicated data? To give context, say I have 3 services: User Typical user service with User object ...
-3
votes
1answer
48 views

What is the rule for making functions private in Python modules?

I was wondering what's the principle behind it, and whether I should treat all functions from module that are not used anywhere else at the time as private, and mark them with underscore prefix so ...
41
votes
10answers
9k views

Clean Code: long names instead of comments

Don't be afraid to make a name long. A long descriptive name is better than a short enigmatic name. A long descriptive name is better than a long descriptive comment. Robert C. Martin Did I ...
1
vote
1answer
116 views

C# | How to Unit test a Timer (in a daily job run scheduler)?

I wrote this class: using System; using System.Threading; using System.Threading.Tasks; public interface IJobScheduler { void RunDaily(Task task, int hour, int minutes ); } ...
-1
votes
2answers
57 views

Execute sequence of methods conditionally and log possible error

I'm not sure if this is the adequate site (maybe CodeReview?) but it's the only one here in StackExchange that have got a "clean code" tag ... There is no need for downvotes if this is not the correct ...
1
vote
0answers
47 views

Identity and access management in Clean Architecture and MVC design

The application user has a lot of standard functionality we see in most applications. At a high-level, this includes some form of authentication, authorization, and session management. At a low-level, ...
3
votes
3answers
206 views

Multiple classes depend on one object reference

I have several classes like Button, Textbox and so on but at instantiation of those object they all need one object reference. The button represents a physical button on the screen but it is not an UI ...
2
votes
2answers
415 views

Does it make sense to use meaningless named constants?

For example, does it make sense to refactor the following code: a = a * 2; as: const int INT_TWO = 2; // ... a = a * INT_TWO; My question hinges on the fact that the new constant conveys no ...
1
vote
2answers
55 views

How to pass variable to function that may or may not be available based upon options?

I have a question and it is quite simple. Here are the details: I want to pass an options object into my mainFunction and some other functions inside of it, i.e. someFunctionCall and ...
-4
votes
1answer
36 views

How to decide what should be bounded context

I am trying to develop a demo application and confused while designing context. Let's say we have three entity and their properties User Id Email Todo Questions Answers Value ...
0
votes
3answers
142 views

Should a function that returns something be named as an accessor (getSomething)?

I understand accessors have to do with OOP. For other languages such as C, imagine you have a function that given 2 numbers returns their sum. Should you name it getSum() or sum()?
7
votes
2answers
220 views

Is there a correct way to use abbreviations in code? [closed]

Oh, abbreviations in code, the bane of every developer. Consensus seems to be against them, because readability might be affected. But the examples given are often extreme: like "repr" for "represent"...
4
votes
4answers
315 views

Measuring the success of coding dojos

I'm interested in starting coding dojos at the company I work at (during or after working hours). I think it will help to spread knowledge on how to write clean, concise and consistent code. I've been ...
0
votes
2answers
101 views

Design pattern for executing and reverting the tasks in same order

I have a Task in my project , to complete that i have call(REST) multiple external systems. If my call fails at some level , i have to rollback all my previous calls(making call with undo action) . ...
-1
votes
1answer
128 views

Pass ID or Object which has irrelavant details as RequestBody in Rest Call?

Situation: I am designing a REST API that needs one or more, potentially large objects to do it's work I am facing a decision to either Pass the large object by reference and have the API retrieve ...
66
votes
13answers
17k views

How to avoid comments about one line of code for cleanliness

I'm trying to clean up some of my code using some best practices, and read that comments are almost always a bad idea for future maintainability. I've managed to get rid of most of them by refactoring ...
1
vote
2answers
214 views

How to declare and share a lot of variables to provide best performance

My question is not about dilemma between clean code vs performance, but I want to understand exact issue with declaring variables and sharing them between functions. I read in many threads, that from ...
41
votes
8answers
7k views

Should I use AND in a function name?

I am in a predicament. I am working in a repository that makes a lot of database changes within its functions. The function I am dealing with returns responseids (but from a transformation, not from ...
3
votes
3answers
317 views

How to manage chaotic code explosion in React application

So we decided to redo UI of our web application in React. Six months down the lane and we have a complete mess of components and reducers and thunks and actions and god knows what not. We have ...
4
votes
4answers
357 views

Grouping of methods

We have multiple pages searching for users, each site having different search parameters. Sometimes, we have 2 parameters, sometimes 4 and most of these parameters overlap. So we have kind of (...
2
votes
2answers
141 views

Refactor approach for huge if else Clutter based on many independant conditions

Currently I am cleaning up hard to maintain and test if else clutter which is based on conditions which have to be checked in isolations: What is the basic semantic of the conditions? Big Entity ...
-3
votes
1answer
87 views

Should vanilla solutions be avoided in Spring web applications?

I am making a Java and Spring webapp that scrapes data from a web and then publishes it through an API. Some of the raw scrapped data is in the form of Set<SomeObject> which I then convert to a ...
82
votes
9answers
17k views

When to use / not use syntactic sugar

Currently I am working on a school project written in C#. Some teammates just started in C# and some are already familiar with C#. Today I had a discussion on whether to use syntactic sugar like this ...
-2
votes
1answer
136 views

Proper program structuring in Python

So, recently I have been doing a lot of programming in Python. I have noticed that my programs can be somewhat hard to read. I usually have one main class which does everything, sort of like this: ...
2
votes
5answers
348 views

Clean code vs ease of testing: Make method params explicit when they are class attributes just so unit testing is easier?

In Clean Code, we're advised to reduce, wherever possible, the number of arguments in a method's signature. This can often be achieved by using class attributes in lieu of parameters. Now in a code ...
7
votes
4answers
694 views

Are “in” parameter modifiers considered a code smell?

As of C# 7.2+, you can add a parameter modifier in before the parameter type to define a parameter as const, essentially. It is like the ref or out keywords, except that in arguments cannot be ...
54
votes
6answers
21k views

Functions that simply call another function, bad design choice?

I have a setup of a class that represents a building. This building has a floor plan, which has bounds. The way I have it setup is like this: public struct Bounds {} // AABB bounding box stuff //...
1
vote
1answer
156 views

Should we put small, potentially often-used pieces of code into tool methods in a shared library? [duplicate]

I recently switched jobs to a new company which develops a .NET framework based product which has been on the market for like 15 years already. Some of the engineers are in this project almost from ...
2
votes
1answer
134 views

Better way to implement a feature with turn on/off based on a flag

I'm trying to implement a feature with option to turn it on/off based on a flag. I'm doing it in the following way which I feel like a overkill, public interface Feature { public interface ...
1
vote
2answers
184 views

Should a BDD feature be implemented by a one (and only one) clean architecture interactor?

TL; DR Given BDD documentation with features composed by several scenarios, should we: Create a single interactor per feature Create minor interactors per scenario, and composing the feature ...
12
votes
5answers
1k views

How to introduce new language features in a legacy source code?

I have a coding style related question. In my example it is java, but I think this can be a generic question regarding languages that are changing rapidly. I'm working on a java code base which was ...
19
votes
6answers
2k views

How to quantify Code Quality [closed]

My Business unit has huge number of developers (About 100). Due to various reasons, the developers are nearly solely focused on delivery rather than quality. The bad quality code has already started ...
7
votes
4answers
569 views

C# declaration redundancy

When declaring a member class MyClass { AnyClass<WithLong<Generic,Declaration>> myProp = new AnyClass<WithLong<Generic,Declaration>>(); } is quite redundant. ...
1
vote
3answers
225 views

How should I name output variables that are the same as the function?

What are some conventions for naming a variable in cases where the name of the variable ought to be identical to the name of the function? I'm using VB.Net. I often have this problem when writing ...
1
vote
2answers
344 views

Clean Code: Avoiding “Order Matters” without passing member variables to private methods?

I am trying to implement some of the principles laid out in Clean Code by Robert C. Martin. I had a class that was heavily suffering from the ordering problem. I have solved most of this by ...
1
vote
3answers
246 views

Which option is best, when you have an attribute that is a list?

I have a class containing a list, for example: class User{ .... List<String> cards ... } What's the best way to provide access to this member? List<String> getCards() or ...
0
votes
0answers
68 views

Where to put use case calling threads in clean architecture?

I've just started using clean architecture, It's clean and nice, but I've found a bit confusing use case. My application should be able to register to update a token after some time, so I handled ...
1
vote
2answers
253 views

What is the cleanest way of writing a function with conditional statement with many returning options?

Maybe that's simple, but I'm a little confused. I have such a Ruby code: def my_function(found_objects) # ... if found_objects.second return CoreObjectFactory.get_object(found_objects.second,...
2
votes
1answer
91 views

How to Avoid Copy Pasting Repetitive Log Calls

Currently working on a Go project of about 10k lines of code. Within the project, there's a logging library that requires a couple steps of initialization in order to actually write to the log ...

1
2 3 4 5
9