3 ms·
> And thousands of manual get/set functions don't? My statement doesn't apply to mere data carrier classes. Anyway, getters and setters are an antipattern as w
by samus 16d ago
> And thousands of manual get/set functions don't?
My statement doesn't apply to mere data carrier classes. Anyway, getters and setters are an antipattern as well since one can just as well make all the fields public.
> Thousands of lines of builders don't?
With withers most of these will go away. And a class will be able to choose which things can be set, which is not the case for initializers.
> But it's not synchronous code, is it? It's easily dozens of lines wrangling Futures, and Thread initialisers, and Executors, and..
That code won't look that much different with async/await.
- troupo 16d ago> Anyway, getters and setters are an antipattern as well since one can just as well make all the fields public. I Java? Yes. Because of the language design, and not because of some inherent "encapsulation" or something. Somehow `x with { a = b }` doesn't break encapsulation and offers nice DX. But object initializers? Lol > And a class will be able to choose which things can be set, which is not the case for initializers. The class in C# can easily chose what can and cannot be set. Because unlike Java it actually cares about things like this. Quick example class Test { public int x { get; set; } public int y { get; } } var t = new Test{ x = 1, y = 2 }; I can give you a hint: this will not compile. Another example: public class Matrix { private double[,] storage = new double[3, 3]; public double this[int row, int column] { // The embedded array will throw out of range exceptions as appropriate. get { return storage[row, column]; } set { storage[row, column] = value; } } } var identity = new Matrix { [0, 0] = 1.0, [0, 1] = 0.0, [0, 2] = 0.0, [1, 0] = 0.0, [1, 1] = 1.0, [1, 2] = 0.0, [2, 0] = 0.0, [2, 1] = 0.0, [2, 2] = 1.0, }; Incomprehensible abilities for Java-land > That code won't look that much different with async/await. Lol. https://news.ycombinator.com/item?id=49726868 https://news.ycombinator.com/item?id=49726868
- samus 14d agoYou can go with a lot less code if you don't care about proper cleanup of resources.