-
Notifications
You must be signed in to change notification settings - Fork 47
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
Preliminary formatting changes #518
Conversation
ccd5b30
to
a2c5d62
Compare
a2c5d62
to
50c734d
Compare
…ent that always results in false in spellcrafter, need to come back to this and see if it is the same end result
…e autoformatter to crash
50c734d
to
7ff3f41
Compare
7ff3f41
to
0c7a64f
Compare
return incentivePool.Concat(ItemLists.AllQuestItems).Distinct().ToList(); | ||
List<Item> incentivePool = new(); | ||
|
||
if (flags.IncentivizeMasamune ?? false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this might be the only thing that's really bothering me, as this change lowers readability imo, but this might be also a sign that these flags should be handled differently
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would have hoped that it would at least make one-liners to make the whole thing a little more compact.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that this makes it less readable, though in most cases cramming as much into one line as possible isnt great imo, so as a general rule I think this is good, but this function likely needs exceptions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make a list that maps flags to items and iterate over the list with a simple function.
this looks good to me |
If it's anything like prettier it switches to multiline when it doesn't fit within the line length you specify. If we don't explicitly set one somehow it's probably like 120 chars. In my experience, forced style is worth the price of nobody being 100% happy with what it looks like, as long as IDE integrations can be tweaked to everybody's liking. I've been a format-on-save dude for a few years now, and just not even thinking about pressing enter or spacing things properly while coding, knowing that just saving once makes everything 'perfect' is a cool thing to get used to. |
HashSet<Item> MehItems = new HashSet<Item>(ItemLists.RareWeaponTier.Concat(ItemLists.RareArmorTier).Distinct()); | ||
HashSet<Item> SparkleItems = new HashSet<Item>(ItemLists.AllGoldTreasure); | ||
|
||
var locations = rom.generatedPlacement.Where(p => p is TreasureChest).GroupBy(p => p.MapLocation); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is var not allowed here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because the current rules chooise IDE0008 over IDE0007
https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/ide0007-ide0008
Personally, I do prefer explicit types, but this is all up for discussion
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like var (I mean, it's less work), but since we're manipulating a lot of lists and arrays explicit types are way clearer at first glance and should make it easier for newcomers to figure out what the randomizer is doing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
one thing that is nice, is you can program it with var, then run the formatter and it will try to replace it with the correct type (it only failed a couple times for me and that was when I had a config issue resulting in the formatter not understanding what a Blob is)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2 years ago i preferred explicit types as well. But when using linq, things can get out of hands very easily like:
foreach (IEnumerable<IGrouping<KeyValuePair<string, Tuple<string, string>>> item in list)
and become really readable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm. I like var
for pretty much everything except primitive types like int
and ushort
. Usually when you're doing a complicated LINQ statement, you don't really care what the exact type is because you're just going to iterate over it in a sec. You can always hover to see the type anyway if you need to.
{ | ||
0x7C649, 0x7C6F9, 0x7C75A, 0x7C75B, 0x7C62D, 0x7C75D, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my opinion, inflating that list is also not ideal.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, this is likely a rule we need to tweak, or we need to add a few exceptions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to disable the style checker for one line with a comment?
Data[0x31F85 + i * 2] = (byte)(xCoord - 0x10); // X Coord of Character targeting cursor | ||
Data[0x31F86 + i * 2] = (byte)(yCoord + 4 + ((i % 4) * 0x1C)); // Y Coord of Character targeting cursor | ||
Data[0x31F76 + i * 2] = (byte)(0xA7 + (Math.Min(i, 4) % 4 * 0x10)); // Y Coord of Command Menu cursor (last four are identical) | ||
Data[0x31F85 + (i * 2)] = (byte)(xCoord - 0x10); // X Coord of Character targeting cursor |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we don't have to do this, do we?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this does not change the functionality, it is the result of choosing IDE0048 over IDE0047
https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/ide0047-ide0048
basically, the formatter will automatically add parentheses anywhere that might cause confusion, so people later on dont make a mistake when reading the code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but that operator precedence you usually learn around the age of 10
return incentivePool.Concat(ItemLists.AllQuestItems).Distinct().ToList(); | ||
List<Item> incentivePool = new(); | ||
|
||
if (flags.IncentivizeMasamune ?? false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would have hoped that it would at least make one-liners to make the whole thing a little more compact.
Dictionary<string, MagicSpell> Spells; | ||
|
||
List<SpellInfo> SpellInfos; | ||
private readonly MT19337 rng; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you kill my whitespace, im leaving...
Just joking, but in my opinion this goes too far.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The rules are up for tweaking, I'll try to find the rule that enforces no blank lines here and we can discuss it as a group.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, yeah. Single blank lines should always be acceptable. I'm okay with the linter removing multiple blank lines or blank lines before close braces.
@@ -91,7 +91,10 @@ public void PlaceShops() | |||
|
|||
ShopData.StoreData(); | |||
|
|||
for (int i = 0; i < 8; i++) TileSets[i].StoreData(); | |||
for (int i = 0; i < 8; i++) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd strongly prefer this to be a one-liner. In my opinion the extra lines can make already long code even longer and less readable.
I know a lot of this is personal preference, but at one point you have to place some trust into a programmer to code it in an understandable and readable way.
if (flags.LegendaryWhiteShop ?? false) result[3] = Allocate(ref slots, 4);//White | ||
if (flags.LegendaryWeaponShop ?? false) result[0] = Allocate(ref slots, 3);//Weapon | ||
if (flags.LegendaryItemShop ?? false) result[4] = Allocate(ref slots, 3);//Item | ||
if (flags.LegendaryBlackShop ?? false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thats 5 lines inflated to 24.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, this is due the the default rules and is up for discussion, in general I do think oneliners can be needlessly confusing when being more verbose only takes up more line -- its not like we need to ration lines. though I do agree that in specific cases oneliners can be better, as showcased here.
I'd prefer it not do anything the VisualStudio "Format Document" command doesn't. In the end, you want me to fix my own code as long as i'm around. If you change my code to the point, where i don't recognize it anymore, it'll severly hamper me. Besides all theese formatting changes don't make the problems of the code go away. Spaghetti code will still be spaghetti code. And shitty code will at most become pretty shitty code. But all this does, is ensure that neither you nor i know, what my code does. So as long as i'm around, I'd like to keep my code intact. |
This is the result of running
This should be a one time migration, afterwards all the errors will show up in your editor and it will suggest how to fix it as well as block merging stuff that doesnt meet the style rules we end up agreeing on. Therefore, for everything after this is merged, it will be the exact code as you had it before that code is merged in. |
Unfortunately it appears the dotnet-format does not have prettier-style line breaking, and what we are seeing is the rule to preserve oneline vs when things are on multi-line, it just breaks it all into its own line. There is a github issue opened in mid 2019 which has the most ❤️ reactions and 👍 reactions out of all current issues, so there is demand and we might get that update in the future. On the topic of line breaking as it currently stands though, we might need to disable the current rules as it does not enforce line length but rather forces you, for each collection, to have everything on one line or everything in mutliple lines, not ideal. |
There just seems to be a few lists that aren't on only one line but get to keep their formatting, like in dialog.cs looking at it, maybe it's not applying the rule to lists inside lists. |
that is also entirely possible, Im open to suggestions on how you think we should handle this, try to follow one the the rules or disable them entirely and looking into a third party line length checker, or disable them and let PR reviewers catch that stuff. |
I'm still not entirely sure, what this will accomplish. I can see a lot of really badly formatted code in the project yes. But formatting it "nicely" will not make the code that much more readable and maintainable. I mean, just look at what it did with enemizer. That's now a whooping 4800 lines instead of already unbearable 3750. Can anyone seriously argument, that he now understands what this code does any more than without theese changes? Besides beeing spaghetti code, the current formatting isn't actually bad. It's sure different, but consistent, clear and it conveys the individial constructs. It's just a really long spaghettified code piece that'll take a long time to get into, no matter what formatting. Or take OverWorldMap. The changes it does, are superficial. A few extra lines here and there. But the algorithm of F/E Shuffle still has the same complexity. Also the Formatter doesn't change bad variable and function names. It doesn't change that half our project is a partial class. I will find theese formatting restrictions mostly annoying, especially if they prevent merges and commits. But they will neither make the code more readable nor more maintainable. I'm 100% sure of that. |
This is temporarily on hold as I work on the FFRBot rewrite, but seeing as how most of the team wants standardized styling of some sort, I'll update the rules and redo this in a bit. It will have scripts that can auto-format for those not using VS (or prefer to use a script) and will introduce a circleci check to ensure that the formatting is ok on future PRs This will be a good first step in moving towards a slightly more organized development process including tests for adding to the changelog, adding tooltips, and (maybe, if this has enough traction) eventually running tests on FF1Lib itself |
This formats all the code in the repo and (eventually) will check formatting and checking that it can be built in circleci before allowing stuff to be merged in