Hacker News new | ask | show | jobs
by salawat 1692 days ago
God, I hate that pattern.

Give me an API that takes a key/value pair where key is the name of the field to be set, and value is the value to be set.

Easy to read. Great way to get people to pay attention to tge datamodel, Low overall maintenance burden.

As opposed to: lets add another bloody withMethod() to the API,

so people can write

MethodsLikeThis .withThis(Thing) .andThat(Stuff) .atTheEndofWhich(aThingwithAnEnd) .someone(you) .hopes(new Hope("There is a point to it all)).but().alas("There is not.");

So now my stack traces look daft when things break in a contrived attempt to make things prettier to read when otherwise it could have been:

Unable to set value for key:"Kye" value:"if you spell it right, it will set it. Unless it isn't even the right datatype". Unknown field:"Kye"

Build your state packet. Prime your logical machine. Push the button. Verify output. Do not try to turn my test suite into a work of effing Shakespeare.

Maybe that's just me being crotchety though.

1 comments

> Give me an API that takes a key/value pair where key is the name of the field to be set, and value is the value to be set.

Not in a statically typed language, please! It should be a compile-time error to try and set the key `Kye`.

I agree with the compile-time error checking part, but it's possible to have groups of key/value pairs (i.e. anonymous records) in a statically typed language where only specific keys are allowed, with specific value types for each key.