Results 1 to 3 of 3

Thread: Enhancement: Add default values to slice definitions

  1. #1
    joshmoore is offline Registered User
    Name: Josh Moore
    Organization: Glencoe Software, Inc.
    Project: OMERO, http://trac.openmicroscopy.org.uk/omero
    Join Date
    Feb 2007
    Location
    Germany
    Posts
    115

    Enhancement: Add default values to slice definitions

    Just a quick suggestion, without knowing how practical it is: it'd be very convenient to be able to specify default values in the slice mapping files.

    Code:
    module omero {
        module grid {
    	class JobParams {
    	    string name;
    	    string description;
                int timeout = 30; // Seconds
                ...
    Though there may need to be some restrictions on how many, what types, etc. this could simplify using constructors significantly.

    Code:
    # python
    
    class JobParams:
        def __init__(self, name, description, timeout = 30):
            ...
    j = omero.grid.JobParams("name", "description")
    Code:
    // Java
    public class JobParams {
    
       public JobParams(String name, String description) {
           this(name, description, 30);
       }
    ...

  2. #2
    michi's Avatar
    michi is offline Registered User
    Name: Michi Henning
    Organization: Triodia Technologies
    Project: I have a passing interest in Ice :-)
    Join Date
    Feb 2003
    Location
    Brisbane, Australia
    Posts
    1,055
    Doing this would be problematic in the face of the various language mappings. For example, with C++, a Slice struct with such an initializer would require the generated code to add a constructor to the corresponding C++ structure. However, that would prevent the structure from being used as a POD (plain old data type) and prevent static initialization.

    There is also the issue of run-time overhead. For example, when unmarshaling a sequence of structures, we would incur the overhead of default-initializing each structure in a vector, only to then have to overwrite the contents of the structure with the unmarshaled data anyway.

    In general, default initialization such as you suggest is an implementation concern, but Slice is an interface definition language. In other words, Slice is almost certainly the wrong level of abstraction to implement such a feature.

    One way to achieve what you want is to define a sub-class or sub-structure in your application code. For example:

    Code:
    // C++
    class MyJobParams : public JobParams // JobParams generated from Slice
    {
    public:
        MyJobParams() { timeout = 30; }
    };
    If you want an initialized class, simply instantiate MyJobParams. Because MyJobParams derives from JobParams, you can pass that instance whereever a value of type JobParams is expected.

    Cheers,

    Michi.

  3. #3
    joshmoore is offline Registered User
    Name: Josh Moore
    Organization: Glencoe Software, Inc.
    Project: OMERO, http://trac.openmicroscopy.org.uk/omero
    Join Date
    Feb 2007
    Location
    Germany
    Posts
    115
    Hi, Michi. Thanks for the response. Obviously, this is more of a pie-in-the-sky wish, so no hard arguments from me below, but a few thoughts.

    Quote Originally Posted by michi View Post
    Doing this would be problematic in the face of the various language mappings [...] would prevent the structure from being used as a POD (plain old data type) and prevent static initialization....There is also the issue of run-time overhead. For example, when unmarshaling a sequence of structures, we would incur the overhead of default-initializing each structure in a vector, only to then have to overwrite the contents of the structure with the unmarshaled data anyway.
    Definitely understood. As I mentioned there would need to be either restrictions on such a feature or a clear description of the performance penalties.

    Quote Originally Posted by michi View Post
    In general, default initialization such as you suggest is an implementation concern, but Slice is an interface definition language. In other words, Slice is almost certainly the wrong level of abstraction to implement such a feature.
    In most cases, but as with the JobParams this is actually a DTO to permit complicated parameters to be built up for a single method invocation. I.e. something between an interface and an implementation concern.

    On the other hand, default values would be just as useful in interface methods, which would be the case here if I were to flatten JobParam into a long argument list.

    Quote Originally Posted by michi View Post
    One way to achieve what you want is to define a sub-class or sub-structure in your application code.
    Sure. My current issue as with JobParams is attempting to unify multiple language bindings for a single API. Dealing with default values at the subclass/object-factory level feels strongly of repetition, and I was looking for a way to delegate that to the code-generation.

    Again, thanks for the consideration.
    ~Josh.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Documentation enhancement: Update to demo code
    By Gravitas in forum Bug Reports
    Replies: 2
    Last Post: 03-11-2011, 11:45 AM
  2. Replies: 10
    Last Post: 03-20-2006, 10:59 PM
  3. Replies: 1
    Last Post: 06-14-2005, 12:44 PM
  4. Why not add DBC feature to Slice?
    By microweb in forum Comments
    Replies: 3
    Last Post: 12-07-2003, 07:29 AM
  5. tests enhancement requests
    By marlowa in forum Comments
    Replies: 1
    Last Post: 02-20-2003, 07:51 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •