12 Replies
releaseAPI
VercelApi
so... minor low hanging fruit, you can and should reused the HttpClient.
you can also just use a statement based using.
using HttpClient client = new();
There's no validation that the data you get back is in the correct format.
using Newtonsoft.Json;
, then you don't need Newtonsoft.Json.JsonConvert.DeserializeObject
, just JsonConvert...
I'd also use linq instead of your loops, but that's just cause I love LINQ so much.
Put constants like those URLs in
static readonly
fields, rather than just hard-coding thjem
Then later:
there is no need to
ToList
all the time.
If console formatting is super important to you, check out a library like Spectr or whatever.
otherwise, I mean the two biggest no-nos I saw were not reusing the HttpClient and the excess to list.i know, i am just new to the linq so i am trying to figure out how to linq
most of the rest is just outdated syntax and preference.
fair enough. Well, there isn't anything especially wrong with your first loop. Some people might prefer that logic.
But you don't need to
ToList
versions later on.
You can just save the result of versions.Except
and foreach that.
or even move it into the foreach call, and save a line.
my personal rule of thumb is less, more complex code is generally better than more verbose "simpler" code. Because the fewer llines of code I have the fewer I have to try and keep in memory.the reson of the !contains("delta") was to remove duplicate data. any faster way?
mmm... probably not.
Contains
should be pretty well optimized.
It's going to use vector instructions to examine the string quickly.
I suppose since you know that if its present it's going to be at a certain position you could slice the string with Span
and search a smaller segment.
Though I think that's a questionable improvement. It makes the code less flexible and speed is hardly going to matter here.
Honestly, you might consider using regex instead. It will be slower, but a single regex pattern is easier to update and understand than a lot of split and indexed based magic. And more adaptable to changes in format.
Don't worry about speed unless it really matters. While string operations and parsing can be slow your bottleneck here is almost certainly going to be the file download anyways.
So optimize first for flexibility and readability, rather than performance, I say.
actually regex might not even be slower than a lot of splits, come to think of it. You'd have to benchmark to determine I suppose.