3 ms·
Can anyone explain to me what the benefit of this is over Lombok annotations? I like the Lombok builder syntax which this seems to lack.
by bobthepanda 7y ago
Can anyone explain to me what the benefit of this is over Lombok annotations? I like the Lombok builder syntax which this seems to lack.
- kelnos 7y agoComing from scala, I consider this an essential language feature, and I don't want to have to depend on a third-party library / compiler plugin / annotation processor to get it. This should be standardized by the language.
- iSnow 7y agoIt's a language feature, so esp. library developers would pick it up over Lombok to reduce their dependency graph. That said, I also like Lombok's annotation style more, I can pick & filter which members are relevant for `toString()` and `equals()`
- peeters 7y agoBesides just the convenience of it not being a dependency, this will allow other language-level features like pattern matching and object deconstruction in the future. Basically anything that requires the language to have a tuple/named tuple type.
- bobthepanda 7y ago> tuple/named tuple type As someone not familiar with using those, can you ELI5 what those are and what their benefits are?
- peeters 7y agoA tuple is the generic term for a pair, triple, etc. It's a collection of data of heterogeneous types, unlike an array which is homogeneous. When the members are unnamed, the data is indexed by its position like an array. E.g. a method could return an unnamed tuple ("foo", 7) which might have type (String, int). In some languages like ML, having tuples is such a fundamental part of the language that things like functions always act on a single argument which is actually just a tuple. So max(5, 5) is a function that takes a tuple of two ints as its parameter. When you have tuples as a first-class concept, you can start to do some interesting shortcuts like: (b, a) = (a, b); // swap two variables with no intermediate or String (first, last) = name; This is called deconstruction, where you extract a tuple into variables representing its members. This is common in a ton of languages (Typescript, C#, ML, Scala, Python, etc). It also forms a cornerstone of pattern matching expressions in some languages (Scala, Haskell) where you can create a condition and simultaneously assign the data you care about to variables that can then be used in that branch. Scala pseudocode: sum(list: ConsList<int>) { return list match { Empty(): 0; Node(first, rest): first + sum(rest); } }
- barbarbar 7y agoRecords are immutable. A normal pojo can be - but you don't know.