3 ms·
Over time I shifted my opinion to consider that ternary operation as "logic", so the Foo is not the right place for that. Either Foo should've been created with
by deepsun 4y ago
Over time I shifted my opinion to consider that ternary operation as "logic", so the Foo is not the right place for that. Either Foo should've been created with "Default" already set to the `name` field, or Foo users should make the decision themselves.
Foo class can only contain something, but not make any decisions, no matter how small, because it's not obvious whether a decision is still small or not anymore.
Getters are still useful though, for example:
class Foo {
// all contents of Foo, but we want to keep it serialized for performance reasons
private ByteBuffer bb;
public Long getId() {
return bb.getLong(ID_OFFSET);
}
}
- stickfigure 4y agoI'm just going to quote myself from a few hours ago: > You don't always get to decide that. The data may be serialized in from JSON, loaded from a database, imported from some weird EDI system, etc. Maybe the initialization process is not so simple, and spread out all over the codebase (or even just dozens of constructors). Real-world codebases (the ones out there running profitable businesses, built by programmers that have come and gone) are rarely so clean and pretty that you can say "well, you just should have initialized it properly in the first place!" To that, I offer you Mike Tyson's incredibly apt programming advice: "Everyone has a plan until they get punched in the mouth".