252 votes
Accepted

Why is a while(true) loop in a constructor actually bad?

What is the purpose of a constructor? It returns a newly constructed object. What does an infinite loop do? It never returns. How can the constructor return a newly constructed object if it doesn't ...
user avatar
192 votes
Accepted

Criticism and disadvantages of dependency injection

First, I would like to separate the design approach from the concept of frameworks. Dependency injection at its simplest and most fundamental level is simply: A parent object provides all the ...
user avatar
180 votes

How can I defend reducing the strength of code reviews?

How can I justify and defend the thesis that: The merge button should be enabled by default The code review should be a recommendation , but not mandatory The code author should have the right to ...
user avatar
159 votes

How do huge open source libraries get maintained while having code far from "clean code" practices?

The principles stated in "Clean Code" are not always generally agreed upon. Most of it is common sense, but some of the author's opinions are rather controversial and not shared by everybody. In ...
user avatar
  • 55k
119 votes
Accepted

When using the Single Responsibility Principle, what constitutes a "responsibility?"

One way to wrap your head around this is to imagine potential requirements changes in future projects and ask yourself what you will need to do to make them happen. For example: New business ...
user avatar
  • 24.8k
114 votes
Accepted

Clean Architecture: Use case containing the presenter or returning data?

The Clean Architecture suggests to let a use case interactor call the actual implementation of the presenter (which is injected, following the DIP) to handle the response/display. However, I see ...
user avatar
112 votes
Accepted

Aren't the guidelines of async/await usage in C# contradicting the concepts of good architecture and abstraction layering?

What Color Is Your Function? You may be interested in Bob Nystrom's What Color Is Your Function1. In this article, he describes a fictional language where: Each function has a color: blue or red. A ...
user avatar
  • 13.4k
112 votes

How to encourage a team to refactor

Do not ask management for permission to refactor. It's none of their business. You might as well be asking permission to sharpen a pencil. Management doesn't understand refactoring. It's not a ...
user avatar
108 votes

Which way are downstream and upstream services?

The downstream services are the ones that consume the upstream service. In particular, they depend on the upstream service. So the front-end is downstream to the back-end because it depends on the ...
user avatar
107 votes

Why should I use dependency injection?

The advantage is that without dependency injection, your Profile class needs to know how to create a Settings object (violates Single Responsibility Principle) Always creates its Settings object the ...
user avatar
106 votes

Criticism and disadvantages of dependency injection

Dependency injection is, like most patterns, a solution to problems. So start by asking if you even have the problem in the first place. If not, then using the pattern most likely will make the code ...
user avatar
  • 55k
105 votes

Should functions that take functions as parameters, also take parameters to those functions as parameters?

There is absolutely no reason to pass a function, and its parameters, only to then call it with those parameters. In fact, in your case you have no reason to pass a function at all. The caller might ...
user avatar
  • 4,021
103 votes
Accepted

Return considered harmful? Can code be functional without it?

If a function doesn't have any side effects and it doesn't return anything, then the function is useless. It is as simple as that. But I guess you can use some cheats if you want to follow the letter ...
user avatar
  • 55k
96 votes
Accepted

Does splitting a potentially monolithic application into several smaller ones help prevent bugs?

Yes. Generally two smaller less complex applications are much easier to maintain than a single large one. However, you get a new type of bug when the applications all work together to achieve a goal. ...
user avatar
  • 65k
94 votes
Accepted

How to deal with fear of taking dependencies

... We are forced to stay on the lowest API level of the framework (.NET Standard) … This to me highlights the fact that, not only are you potentially restricting yourselves too much, you may also be ...
user avatar
  • 38.3k
87 votes

RESTFul: state changing actions

I find the practices described here to be helpful: What about actions that don't fit into the world of CRUD operations? This is where things can get fuzzy. There are a number of approaches: ...
user avatar
  • 979
83 votes
Accepted

How do huge open source libraries get maintained while having code far from "clean code" practices?

Good answer here already, but let me say a word about your butterknife example: though I have no idea what the code does, at a first glance, it does not look really unmaintainable to me. Variables and ...
user avatar
  • 186k
82 votes

Aren't the guidelines of async/await usage in C# contradicting the concepts of good architecture and abstraction layering?

You are right there is a contradiction here, but it is not the "best practices" being bad. It is because asynchronous function does essentially different thing than a synchronous one. Instead of ...
user avatar
  • 2,513
81 votes
Accepted

Responsibility for arrangement of elements - frontend or backend?

Any decent back-end API should receive parameters that allow some customization or filtering of the results it gives back to the client. For something that returns a list, it's usually common to ...
user avatar
  • 3,530
80 votes

In microservice, is it single database or single database instance for each service?

Assumed you have some services which can use the same kind of DB system and version, if you use different database or db instances is a decision you should not need to make at design time. Instead, ...
user avatar
  • 186k
78 votes

When using the Single Responsibility Principle, what constitutes a "responsibility?"

Practically speaking, responsibilities are bounded by those things that are likely to change. Thus, there's no scientific or formulaic way to arrive at what constitutes a responsibility, unfortunately....
user avatar
  • 13.2k
77 votes
Accepted

Why is it so bad to read data from a database "owned" by a different microservice

Databases are not very good at information hiding, which is quite plausible, because their job is to actually expose information. But this makes them a lousy tool when it comes to encapsulation. Why ...
user avatar
  • 29.8k
76 votes
Accepted

How do microservice system architectures avoid network bottlenecks?

Internal networks often use 1 Gbps connections, or faster. Optical fiber connections or bonding allow much higher bandwidths between the servers. Now imagine the average size of a JSON response from ...
user avatar
75 votes

What does Robert C. Martin mean by SQL being unnecessary?

Bob Martin is clearly exaggerating to make his point more clear. But what is his point? Does he just want people to stop using SQL/Relational Databases because of SQLi attacks? To my understanding,...
user avatar
  • 186k
74 votes
Accepted

Is it okay to have code smells if it admits an easier solution to another problem?

When building real-world programs, there is often a trade-off between staying pragmatic on one hand, and staying 100% clean on the other. If staying clean prohibits you to ship your product in time, ...
user avatar
  • 186k
68 votes
Accepted

Uncle Bob's clean architecture - An entity/model class for each layer?

In my opinion, that's absolutely not how it's meant. And it's a violation of DRY. The idea is that the entity / domain object in the middle is modeled to represent the domain as good and as ...
user avatar
  • 804
64 votes
Accepted

Value of using private methods vs all public in classes for internal software for ease of unit testing

I've left them public for ease of unit testing Ease of writing those tests, maybe. But you are then tightly coupling that class to a bunch of tests that interact with its inner workings. This results ...
user avatar
  • 38.3k
64 votes

Why should I use dependency injection?

Dependency Injection makes your code easier to test. I learned this first-hand when I was tasked with fixing a hard-to-catch bug in Magento's PayPal integration. An issue would arise when PayPal was ...
user avatar
63 votes

What is a good approach to handling exceptions?

This code: try: do_something() except Exception: log_error() is dangerous. Not because you caught a generic Exception but because you suppressed the exception without doing any recovery or ...
user avatar
63 votes

What is the best practice about microservice architecture for consuming many stored procedures in the same database?

I get the feeling that some decision maker in your company heard about the buzzword "micro-service" and decided that you need to have them as well, regardless of if they actually solve a ...
user avatar

Only top scored, non community-wiki answers of a minimum length are eligible