Is there a difference in terms of performance (or other objective factors) between calling an empty GORM constructor and setting the properties individually, and mapping the parameters in the constructor?
ie
Foo foo = new Foo()
foo.bar = 1
foo.baz = 2
vs
Foo foo = new Foo(bar: 1, baz: 2)
I’ve always preferred the former, but I’m wondering if the second is more efficient.
I’d say no significant performance difference. I ran some tests creating 1000 objects each way and each way always took less than 50ms so you’re probably splitting hairs at that point. In both instances the setters (if implemented) are invoked so you’re good to go on that front.
I’d go with whatever is easier to read. As for consistency, yes overall I think it’s important, but I would stick with easier to read. If you’re constructing an object with 20 properties, a map may not be the best. If you’re constructing it with 4 properties then maybe it makes sense.
Here are the tests that I ran: