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
1answer
77 views

Refactorings of larger types

This is a sweet spot thing for me. But I am not sure what rules others apply to the challenge. In this codebase I have many large types. Mostly types called *Service. Large types are cool. But I tend ...
0
votes
1answer
58 views

How to name a function(non-default image orientation)?

I have a C++ interface for video provider. Frames can be rotated (Portrait/Landscape) as a result of platform-specific functions. enum class EFrameOrientation { KUp, // default orientation ...
0
votes
1answer
718 views

Should I separate into own class when creating private methods in service layer?

I would like my project to adhere to the SOLID principles and write clean code, but I am still not very clear on when I should separate from the service layer. I have a Web Api 2.0 Controller called ...
0
votes
3answers
1k views

Why are no parameters better than few parameter methods?

In Clean Code, Robert C. Martin states that no parameter methods are better than those with very few parameters. I'm kind of confused as no parameter methods are usually harder to unit test and tend ...
1
vote
2answers
163 views

Naming functions that do one or more things

I recently picked up 'Clean Code' by Robert Martin and have taken to refactoring my recent project. I'm realizing how important it is to name variables and functions in a way that clearly expresses ...
2
votes
1answer
3k views

Node.js script const variables in SCREAMING_SNAKE_CASE or camelCase

TL/DR: When requiring another script in Node.js and defining it as a const should the variable name still be in camelCase like it was usual with var or should it instead be in SCREAMING_SNAKE_CASE as ...
5
votes
1answer
468 views

Listen for data(base) changes using Clean Architecture

Our team is building an Android app using Kotlin (if that matters at all) by following the guidelines described by Uncle Bob (Robert Martin). The presentation pattern we use is MVI. We have ...
5
votes
7answers
662 views

Is it a good idea to split a constructor in multiple functions?

Here is the work flow of a class of my program: Server class instanciation -> Creating socket -> Binding socket to addr:port -> Listening -> Handling clients Should I put all that stuff in the ...
2
votes
3answers
987 views

Is it a good thing to create a namespace for global functions in C++?

I'm making a C++ OpenSource project and I want it the more understandable and clean, so I need some point of views about doing things like this : Server.cpp: void Server::setOption(type foo, type ...
2
votes
3answers
486 views

How to handle common functionality that is not business logic in clean architecture

The dependency rule in Clean Architecture states that: ... that source code dependencies can only point inwards. I now came across a problem that I cannot figure out myself. Lets assume I have a ...
2
votes
3answers
375 views

Is there a way to have four possible outcomes without repeating the two conditions? [duplicate]

In a generic sense, my question goes something like this: if (p) { if (q) { a(); } else { b(); } } else { if (q) { c(); } else { d(); } } ...
10
votes
1answer
914 views

Trouble grasping what clean code looks like in real life

I am currently reading and working through "Clean Code: A Handbook of Agile Software Craftsmanship" by Robert C. Martin. The author talks about how a function should do one thing only, and thus be ...
3
votes
2answers
226 views

How to build a shared vocabulary of the project terms on a developers team?

When I work on a developer team (3-10 people), I often notice that getting a precise and shared definition of each what each term in code means becomes an issue as the code base grows. After a few ...
39
votes
8answers
8k views

Inverting an IF statement

So I've been programming for a few years now and recently have started using ReSharper more. One thing that ReSharper always suggests to me is to "invert 'if' statement to reduce nesting". Let's say ...
2
votes
1answer
503 views

Where to instantiate object on clean architecture

I am trying to wrap my head around clean architecture but I am struggling with the concept of how to avoid some dependencies. I am implementing an API in Java for personal use, however I was trying ...
-3
votes
3answers
457 views

Writing quality code [closed]

I know there are many books on writing clean, modular, readable and whatever else you can say but frankly speaking I find it very hard to remember every advice given on those books. Frankly speaking ...
4
votes
1answer
207 views

How to make sure that each field's setter executes a specific code?

I am working with Java 1.7, IDE is Eclipse Indigo. I have a base class which has id as an int. It also has a boolean variable onlyIdInitialized; I am setting it to true when an object is created with ...
0
votes
2answers
76 views

Using typeless maps on api boundaries

What do you think about passing typeless maps to APIs (packages, systems, adapters) outer to Core Domain as in 1st Way below? Strongly-typed objects are inside Domain API, and business rules are ...
0
votes
1answer
132 views

Encapsulated views in MVC

This is an architectural / design question that just came to my mind when comparing current MVC practices in PHP with component based development in Javascript. My question is: Why doesn't the view ...
49
votes
15answers
26k views

Clean Code: Functions with few parameters [closed]

I read the first chapters of Clean Code by Robert C. Martin, and it seems to me it's pretty good, but I have a doubt, in one part it is mentioned that it is good (cognitively) that the functions ...
1
vote
1answer
427 views

Does separating Domain model and Persistence model have impact on transactional aspect?

In this post, there is: For example, with your own persistence model, you are not able to benefit from the built-in change tracking functionality. And that means you will not be able to ...
14
votes
5answers
765 views

What is a helpful mindset when conducting a formal code review

Our team has recently started conducting code reviews against each checkin. As the team lead I'm trying to find a balance between providing too many suggestions, annoying developers and decreasing ...
9
votes
4answers
6k views

Clean architecture validation in domain vs data persistence layer?

I'm studying up on clean and as a result am quite dramatically rethinking a great deal of how I design and write software. I've thing I'm still wrestling with however, is for business rules like "on ...
29
votes
11answers
6k views

How many design patterns and levels of abstraction are necessary? [closed]

How can I tell my software has too much abstraction and too many design patterns, or the other way round, how do I know if it should have more of them? Developers I work with are programming ...
3
votes
1answer
139 views

How to architect the network system in my project?

I'm developing a open source application that have a client and server side. The first version only have as client tvOS, and is being written with Swift. Now, I'm writing the network system for my ...
3
votes
3answers
782 views

Should OOP languages eliminate keyword 'protected' in order to force programmers to write clean and high quality codes?

I've seen some posts which has strong reason to avoid using protected: Why have private fields, isn't protected enough? Why is Clean Code suggesting avoiding protected variables? And there are ...
5
votes
4answers
285 views

Is it acceptable to assign a class variable within a method?

I've just done a code review where I came across a method like this: private void FindMinAndMax(double[] values) { // Some algorithm that results in two class vars being assigned: _min = ... ...
3
votes
4answers
198 views

I have a set of variables that are not known until run-time, and will be shared by all instances of that class.

Without getting into specific language or implementation: The value of the variables are not known until runtime. All instances of this class will need this variable. The obvious solutions: Use a ...
2
votes
2answers
896 views

Augment a thrown exception with some contextual information

The application this question is about is basically a transpiler which contains a lot of logic. The transpiler is written in C++ (which should not be much of relevance for this question), and it ...
0
votes
3answers
333 views

Automating checks for “good” unit tests

There's already a question about How to write good unit tests. Based on the answers provided there, the key properties of a good unit test - Short Readable and conveys intent instantly Independent ...
2
votes
4answers
701 views

Should I comment or remove any un-used code from my Solution?

I was working in a story and in last minute, I have been asked to hide something from UI and we will used it next release. Should i remove it or comment it Should i remove or comment anything ...
1
vote
1answer
118 views

Refactoring code dependent on external class

I have a class similar to ServletFilter which has multiple validation on the input request class TokenHandler implements SomeHandler{ Response handle(Request request){ if(paramXMissing(request))...
3
votes
2answers
273 views

Should you use else to check?

Which structure of writing code is better and why? if (!file_exists('file.txt')) { throw new Exception(); } else { //operations } or if (!file_exists('file.txt')) { throw new Exception(); }...
0
votes
4answers
378 views

Cleaner code practices for Java programming

What would be considered better, cleaner code from the following options? The code basically sends a file through a Socket using an OutputStream that encrypts it. The code does not look that basic ...
5
votes
2answers
175 views

Symbols or Keywords for Operators?

I'm defining coding conventions for Progress OpenEdge in our company. In this language one can use symbols or keywords for operators, both work the same. For code quality purpose (code review, code ...
6
votes
3answers
1k views

Writing clean code without knowledge on the programmed topic

Are there any tips that can help me create clean code when I'm working with something poorly documented and completely new to me? It is easy to write a clean code when we are writing something for ...
1
vote
1answer
160 views

Providing context in Class name, even though the namespace provides context

So I am reading Clean Code and I want to write my class names with the proper amount of context, but how does .NET namespaces play into the concept of Meaningful Names? Do I forego context in the ...
-6
votes
1answer
736 views

Class names with Verbs

So I am reading Clean Code. In the Meaningful Names chapter, they lay down a rule of no verbs in class names. However in the Adding Meaningful Context section of that chapter, on page 29, he uses a ...
3
votes
1answer
196 views

Clean Architecure: Creating an entity from a set of other entities

I have an app that collects data points throughout the day. Each data point is stored in a DataPoint object (that is persisted in the DATA_POINTS) table. I also have a DataPointRepository with basic ...
0
votes
2answers
652 views

Does this code have only one level of abstraction?

I'm trying to apply some good practices from Clean Code in my code, but I'm stuck trying to figure out if my code has a [G34] code smell, which tells that functions should descend only one level of ...
4
votes
7answers
869 views

How can wrapping an expression as a function be Clean Code?

Another programmer just started working in our team and submitted a patch. What required was to have something that compares and check a couple of conditions and set a property based on the outcome. ...
15
votes
5answers
6k views

Boolean return of set.add() in if conditional?

The add operator of the set class returns a boolean which is true if the element (which is to be added) wasn't already there, and false otherwise. Is writing if (set.add(entry)) { //do some more ...
1
vote
2answers
2k views

Return array of multiple different objects?

I have code along the following lines: public void processInput() { List<String> input = readInput(); final Object[] returnObj = createInternalStructureFrom(input); final Dictionary ...
3
votes
3answers
1k views

Tradeoff between clean code, duplicate code and code efficiency in java

I have a question on writing clean code. I’m trying to refactor the following method: private static Map<String, String> createMapOfAttributes( final String Id, final String ...
0
votes
3answers
284 views

Which method of defining variables is a cleaner way to code

My question is which method below of defining variables is a cleaner way to code and why? Option 1: file_one=/path/to/file1 file_two=/path/to/file2 if condition cd(file_one) else cd(...
1
vote
2answers
156 views

Does sending parameters around inside a class suggest that I should refactor to a new class?

I have noticed a pattern when I refactor my code for readability. When I refactor a method into several smaller methods, I often have to introduce parameters which sometimes (too often) makes the code ...
4
votes
1answer
148 views

Choosing between adding a maven dependency vs. copying the one class I need

My project can benefit from a bit of code from the Apache commons-math3 project. Specifically, my math heavy application would benefit from using the FastMath class which avoids using extremely ...
124
votes
20answers
22k views

How do you safely delete a piece of code that looks like it's never entered?

You've found some code that looks superfluous, and the compiler doesn't notice that. What do you do to be sure (or as close to sure as you can) that deleting this code won't cause regression. Two ...
2
votes
1answer
84 views

Best practices for spreading various options in application code

I have a large class consisting of properties that are kind of (import) options. They are stored in one bundle class, so that it's easy to serialize them (or set eg. from environmental variables ...
2
votes
3answers
429 views

Refactoring Atrocious Java Code [duplicate]

So I recently started a new job for a small software company. They've got some old technology which I was aware of during the interview process. However, I've been digging into their code-base, and I'...

1 2 3 4 5 8