Revise "undefined" concept #782

Closed
DaniilVeriga opened this Issue Dec 22, 2015 · 7 comments

Projects

None yet

6 participants

@DaniilVeriga
Contributor

http://forums.bridge.net/forum/general/open-discussions/1320

"undefined" is a strange concept in C#. Having it map to "null" would be easier to deal with.

@DaniilVeriga DaniilVeriga added the review label Dec 22, 2015
@DaniilVeriga DaniilVeriga changed the title from Revise Undefined concept to Revise "undefined" concept Dec 22, 2015
@johnwason

After looking at the problem more I am not sure what I suggested makes sense. Maybe have a utility method IsNullOrUndefined somewhere instead of mapping undefined to null?

@SamuelEnglard

A thought would be to map undefined to a "class", something like

public static class Undefined
{
    private static readonly object _internal = new object();

    public static object Undefined
    {
        get
        {
            return _internal;
        }
    }
}

So Undefined.Undefined compiles down to just undefined

@johnwason

Currently there is the definition "Script.undefined" that can be used to compare to "undefined". This leads to a lot of code:

if (myvar == null || myvar == Script.undefined)
{
    //Do something to deal with unset variable
}

I think that this is what you suggest. Maybe replace the comparison with a utility function:

if (Script.IsNullOrUndefined(myvar))
@SamuelEnglard

Ah, yes. In that case I think such a utility function could work. Though I think I might make it an extension method on Object

@geoffreymcgill
Member

I like the idea of an extension method on Object, although I'm a little reluctant to be bolting on unexpected members to native classes.

The Script class might also get separated out into the Html5 project with v1.11, and since undefined is not a C# concept, all references to undefined within the main Bridge project will likely be moved to Html5 as well.

I'm just speculating here, and haven't taken a really good look at the implications of this reorganization. Once we get in there (this week) we'll have a better understanding of what needs to change.

Thanks for the great feedback and comments.

@Suchiman

@johnwason there's Validation.IsNotNull() which is basically defined as typeof value !== "undefined" && value !== null;

But i agree that undefined is currently being handled awkwardly.

@geoffreymcgill geoffreymcgill added this to the 1.11 milestone Jan 18, 2016
@vladsch vladsch added a commit that referenced this issue Jan 24, 2016
@vladsch vladsch [TEST] [#782] Update unit tests 1668d82
@LeonidVeriga LeonidVeriga added feature and removed review labels Feb 2, 2016
@DaniilVeriga
Contributor

With the upcoming 1.11 release obj === null check will be emitted as !Bridge.hasValue(obj) that actually checks on both - null and undefined. We will appreciated any feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment