Skip to content
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

removed upper and lower for name #77

Merged
merged 13 commits into from
Apr 22, 2020

Conversation

pollend
Copy link
Member

@pollend pollend commented Apr 17, 2020

This issue for terasology shows kind of a key problem with transforming the name of the asset in gestalt. MovingBlocks/Terasology#3887 I think we should avoid transforming the name at all and just use the name that was provided by the asset. Any kind of additional transformation on the type seems like a good way to introducing bugs. for one case it might be uppercase but another case it could be lower. When systems intersect is where we will see kind of a mix of the two and working out if its one or the other seems like a major problem.

@pollend pollend changed the title removed cases sensitivity from name removed upper and lower for name Apr 17, 2020
@pollend pollend force-pushed the feature/removed-upper-lower branch from 1f011a0 to 8abf1e0 Compare April 17, 2020 20:37
Copy link
Member

@skaldarnar skaldarnar left a comment

Choose a reason for hiding this comment

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

I don't know whether removing/deprecating toLowerCase and toUpperCase is strictly necessary, but it will likely reduce misuse for later string comparison...

@immortius do you have any opinion on this? And what is the process of merging a change in gestalt and porting it back to v5?

@immortius
Copy link
Member

Mmmm. I'm not against removing (or deprecating) the toUpper and toLower methods, but I think we should leave toString alone - toString exists for display, introducing a new function for this isn't necessary. Also don't think it is worth changing the spelling of normalised to a perhaps slightly more correct spelling when it is only used internally.

@pollend
Copy link
Member Author

pollend commented Apr 19, 2020

my main reasoning would be that toString should return the id of the object and that choosing to display it would be a more deliberate process. we probably do more comparisons using toString vs cases where we would display the name of the object. The default behavior would be to give back the normalized version because in most cases it would be used for a comparison right?

@skaldarnar
Copy link
Member

I have to agree with both of you (to some degree). toString should be used for display, but unfortunately it isn't. Maybe @immortius is right and the main problem is that (basically all of) Terasology's code is using it wrong, but that's still no reason for changing the library.

However, I also agree with @pollend that it is a bit of bad design if it is too easy to use the class in a wrong way... toString is used implicitly in some cases, and most (new) Java programmers learn about that method, and whenever they try to compare a Name to a String they'll use the (case sensitive) one...

I'm wondering whether something like Names.compare(name, string) would help here, as it might be a bit more straightforward than name.compareTo(new Name(string)) 🤷‍♂️

@immortius
Copy link
Member

We could also add Name::compareTo(String) if that would be more straight forwards.

Copy link
Member

@skaldarnar skaldarnar left a comment

Choose a reason for hiding this comment

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

While at it - would it make sense to add contains(substring) and startsWith(prefix)/endsWith(suffix)? Would that be a bad idea as it would weaken the Name as a unit?

@@ -39,62 +39,81 @@
*/
public static final Name EMPTY = new Name("");

private final String normalised;
Copy link
Member

Choose a reason for hiding this comment

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

Let's keep it as it was - less noise in the diff.

Suggested change
private final String normalised;
private final String normalisedName;

Copy link
Member

@immortius immortius left a comment

Choose a reason for hiding this comment

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

Cheers, I'm happy with this outcome.

@immortius immortius merged commit d4b0330 into MovingBlocks:develop Apr 22, 2020
@pollend pollend deleted the feature/removed-upper-lower branch April 22, 2020 23:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants