New answers tagged

4 votes

How to "Tell, don't ask" when both the condition and action involves 2 objects?

As others have pointed out, "tell, don't ask" is a principle not a rule. It leads your code in a direction which has some good properties, but has other quirks that sometimes you wish to ...
Cort Ammon's user avatar
  • 10.9k
-1 votes

How to "Tell, don't ask" when both the condition and action involves 2 objects?

When you do decide it is worth the hassle, there is a refactoring for this that follows tell don't ask. Yes, even with two classes. Yes, without encapsulation destroying accessors. No getters required....
candied_orange's user avatar
13 votes

How to "Tell, don't ask" when both the condition and action involves 2 objects?

Tell don't ask is a principle aiming at guidance for effectively encapsulating internal details of objects. It therewith: encourages better abstraction, by placing inside the object the logic that ...
Christophe's user avatar
  • 76.8k
26 votes

How to "Tell, don't ask" when both the condition and action involves 2 objects?

You wrote I know the following is bad and already here is a misconception: thinking religiously in terms of good and bad about this. My interpretation of Tell-Don't-Ask is: when you see a code ...
Doc Brown's user avatar
  • 206k
1 vote

How to "Tell, don't ask" when both the condition and action involves 2 objects?

if(a.isX){ a.doY(); } This is not a violation of "Tell, don't ask". Directly accessing the data-member isX is not nice, but that can be easily remedied with a accessor: public class A{ ...
Bart van Ingen Schenau's user avatar
3 votes

Does turn "global state" into "passing parameter" increase whole system coupling or not?

Coupling comes in many forms. For globals it's called: Common coupling Common coupling is said to occur when several modules have access to the same global data. But it can lead to uncontrolled error ...
candied_orange's user avatar
1 vote

Does turn "global state" into "passing parameter" increase whole system coupling or not?

In my answer to the question Are open-closed principle" and "less coupling" rationales to use global state?, I was not talking about metrics which measure the number of direct ...
Doc Brown's user avatar
  • 206k
0 votes

Does turn "global state" into "passing parameter" increase whole system coupling or not?

isn't "coupling" about counting number of other classes in a class? No, this rule is overly simplistic and the linked answer is more correct, you have to count all the classes that are ...
Ewan's user avatar
  • 74.6k
1 vote

How are strings simultaneously objects and primitive data types in C#?

Strings are objects in C#, just like in Java. But strings have value semantics, which mean: They are immutable They are compared by value (content) rather than reference when using == When an object ...
JacquesB's user avatar
  • 58.7k
11 votes

How are strings simultaneously objects and primitive data types in C#?

In C#, strings can be used like objects with methods, properties, and other features of objects. In C# strings are objects with methods and properties. At the same time, strings are treated the same ...
Eric Lippert's user avatar
  • 46.1k
2 votes

How are strings simultaneously objects and primitive data types in C#?

Key points are that strings are reference types, not value types and that having a native C# name for it or not says nothing about the type. Identifiers like string and int are part of the C# language....
Martin Maat's user avatar
  • 18.4k
2 votes

How are strings simultaneously objects and primitive data types in C#?

So, to be pernickety "string" isn't a primitive in either language, "char" is. The real question is why "string" is a keyword, like int, byte, char etc. Its hard to be ...
Ewan's user avatar
  • 74.6k
3 votes

How are strings simultaneously objects and primitive data types in C#?

There is some big misunderstanding going on here. In c# everything is object, including primitive types like ints. Following pieces of code are valid: string text = 123.ToString(); object obj = 123; ...
Euphoric's user avatar
  • 37.3k
1 vote

Non blocking algorithm for invalidating and reloading cache in concurrent environment using Redis (with Redisson)

I don't understand the design process that led to all this locking. It sounds like (lots of) clients need to access a "mostly valid" result with very low latency. You're working too hard. ...
J_H's user avatar
  • 6,625
1 vote

How to solve a circular dependency with a composition relation?

I am not sure which of the circular dependencies you are concerned with, there are at least three: Compile time circular dependency. Memory/Reference circular dependency (each object holds a ...
DavidT's user avatar
  • 3,298
2 votes

How to solve a circular dependency with a composition relation?

One solution to your problem is a callback system, where the Gun "has a" ReloadSystem. The Reload method takes a reference to the Gun as a parameter. So at the end of Reload it can call back ...
Simon B's user avatar
  • 9,611
4 votes

How to solve a circular dependency with a composition relation?

1 and 2 are the same option as far as dependency knowledge goes. Without them the ReloadSystem has to know what a Gun is. Narrow what the ReloadSystem knows down to Reloadable and it doesn't care what'...
candied_orange's user avatar
3 votes
Accepted

Clarification on using timestamp without time zone and LocalDateTime in UTC-centric systems

Storing a date in UTC, Posix or any other universal time scale means that everyone in the world can easily agree that two events happened at the same time, of that one happened before the other, and ...
gnasher729's user avatar
  • 44.7k
1 vote

What are the bottlenecks for the Java build speed?

It is instructive to compare Java compilation speed in Eclipse and IntelliJ IDEs. Eclipse wins. Why? First, Eclipse uses its own compiler, which generates less optimized bytecode, but works faster. ...
user7610's user avatar
  • 429

Top 50 recent answers are included