lightblue-platform / lightblue-client

GNU General Public License v3.0
5 stars 24 forks source link

Deal with null QueryExpression and Projections in DataFindRequest better #74

Open alechenninger opened 9 years ago

alechenninger commented 9 years ago

Few options:

As an aside, this is why the Builder pattern is much prefered than mutable objects:

So I guess I'm suggesting IMHO moving all of these requests to a builder pattern where the final object is immutable and guaranteed valid, but ultimately anything other than throwing an NPE would be nice.

dcrissman commented 8 years ago

@alechenninger is this still a concern?

alechenninger commented 8 years ago

Can you still create requests in an invalid state?

In other words, as a good design practice, I'd like to be able to create a request and see what is required from its constructor, and if something is omitted, it has a reasonable default. I don't want to find out I missed something vital only once I go to integration test it with a running lightblue API.

My 2c

dcrissman commented 8 years ago

Accept a QueryExpression and Projection(s) in constructor. This prevents the DataFindRequest from being allow to be in an invalid state which is a bad practice for constructors (allowing objects which will never actually work without more configuration).

I agree that a constructor shouldn't leave the object in an incomplete state (an issue I have with a lot of DI frameworks). I do like the expression style methods we currently have. So yeah, a builder would be the correct way to deal with this.

Throw something other than NPE if either are omitted (but this is still failing at runtime which is bad IMHO)

You shouldn't get a RuntimeException any more, but you will still get an exception from lightblue in the form of a LightblueResponseException.

Use a default QueryExpression and Projection if either is omitted (then you could also implement the first suggestion)

  • We might be able to get away with a default Projection for a recursive return everything, but I don't like that idea and think the client really should be providing this for each execution.
  • A default Query I feel is a bad idea.
alechenninger commented 8 years ago

I only suggested defaults as a fallback if you didn't make it explicit was required by a constructor or some other means.

If requests are able to be created invalid still, then we should at least throw an exception client side for obvious problems rather than waiting for lightblue to respond with an error. That is, if you're missing a projection for a query where it is required, throw an error client side like, InvalidRequestException or some such thing and explain what the problem is.

alechenninger commented 8 years ago

In other words, when I say failing at runtime is bad, it's only bad relative to failing at compile time. In other words

Catching failure at compile time (via combination of constructor forcing arguments and/or defaults) > Catching failure at runtime client side > Catching failure at runtime lightblue side

Waiting til it gets to lightblue is a bad time to find out you have an otherwise detectable bug in your query code basically.

josh-cain commented 8 years ago

Can I +1 this? #257 happened to me because I can construct invalid queries. As someone who has been working with LB for about a week now, I can say that a fluent builder that guaranteed a correct query would be fantastic. If you're not well-versed in the query syntax and internals there's plenty of rope out there with which it's easy to hang yourself.