8000 Fixes #1305 - Convert constants to enums by shaddockh · Pull Request #1389 · AtomicGameEngine/AtomicGameEngine · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on May 10, 2024. It is now read-only.

Fixes #1305 - Convert constants to enums #1389

Merged
merged 2 commits into from
Jan 19, 2017
Merged

Conversation

shaddockh
Copy link
Collaborator
@shaddockh shaddockh commented Jan 18, 2017

This PR adds new JS object literals to the Atomic namespace that allows for more proper enums instead of having to use constants. Now, in both TS and JS, instead of using:

Atomic.BT_STATIC

you can use

Atomic.BodyType2D.BT_STATIC

The original constants are still present in the Atomic namespace so existing code doesn't break, but it is flagged to be removed. I also left the existing constants in the d.ts, but am contemplating removing it. The repercussions would be that existing TS that uses the constants would have transpilation errors and would have to be converted to use the enums, but the JS would work fine. Also, it would clean up the auto-generated documentations and not have all those extra constants. Thoughts?

Each of the existing legacy constants has a comment stating that it is deprecated and points to the corresponding enum.

@mattbenic
Copy link
Collaborator
mattbenic commented Jan 18, 2017

I think this is a good point to discuss how obsolescence should be handled going forward. C# supports an [Obsolete] attribute, I assume there's nothing like that in JS, but there might be in TS? Besides doing this in code, it can be handled in a predictable way and announced in build release notes.

Perhaps something like the following would work:

  • Create a "Remove build 3 obsolete objects" task that references this PR, and is scheduled for build 4.
  • In Build 3's release notes mention the APIs that will become be removed in Build 4.
  • As one of the first things in build 4, actually kill those off

@JoshEngebretson just pulling you into this convo :)

@shaddockh
Copy link
Collaborator Author

I searched for some kind of [Obsolete] annotation for TypeScript as that's really handy in C#, but unfortunately there is nothing really available yet. There has been talk about how to handle it though. In the mean time, I've just added comments on those elements that will get picked up by TypeDoc.

I like the idea of creating followup tasks to remove deprecated items. That would be much better than scouring the code for TODO comments or just trying to make sure you remember that something has to be done.

@mattbenic
Copy link
Collaborator

Yeah I think we all know how often those actually lead to things being done >.>

@rosshadden
Copy link
Collaborator

There is some talk about handling deprecations and obsolutions in TypeScript here. But not currently a thing.

@JoshEngebretson
Copy link
Contributor

@shaddockh Thanks for the PR, I'll check it out a bit later, looks good from a quick glance.

Yeah, C# compiler/IDE's have good support for deprecation... on TS, would be nice, though I think we can survive for a bit, for now good to have the comments in place for future TS deprecation language feature.

Copy link
Contributor
@JoshEngebretson JoshEngebretson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good, have one question on what looks to be a bug 🐛

else if (name == "BT_DYNAMIC")
value = "2";
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice cleanup :) This is something that would be nice to be able to do in C#, though we can't due to constant requirements

{
String name = (*itr).first_;
source.AppendWithFormat("duk_push_number(ctx, (double) %s);\n", name.CString());
source.AppendWithFormat("duk_put_prop_string(ctx, -2, \"%s\");\n",name.CString());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, seems to be a bit odd here, we're using the name to format a double?

source.AppendWithFormat("duk_push_number(ctx, (double) %s);\n", name.CString());

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I copied that from how it was constructing the constants above. Those may both need to be fixed. I'll look at that.

@JoshEngebretson
Copy link
Contributor

@shaddockh Hey, some neurons misfired on that string format, which uses the variable name, I have no idea what I was thinking :)

I'll keep an eye out for any compiler warnings, though I don't think the cast to double was necessary, so in the end a few characters less code, and less code is always better 👍

Thanks! LANDING for Build 3! ✈️

@JoshEngebretson JoshEngebretson merged commit a99dc91 into master Jan 19, 2017
@JoshEngebretson JoshEngebretson deleted the TSH-ATOMIC-1305 branch January 19, 2017 12:03
@JoshEngebretson JoshEngebretson added this to the Atomic Build 3 milestone Jan 20, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
0