Skip to content

Tidy up, modernise code and VS cleanup#1920

Closed
BobLd wants to merge 3 commits into
oxyplot:developfrom
BobLd:cleanup
Closed

Tidy up, modernise code and VS cleanup#1920
BobLd wants to merge 3 commits into
oxyplot:developfrom
BobLd:cleanup

Conversation

@BobLd

@BobLd BobLd commented Aug 16, 2022

Copy link
Copy Markdown
Contributor

Checklist

  • I have included examples or tests (no need)
  • I have updated the change log
  • I am listed in the CONTRIBUTORS file
  • I have cleaned up the commit history (use rebase and squash)

Changes proposed in this pull request:

@oxyplot/admins

@VisualMelon

Copy link
Copy Markdown
Contributor

Can we lose the dropping of the space before /> (for this PR at least)? That's creating a lot of noise here, and wasn't in the original PR, so it's hard to check the other changes.

@BobLd

BobLd commented Aug 17, 2022

Copy link
Copy Markdown
Contributor Author

@VisualMelon I know there are a lot of files changed due to that, my bad. But I can't really easilly revert that back on my side.

Maybe the easiest is to Hide whitespace in the 'Files changed' tab. This should help a lot, let me know what you think
image

@VisualMelon

Copy link
Copy Markdown
Contributor

Maybe the easiest is to Hide whitespace in the 'Files changed' tab

Thanks ;) feels like I'm having to relearn how to use github at the moment.

Could we change it to the opposite? (i.e. add the spaces before /> rather than removing them). It's totally arbitrary, and if thsi was an accidental change on your behalf then that would be my preference if it's just as easy and no-one has any particular objection.

Tagging @HavenDV who has suggested we sort out some XAML standards, and who might know better what is the Zeitgeist on XML whitespace.

@VisualMelon

Copy link
Copy Markdown
Contributor

Don't know why azure is failing at the moment; I doubt it's anything wrong with this PR.

@VisualMelon

Copy link
Copy Markdown
Contributor

Slowly getting through these; all looks sane so far.

@BobLd just to check, are these otherwise all the automatic changes from the old PR?

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

There are a few changes here I wouldn't personally make, but nothing too objectionable. is patterning, ?. on events, and readonly properties are nice. Everything else seems reasonable enough.

Couple suggestions below among examples of things that don't fill me with joy.

Comment thread Source/OxyPlot/Axes/Rendering/AngleAxisFullPlotAreaRenderer.cs Outdated
Comment thread Source/OxyPlot/Axes/Rendering/MagnitudeAxisFullPlotAreaRenderer.cs Outdated

