You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@reef.apache.org by Mariia Mykhailova <ma...@microsoft.com> on 2016/08/04 22:24:16 UTC

Why IMRU IMapFunction and IUpdateFunction are not disposable?

Hi,

It seems that map and update functions in IMRU should be disposable, because they are user-provided and stateful and thus might have some resources which should be released after job completion. Is there a reason why they are not disposable?

-Mariia

RE: Why IMRU IMapFunction and IUpdateFunction are not disposable?

Posted by Mariia Mykhailova <ma...@microsoft.com>.
Thank you. I've filed REEF-1518 to implement this.

-Mariia

-----Original Message-----
From: Anupam [mailto:anupam128@gmail.com] 
Sent: Friday, August 5, 2016 3:28 PM
To: dev@reef.apache.org
Subject: Re: Why IMRU IMapFunction and IUpdateFunction are not disposable?

In order to avoid bleeding IDisposable across the codebase, I agree with Markus' approach.
More importantly, being IDisposable is usually an implementation detail and may be it should be avoided on interfaces.

> Couldn't we change the IMRU tasks such that they check whether a 
> specific user provided function implements `IDisposable` and, if so, 
> calls `.Dispose()` on it?

Properly programming to an interface where we expect a few implementations to be IDisposable (yes, this is ambiguous, but in practice it works) can be done as:

public interface IFoo
{}


public class FooDisposable : IFoo, IDisposable {
    ...
}

public class Foo : IFoo
{}

public static void Main()
{
    ...
    var foo = <get IFoo from somewhere>;

    var fooDisposable = foo as IDisposable;

    // the empty using statement disposes foo if it is IDisposable else is noop as fooDisposable is null.
    using(fooDisposable){}
}


Hope this helps.

Please refer to Section 8.13 of C# Language Specification for details about the using statement.


On 5 August 2016 at 09:36, Markus Weimer <ma...@weimo.de> wrote:
> On 2016-08-04 3:24 PM, Mariia Mykhailova wrote:
>>
>> It seems that map and update functions in IMRU should be disposable, 
>> because they are user-provided and stateful and thus might have some 
>> resources which should be released after job completion. Is there a 
>> reason why they are not disposable?
>
>
> If we make them `IDisposable`, all such functions have to implement 
> the `.Dispose()` method, right? Couldn't we change the IMRU tasks such 
> that they check whether a specific user provided function implements 
> `IDisposable` and, if so, calls `.Dispose()` on it? That way, we don't 
> broaden the required interfaces, yet support disposing. Or is that an 
> anti-pattern in .NET?
>
> Thanks,
>
> Markus



--
Anupam
Bellevue, WA
Ph: +1 (425)-777-5570

Re: Why IMRU IMapFunction and IUpdateFunction are not disposable?

Posted by Anupam <an...@gmail.com>.
In order to avoid bleeding IDisposable across the codebase, I agree
with Markus' approach.
More importantly, being IDisposable is usually an implementation
detail and may be it should be avoided on interfaces.

> Couldn't we change the IMRU tasks such that they
> check whether a specific user provided function implements `IDisposable`
> and, if so, calls `.Dispose()` on it?

Properly programming to an interface where we expect a few
implementations to be IDisposable (yes, this is ambiguous, but in
practice it works) can be done as:

public interface IFoo
{}


public class FooDisposable : IFoo, IDisposable
{
    ...
}

public class Foo : IFoo
{}

public static void Main()
{
    ...
    var foo = <get IFoo from somewhere>;

    var fooDisposable = foo as IDisposable;

    // the empty using statement disposes foo if it is IDisposable
else is noop as fooDisposable is null.
    using(fooDisposable){}
}


Hope this helps.

Please refer to Section 8.13 of C# Language Specification for details
about the using statement.


On 5 August 2016 at 09:36, Markus Weimer <ma...@weimo.de> wrote:
> On 2016-08-04 3:24 PM, Mariia Mykhailova wrote:
>>
>> It seems that map and update functions in IMRU should be disposable,
>> because they are user-provided and stateful and thus might have some
>> resources which should be released after job completion. Is there a
>> reason why they are not disposable?
>
>
> If we make them `IDisposable`, all such functions have to implement the
> `.Dispose()` method, right? Couldn't we change the IMRU tasks such that they
> check whether a specific user provided function implements `IDisposable`
> and, if so, calls `.Dispose()` on it? That way, we don't broaden the
> required interfaces, yet support disposing. Or is that an anti-pattern in
> .NET?
>
> Thanks,
>
> Markus



-- 
Anupam
Bellevue, WA
Ph: +1 (425)-777-5570

Re: Why IMRU IMapFunction and IUpdateFunction are not disposable?

Posted by Markus Weimer <ma...@weimo.de>.
On 2016-08-04 3:24 PM, Mariia Mykhailova wrote:
> It seems that map and update functions in IMRU should be disposable,
> because they are user-provided and stateful and thus might have some
> resources which should be released after job completion. Is there a
> reason why they are not disposable?

If we make them `IDisposable`, all such functions have to implement the 
`.Dispose()` method, right? Couldn't we change the IMRU tasks such that 
they check whether a specific user provided function implements 
`IDisposable` and, if so, calls `.Dispose()` on it? That way, we don't 
broaden the required interfaces, yet support disposing. Or is that an 
anti-pattern in .NET?

Thanks,

Markus