3 ms·
Somewhat related question: Do these fluent interfaces provide any real advantage over named parameters? The wikipedia example of: config.setColor("blue").set
by thurn 15y ago
Somewhat related question: Do these fluent interfaces provide any real advantage over named parameters? The wikipedia example of:
config.setColor("blue").setHeight(17)
seems like it could just as easily be written:
config.update(color="blue", height=17)
- raganwald 15y agoFor updates and initialization, I wonder the same thing. In a discussion about adding chaining syntax to CoffeeScript, one of the contributors wondered about libraries that handle traversing a structure for you: foo.update color: ‘blue’ suffix: ‘singular' barCollection: color: ‘green’ suffix: ‘plural’ This is probably far superior for fairly static tree navigation.
- politician 15y agoAren't JavaScript objects supposed to be unordered sets? Why is that example equivalent to `foo.color('blue').suffix('singular').barCollection.color('green').suffix('plural')`? (Is it?)
- raganwald 15y agoThey are unordered. For certain types of updates, the order is immaterial and a hash of attributes could be applied. On the other hand, if you are mutating a tree as you go along, the order is important and you want to call methods and/or functions to traverse and apply side-effects.
- omaranto 15y agoI think they don't have any advantage over named parameters and moreover, that they were invented for and mostly used in languages that do not have named parameters, like Java.