double nextInterval = goodIntervals.FirstOrDefault(i => i > interval);
if (nextInterval == default(double))
if (nextInterval == 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.

Not sure I like this, but if it's automatic, so be it.

protected void BindCore(OxyInputGesture gesture, IViewCommand command)
{
var current = this.InputCommandBindings.FirstOrDefault(icb => icb.Gesture.Equals(gesture));
var current = this.InputCommandBindings.Find(icb => icb.Gesture.Equals(gesture));

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.

Prefer FirstOrDefault, but again, if this is an automatic change it's OK.

Comment thread Source/OxyPlot/Imaging/Deflate/Deflate.cs
else
{
c = c >> 1;
c >>= 1;

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 wild about this, but again, if it's automatic I'm not bothered.

if (dh > 0.5)
{
dh -= 1.0;
dh--;

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.

Again, prefer version which makes it clear this is a float, but not going to fight VS over it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

you're making a good point, happy to revert back and disable the warning. @VisualMelon what do you think?

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.

Yep, if it's easy to disable this whole class of warning that'd be great.

Comment thread Source/OxyPlot/Series/ItemsSeries.cs Outdated
Comment thread Source/OxyPlot/Svg/SvgRenderContext.cs Outdated
List<double> binBreaks = new List<double>(binCount + 1);

binBreaks.Add(start);
List<double> binBreaks = new List<double>(binCount + 1)

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.

Don't like this much either, but again, if it's automatic, I'll live.

@HavenDV

HavenDV commented Aug 17, 2022

Copy link
Copy Markdown
Contributor

I would prefer this PR to be broken down into separate PRs that change one type of style at a time. For example, a PR that changes strings to nameof and so on. This makes it much easier to check.
Regarding spaces - https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/xmldoc/recommended-tags#generate-links-and-references contains values without spaces, so I would prefer that(in In my code, I also use xml tags in xml documentation without spaces before />).

@VisualMelon

Copy link
Copy Markdown
Contributor

@HavenDV thanks. Looks like /> is OK then.

@VisualMelon

Copy link
Copy Markdown
Contributor

Separate commits would be nice, but I don't think it's too big a problem if it's difficult or time-consuming.

@HavenDV

HavenDV commented Aug 17, 2022

Copy link
Copy Markdown
Contributor

I will wait for progress on this PR before continuing with nullable enable PRs

@BobLd

BobLd commented Aug 20, 2022

Copy link
Copy Markdown
Contributor Author

@VisualMelon @HavenDV I've implemented your feedback.

  • Regarding the separate commits, I agree but it was really easier to do in one go
  • The changes here are indeed mainly from the other PR, but reviewed them again
  • For the Azure issue, I agree, I'm not sure what's going on... Let me know if you have an idea, or if I need to change something

Once I have your go, I will squash the commits to make it clean

@VisualMelon

VisualMelon commented Aug 20, 2022

Copy link
Copy Markdown
Contributor

@BobLd I'll probably not have time to look at this properly for a quite a few days, but nothing jumps out to me as a problem. Re. azure, looks like it has never worked for the .NET Core versions of the tests, but at some point it started failing noisily rather than silently. I tried a few things to make it happy (see the open PRs), but failed and ran out of time. Not a problem for this (or any other) PR so long as we check it's the .NET Core tests failing and not something unexpected.

Don't worry about squashing: can do that within the github interface now.

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

If it is possible to turn off the automatic contraction for x = x (whater) y to x (whatever)= y that would be good. None of the instance here improve readability, and I think a number of then make it worse.

I also really don't like all the checks of the form x?.y > z: this is producing a bool from an int? > int comparison and that's just wrong. bool? == bool is acceptable, but very happy for that to be disabled as well if they're all under one rule.

I'd also much prefer if it didn't remove all the empty lines within methods.

double y_portion = delta_y / _y;
lineend_x = y_portion * _x;
lineend_y = y_portion * _y;
result = new ScreenPoint((y_portion * _x) + midPoint.X, (y_portion * _y) + midPoint.Y);

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 change this to use lineend_* instead; probably clearer.

// </copyright>
// <summary>
// Provides information about an <see cref="OxyImage" />.
// Provides information about an <see cref="OxyImage />.

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.

Something looks fishy here.

byte[] streamBytes = null;

if (this.contents != null && this.contents.Length > 0)
if (this.contents?.Length > 0)

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.

I was a bit unsure about this last time, now I'm sure I don't like it... Don't want to lose the event refits etc. but these nullable comparisons are not nice. There are some instances of blah?.blah() == true also, but if they're not nearly as bad.

Don't know what others opinions are on this, but this sort of lifting makes me very uncomfortable.

Comment on lines +97 to +101
this.IsPanEnabled = (this.XAxis?.IsPanEnabled == true)
|| (this.YAxis?.IsPanEnabled == true);

this.IsZoomEnabled = (this.XAxis != null && this.XAxis.IsZoomEnabled)
|| (this.YAxis != null && this.YAxis.IsZoomEnabled);
this.IsZoomEnabled = (this.XAxis?.IsZoomEnabled == true)
|| (this.YAxis?.IsZoomEnabled == true);

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.

Per the above comment about lifting with comparisons, these are OK, but also not going to complain if they are lost if it means we can keep the rules simple.

if (dh > 0.5)
{
dh -= 1.0;
dh--;

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.

Yep, if it's easy to disable this whole class of warning that'd be great.

Comment thread Source/OxyPlot/Rendering/OxyRect.cs
this.StrokeColor = OxyColors.Black;
this.StrokeThickness = 0;
this.TrackerFormatString = XYAxisSeries.DefaultTrackerFormatString;
this.TrackerFormatString = DefaultTrackerFormatString;

@VisualMelon VisualMelon Aug 21, 2022

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.

These are OK, but again, if there's a way to turn them off, I think these are clearer as they were.

This could lead to inconsistency, however. What are others' opinions?

{
this.MinY = Math.Min(this.ActualItems.Min(r => 0), this.ActualItems.Min(r => r.Height));
this.MaxY = Math.Max(this.ActualItems.Max(r => 0), this.ActualItems.Max(r => r.Height));
this.MinY = Math.Min(0, this.ActualItems.Min(r => r.Height));

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.

(Note: this is OK: checks that the collection isn't empty above)

@VisualMelon

VisualMelon commented Aug 21, 2022

Copy link
Copy Markdown
Contributor

@BobLd thanks for your changes. If we can change a few of the rules per the above, that's great. I don't know much about how this is all configured (must be editor config or something?), but obviously if we can use the VS defaults where possible and only disable those rules that we've agreed are problematic that'd be great. I didn't see a config file in the PR: does it just need adding or have I missed something? (e.g. my VS doesn't light up all of these same things).

@Jonarw Jonarw left a comment

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.

Thanks for tackling this task! I think I can get behind pretty much all of the changes. I'd just have two additional comments:

  • (As already mentioned by @VisualMelon) Would it be possible to include a VS configuration file, so others would get the same automatic suggestions and refactorings regarding code style? I think this should be possible with an EditorConfig file.
  • Could we define (and enforce) a consistent code style regarding var usage? I think this is still a bit all over the place in different sections of code. My personal style is to always use var wherever possible, but I would also be happy with other conventions, as long as it is consistent.

@VisualMelon

Copy link
Copy Markdown
Contributor

@BobLd CI should be happy after a rebase

@VisualMelon

Copy link
Copy Markdown
Contributor

@BobLd if you can include a VS configuration file I'll take another look at this

@Jonarw

Jonarw commented Jul 12, 2023

Copy link
Copy Markdown
Member

Following the discussion in #2012, I will close this for now and revisit once we have fewer open PRs. If you have a VS config file that you could share you are welcome to do so, if not no worries :)

@Jonarw Jonarw closed this Jul 12, 2023
@BobLd

BobLd commented Jul 12, 2023

Copy link
Copy Markdown
Contributor Author

Thanks for that @VisualMelon, I'll try to do something along the lines but focusing on other projects at the moment

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.

4 participants