Skip to content

Clean up resx code - #212

Merged
zsd4yr merged 14 commits into
dotnet:masterfrom
Liminiens:resx-cleanup
Jan 22, 2019
Merged

zsd4yr merged 14 commits into
dotnet:masterfrom
Liminiens:resx-cleanup

Conversation

@Liminiens

@Liminiens Liminiens commented Dec 8, 2018 •

Copy link
Copy Markdown
Contributor

Addreses #216

  • Code readability improvements
  • Compare types directly
  • Use char String.Split overload
  • Replaced str != null && str.Length > 0 pattern with String.IsNullOrEmpty
  • Use language keywords insted of BCL types
  • Removed unused parameter isMetaData in ResXResourceReader.ParseAssemblyNode
  • Removed unused field binaryFormatter in ResXResourceWriter
  • Simplified/unnested if statements where possible
  • Replaced for loops with foreach loops
  • Fixed local variable naming in a few places

@Liminiens
Liminiens requested a review from a team as a code owner December 8, 2018 14:07
@zsd4yr

zsd4yr commented Dec 8, 2018

Copy link
Copy Markdown
Contributor

I feel like I need more info on what it means to "Use newer C# features where possible"; the rest I get

@merriemcgaw

Copy link
Copy Markdown
Contributor

Thanks @Liminiens for this PR! We'll review soon and get some regression testing done offline. In the meantime, please file a corresponding issue so we can better track things. Thanks!

@zsd4yr zsd4yr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

In general, this is a great add to the codebase. A few questions we need answered before proceeding. You should also expect that you'll be asked to write unit tests for (some of) these (as we really need them). In particular, I think you could focus yourself on writing tests for functions where a change was made to:

  1. use a switch statement instead of if/elseif/else pattern
  2. create the object in scope
  3. or when this pattern "fileRef?.FileName ?? fileRefFullPath" was used

Perhaps @AdamYoblick can speak better to where tests might be most necessary

AddDataRow(elementName, info.Name, info.ValueData, info.TypeName, info.MimeType, info.Comment);
break;
}
default:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

maybe @dreddy-work can advise on what the default, if any, work should be done?

@dreddy-work dreddy-work Dec 8, 2018 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

what if value=null? or it can't be the case at all?.

I need better editor to review code. From browser, it is hard to look for the callers etc. :)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

oh I see the else below, my b

@Liminiens

Copy link
Copy Markdown
Contributor Author

@zsd4yr sorry for being unclear, with "Use newer C# features where possible" I ment "improve code readability" with things like pattern matching, object Initializer syntax in places where it could make code more clear :) I will reword the text.

@Liminiens

Copy link
Copy Markdown
Contributor Author

@merriemcgaw i added #216 for this pr :)

@Liminiens

Copy link
Copy Markdown
Contributor Author

@zsd4yr tests should be added in System.Windows.Forms.Tests, am I correct ?

@zsd4yr

zsd4yr commented Dec 9, 2018 •

Copy link
Copy Markdown
Contributor

@Liminiens because these code changes are in System.Windows.Forms, that’s correct.

There are separate test projects for each of the three binaries currently in the solution.

}
else if (names != null)
{
foreach (AssemblyName asmName in names.Where(an => an.Equals(name)))

@Therzok Therzok Dec 10, 2018 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Compared to the previous version, this now allocates a lambda capture and an enumerator instance when hit. Unroll the LINQ inline like below to keep previous performance characteristics?

foreach (AssemblyName asmName in names) {
    if (!name.Equals (asmName))
        continue;

    ...
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Not sure if we want to preemptively optimize generally; however, this is a good suggestion for this spot.

This is only of concern if these allocations take a "too much" time, as they should be on the stack?

@Liminiens

Copy link
Copy Markdown
Contributor Author

@AdamYoblick @zsd4yr I added some tests, mostly for ResXFileRef.Converter. Can you take a look? :)

@sharwell sharwell left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Temporarily marking as blocked while I discuss a couple of items with the team. Normally changes to code style are only submitted by one of the project maintainers for two reasons:

  1. Avoid code churn in areas where the project has not adopted and applied a unified style
  2. Strictly contain style changes by subject, and ensure the changes are applied in a manner that works well with source control history (see e.g. dotnet/roslyn#31652 which was internally coordinated and applied to minimize disruption)

@Liminiens

Copy link
Copy Markdown
Contributor Author

There are missing explicit this. in some places . Should I add them?

@sharwell

sharwell commented Dec 12, 2018 •

Copy link
Copy Markdown
Contributor

@Liminiens Please note that even if the style changes from this aren't brought in, I'll find a way to ensure the tests you added are correctly assigned with you as the contributor. It can be hard to find people to write tests and very much appreciated when someone takes the time to do so.

Also note that you probably shouldn't take direct action per my previous comment at this time. It's possible the style changes are handled separately, but it's also possible an exception (full or partial) gets made for this pull request. I won't know more until I meet with the maintainers.

@Liminiens

Copy link
Copy Markdown
Contributor Author

@sharwell ok, understood :)

@zsd4yr

zsd4yr commented Dec 12, 2018 •

Copy link
Copy Markdown
Contributor

@Liminiens I am going to rake through this PR later this afternoon and mentally separate your changes into (1) code upgrades and (2) style changes.

Likely we will need to work together afterwords to separate our your style changes as we have yet to agree on a cohesive style. Sorry to burden you with this, but the team really wants to take these code upgrades; we're just not ready for the style changes 😭

@sharwell
sharwell dismissed their stale review December 12, 2018 19:49

@zsd4yr is following up on the code style issues

@zsd4yr

zsd4yr commented Dec 12, 2018

Copy link
Copy Markdown
Contributor

@Liminiens I've finished my review; going to circulate among the team for feedback before sharing 😄 Don't want to tell you something and then later be wrong...

I'll come back to this thread once things are settled. Hopefully later this week

@zsd4yr

zsd4yr commented Jan 16, 2019

Copy link
Copy Markdown
Contributor

@Liminiens I believe we are satisfied to take this once you have had a chance to resolve these merge conflicts.

…-cleanup

# Conflicts:
#	src/System.Windows.Forms/src/System/Resources/ResXDataNode.cs
#	src/System.Windows.Forms/src/System/Resources/ResXFileRef.cs
#	src/System.Windows.Forms/src/System/Resources/ResXResourceWriter.cs
@Liminiens

Copy link
Copy Markdown
Contributor Author

@zsd4yr done :)

AddDataRow(elementName, info.Name, info.ValueData, info.TypeName, info.MimeType, info.Comment);
break;
}
default:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

oh I see the else below, my b

@zsd4yr zsd4yr closed this Jan 19, 2019
@zsd4yr zsd4yr reopened this Jan 19, 2019
@zsd4yr
zsd4yr merged commit f8cafef into dotnet:master Jan 22, 2019
rainersigwald added a commit to rainersigwald/msbuild that referenced this pull request Jan 24, 2019
@ghost ghost locked as resolved and limited conversation to collaborators Feb 8, 2022
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.

8 participants