Skip to main content
96 votes
Accepted

Multiple boolean arguments - why is it bad?

The obvious problem To resolve this however, how would one refactor this? Do you create 4 functions now? trainModelWithZerosInitOptimSGD(...) trainModelWithZerosInitOptimAdam(...) ...
Flater's user avatar
  • 52.5k
59 votes
Accepted

What is the advantage of log file rotation based on file size?

"I have never had any issues with large files" is not synonymous with "there is never a problem with large files". Your lack of experience with problems does not prove that there ...
Flater's user avatar
  • 52.5k
53 votes

Is it logical to not use inheritance because the function is critical?

This is a “protect the idiots” rule. I’ve seen it in many forms. Once entrenched it’s very difficult to overturn. I’ve seen rules like this forbid code that is identical to code in the language ...
candied_orange's user avatar
48 votes
Accepted

Sufficient conditions for refactoring

Refactoring takes time. If not done well, it creates bugs that you need to fix. So it costs. You refactor when the benefits outweigh the cost of refactoring. There are good times for refactoring: one ...
gnasher729's user avatar
  • 45.9k
32 votes

Is it possible to build a system to generate UUIDs where every UUID is guaranteed unique?

there is a finite number of ids which can fit into some structure Correct. If you have n bits in your structure, after you have generated 2^n IDs, the next one must be a collision; this is the ...
Philip Kendall's user avatar
29 votes

What is the advantage of log file rotation based on file size?

Log file rotation is not only related to technical issues with the file itself. It's also related with operational considerations, like: being able to incrementally backup the logs (especially in ...
Christophe's user avatar
  • 78.4k
26 votes

Is it logical to not use inheritance because the function is critical?

This is difficult to tell without analyzing the code. I can't provide you an authoritative answer, but perhaps some guidance on how to make this decision will do. In a situation like this, the first ...
Greg Burghardt's user avatar
26 votes

Sufficient conditions for refactoring

To enable a codebase to be refactored, the fundamental necessity is test coverage. Ideally fast, automated test coverage. You want to be able to assert, with high confidence after every refactoring ...
Thomas Owens's user avatar
  • 83.3k
23 votes

Multiple boolean arguments - why is it bad?

Functions with a bunch of boolean parameters are often "helper" functions, as in your example, that just end up delegating to other functions based on the values of those parameters. You get ...
casablanca's user avatar
  • 4,964
22 votes
Accepted

Is there a clean way to model methods that only make sense depending on the current state of the object?

What you've done here has a name. This is an internal Domain Specific Language (iDSL). It can be used like this: void execute(PlannedMission plannedMission) { plannedMission .start() ...
candied_orange's user avatar
20 votes

Is it possible to build a system to generate UUIDs where every UUID is guaranteed unique?

You want version 1 UUIDs. They don't collide but they leak the generating computer's MAC address and require a monotonic clock. From RFC4122 we have this format 8 bytes time-low 2 bytes time-mid 2 ...
Joshua's user avatar
  • 1,664
15 votes

Is it logical to not use inheritance because the function is critical?

it's important for that function to be correct, so we want to ensure that the developer of a new sub-class goes through the steps to make sure they have the right logic. I would question the core ...
DavidT's user avatar
  • 3,358
15 votes

What is the advantage of log file rotation based on file size?

The other answers already provided very useful reasons, but there is one more I'm surprised I haven't seen outside of a comment yet: To be able to delete old log files to free disk space A very busy ...
Syndic's user avatar
  • 312
14 votes
Accepted

Is it okay to have misleading struct and function names for the sake of encapsulation?

This is why we invented the word meta. You're packing the result structure with meta info that isn't strictly part of what you're returning. But the info is about what you're returning. Just carve out ...
candied_orange's user avatar
14 votes

Is it possible to build a system to generate UUIDs where every UUID is guaranteed unique?

Is it possible, when K different hosts are generating IDs? Yes. And we can do it with readily available libraries. ULIDs do a pretty good job already, but they're not collision free. It looks like the ...
J_H's user avatar
  • 7,338
