New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revise "undefined" concept #782

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

Comments

Projects
None yet
6 participants
@DaniilVeriga
Contributor

DaniilVeriga commented Dec 22, 2015

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

This comment has been minimized.

Show comment
Hide comment
@johnwason

johnwason Dec 23, 2015

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?

johnwason commented Dec 23, 2015

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

This comment has been minimized.

Show comment
Hide comment
@SamuelEnglard

SamuelEnglard Jan 13, 2016

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

SamuelEnglard commented Jan 13, 2016

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

This comment has been minimized.

Show comment
Hide comment
@johnwason

johnwason Jan 13, 2016

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))

johnwason commented Jan 13, 2016

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

This comment has been minimized.

Show comment
Hide comment
@SamuelEnglard

SamuelEnglard Jan 13, 2016

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

SamuelEnglard commented Jan 13, 2016

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

This comment has been minimized.

Show comment
Hide comment
@geoffreymcgill

geoffreymcgill Jan 13, 2016

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.

Member

geoffreymcgill commented Jan 13, 2016

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

This comment has been minimized.

Show comment
Hide comment
@Suchiman

Suchiman Jan 14, 2016

@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.

Suchiman commented Jan 14, 2016

@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 added a commit that referenced this issue Jan 24, 2016

@LeonidVeriga LeonidVeriga added feature and removed review labels Feb 2, 2016

@DaniilVeriga

This comment has been minimized.

Show comment
Hide comment
@DaniilVeriga

DaniilVeriga Feb 2, 2016

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.

Contributor

DaniilVeriga commented Feb 2, 2016

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