splunk-sdk-python icon indicating copy to clipboard operation
splunk-sdk-python copied to clipboard

Top level methods should not return generic objects

Open ansman opened this issue 15 years ago • 3 comments

Service#confs for example returns a Collection object which is really confusing, just having an empty class called Confs that inherit from Collection would be so much simpler.

ansman avatar Nov 04 '11 02:11 ansman

I'm not sure I agree. Polluting the namespace with empty objects seems unnecessary and bad practice. Nearly all Splunk collections have the same behavior, so no reason to give each one a different name. But, I'm willing to be swayed with a great argument :)

itay avatar Nov 04 '11 02:11 itay

Well, then it's really unclear on what a method returns and it will be hard to create a good documentation.

It's easy to doc that Service#confs returns a collection item but much harder to doc how to get a specific conf file.

I my opinion I would skip the lambda functions (which we had a hard time figuring out what they do) and just implement those lambda functions a member functions:

class Confs(Collection):
    # From Collection
    def _item(self, service, conf):
        return Conf(...)

ansman avatar Nov 04 '11 03:11 ansman

There are two separate issues here.

  1. A request to create, in effect, "nominal" types to reflect the various distinct entity & collection types

  2. A request to parameterize the collection implementations using subclass overrides instead of the current method of passing optional lambdas to the "base" class constructor.

Both requests would be completely natural in an object oriented language, but Python is "structurally" typed (duck typed, if you prefer) and in my opinion we are better off with a more functional style of usage, which has been our general approach in this SDK.

Regarding the specific asks:

  1. Python is not a nominally typed language and I think it would be a mistake to create empty types to play the role of a named placeholder.

  2. I think the current implementation has the advantage of being more compact and reducing the proliferation of types and I am not convinced that it is surprising when considered from the point of view of a dynamic language with higher order functions.

blovering avatar Feb 28 '12 04:02 blovering