13 votes
Accepted

Dealing with global variables required by badly-written library

Assuming that you cannot change the library, and you have to use it, you need to have these global variables somewhere in your code. I’d recommend implementing an interface module that the rest of ...
gnasher729's user avatar
  • 45.9k
12 votes

Does the signature of a method create a dependency between the implementation of that method, and the code that invokes it?

To give your question more context, let us remember what Ousterhood is trying to explain in the section of the book. Let me cite the first sentence from the paragraph where you got your cite from: ...
Doc Brown's user avatar
  • 209k
11 votes

Is it possible to build a system to generate UUIDs where every UUID is guaranteed unique?

It is easy enough, but require some degree of coordination. The general scheme is relatively simple: partition the bit-space of the ID in two sections, one with a "generator ID" unique to ...
Matthieu M.'s user avatar
11 votes
Accepted

Is this design too convoluted?

There's a GameUtils project that contains the following classes: IPlayer, ICard, and IDeck. 'Utils' are helpers (i.e. utilities), which are ancillary services. Players, cards and decks are ...
Flater's user avatar
  • 52.5k
9 votes

Is it an anti-pattern to use interface for entity?

Without the full context of this article, it's impossible to say exactly what the point of it was but I think I can provide a useful answer to your question. The first bullet "Your interface ...
JimmyJames's user avatar
  • 27.6k
9 votes

Is it logical to not use inheritance because the function is critical?

As far as I can see this problem will not automatically be solved by switching from inheritance to composition. When I understand this correctly, in your system, each new subclass (or new module of a ...
Doc Brown's user avatar
  • 209k
8 votes
Accepted

Should my methods return concrete classes or interfaces?

You should return exactly what using clients need. If you believe in the solid principles the two worth considering here are Interface Segregation (depend only on what you need) and Dependency ...
candied_orange's user avatar
8 votes

What is the advantage of log file rotation based on file size?

never had any issues with large files and cannot think of reasons why we might set an arbitrary limit Every system I have ever ssh'd into has had limited budget and limited attached storage. If you ...
J_H's user avatar
  • 7,338
7 votes

Is it okay to have misleading struct and function names for the sake of encapsulation?

I don't see why you consider it "dirty" to keep the original name, as that's exactly what OOP does - there's a public interface to an object, and there are some internal implementation ...
Philip Kendall's user avatar
7 votes

Is there a clean way to model methods that only make sense depending on the current state of the object?

There is no perfect way to model runtime state transitions in a type-safe manner. Your suggestion is a valid approach, but it has the downside that code can still hold a reference to a previous state ...
JacquesB's user avatar
  • 59.8k
7 votes

Code quality: expressiveness vs. conciseness

contract Variant1 is not terrific. It offers poor maintainability, and likely wouldn't get past Code Review unchanged. int? checkLoginDay(int lastDay) { We started with a verb, good. But what's the ...
J_H's user avatar
  • 7,338
7 votes

Representing vectors as arrays of points vs. as data structures

A lot of this depends on where the data is coming from and what you need to do with it. For example, if all you were doing is reading it in from a file and passing it to a calculation, you might not ...
JimmyJames's user avatar
  • 27.6k
7 votes

Possible violation of LSP when adhering to ISP?

This is a covariance of a method's return type. This is compliant with LSP: The preconditions to getUser() are not changed and in particular, they are not strengthened. The postconditions of getUser()...
Christophe's user avatar
  • 78.4k
7 votes

Is it good practice for object APIs to be required to be called in sequence to gather information?

Your coworker is right. Constructors should give you a fully initialized and usable object. I also understand why you don't want parsing to happen in the constructor, because it can throw an exception....
Greg Burghardt's user avatar
6 votes

Multiple boolean arguments - why is it bad?

Prioritize client usage for simplicity over implementation issues. Look to the callers/clients to see how they use these functions. If they all always pass constant values (true/false), then probably ...
Erik Eidt's user avatar
  • 34.2k

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