3 ms·
Where it starts to get more cumbersome than it is worth is requests that can come in with any combination of N fields. The generic path defined here would have
by taeric 3y ago
Where it starts to get more cumbersome than it is worth is requests that can come in with any combination of N fields. The generic path defined here would have RequestWithA, RequestWithB, RequestWithC, etc. And, arguably, yes, that is a good idea.
Realistically, nobody wants to review all of that. And you will get phantom code of RequestWithZ that isn't actually valid anymore, but nobody remembers it and there is nothing about the type that makes that clear. In fact, you assume that it has a type, it must be needed.
I suspect you will push for groups of the fields that are relevant for the request. Such that it is RequestWithGroupA and such, but, isn't that what "Request" is supposed to be already? The group of data sent? So now you start down a taxonomy of Requests and you build an impressive machine that can deal with this.
Which is even more amusing, as that is called a program. And often we accept some invalid possibilities for highly theoretical reasons that help keep the programs easy to read for the people using them.
- mrkeen 3y ago> And you will get phantom code of RequestWithZ that isn't actually valid anymore It is the opposite. My IDE will show "no usages of RequestWithZ". I will not get any such help if it was encoded as Request.get("z").
- majormajor 3y agoNah, your IDE will show all the usages of RequestWithZ, but won't tell you anything about how the thing that sent RequestWithZ has been gone for two years. You'd still need instrumentation with that.
- taeric 3y agoAs the sibling post said, you probably have a ton of code that deals with what happens when a RequestWithZ appears. The thing that changed is that that isn't a thing that can actually be sent to you. Now, you are right that you can contrive a situation where you can choke off all parts that trim this down. And then you can use the type system as a tool to help delete dead code. When it works, it is a great tool. Just like the example in the original article. Please don't take my point as a complete teardown of the idea. Just don't oversell it, either.
- tharkun__ 3y agoExactly! And good tests would be of the type "should accept RequestWithZ under circumstance Y" and in many cases you'll be able to say "Oh, circumstance Y hasn't been current for like 2 years now, we can delete this code!"