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

Cleanup items.cpp #1967

Merged
merged 50 commits into from
May 16, 2021
Merged

Cleanup items.cpp #1967

merged 50 commits into from
May 16, 2021

Conversation

vlolteanu
Copy link
Contributor

Marking it as draft for the moment.

The changes were all mechanical, and hence, error-prone when all done at once. An extra pair of eyes would be really needed here.

@vlolteanu vlolteanu marked this pull request as draft May 14, 2021 00:28
@vlolteanu vlolteanu changed the title Refactor items Refactor items.cpp May 14, 2021
@vlolteanu vlolteanu changed the title Refactor items.cpp Cleanup items.cpp May 14, 2021
@vlolteanu vlolteanu force-pushed the refactor-items branch 2 times, most recently from 7e8bd56 to bc9d3b8 Compare May 14, 2021 02:08
@vlolteanu
Copy link
Contributor Author

vlolteanu commented May 14, 2021

I'll tick stuff that I've proofed/tested. Feel free to join.

@vlolteanu vlolteanu marked this pull request as ready for review May 14, 2021 02:40
@vlolteanu
Copy link
Contributor Author

The vendors' inventories are now sorted using std::sort. The items are sorted by item type, so this change of algorithm may produce a slightly different item order from vanilla.

Source/items.h Outdated Show resolved Hide resolved
Source/items.cpp Outdated Show resolved Hide resolved
Source/items.cpp Outdated Show resolved Hide resolved
Source/items.cpp Outdated Show resolved Hide resolved
Source/items.cpp Outdated Show resolved Hide resolved
Copy link
Member

@AJenbo AJenbo left a comment

Choose a reason for hiding this comment

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

Looks good, but there where a couple of notes mostly related to code style.

@AJenbo
Copy link
Member

AJenbo commented May 15, 2021

Looks like the test is failing, several items are morphing. Do you need any help with getting feedback from the test?

@vlolteanu
Copy link
Contributor Author

Please do. Or better yet, tell me how to run the tests myself. (I set RUN_TESTS to ON in CMakeLists.txt, but that apparently didn't do anything.)

@AJenbo
Copy link
Member

AJenbo commented May 16, 2021

If you are on linux or WSL:

apt-get install -y cmake curl g++ git lcov libgtest-dev libfmt-dev libsdl2-dev libsdl2-ttf-dev libsodium-dev
cmake .. -DRUN_TESTS=ON
make -j 4
./devilutionx

I usually create a build-test folder and run it from there.

I don't know what would be needed to do it on VC or Mac

@AJenbo
Copy link
Member

AJenbo commented May 16, 2021

Looks like you found the issue 👍 Did you also manage to get the tests running? What system are you developing on?

@vlolteanu
Copy link
Contributor Author

Yes, it was a mechanical error in RndVendorItem. "-DRUN_TESTS=ON" did the trick.

I'm working on Linux.

@julealgon
Copy link
Contributor

50 commits on a single PR seems excessive to me, and the fact that each commit is just "Cleanup X" is really, really bad imho. We should be specific on what we are doing, like "Use Point struct for X/Y/Z" instead of "Cleanup".

@vlolteanu
Copy link
Contributor Author

I guess I'll open 50 PRs next time :)

I frankly expect this to get squashed.

I agree that the commits that did make a function use Point could have been worded differently, but it's a current policy to use Point wherever possible, so I'd count that as cleanup. Aside from that, all other Cleanup Foo commits were literally nothing more than cleanups of Foo, no matter how you slice it.

@AJenbo
Copy link
Member

AJenbo commented May 16, 2021

I frankly expect this to get squashed.

Oh, guess I don't have to bother with any rebasing then 👍

@AJenbo AJenbo merged commit 0c7c71d into diasurgical:master May 16, 2021
@vlolteanu vlolteanu deleted the refactor-items branch May 16, 2021 22:15
@AJenbo
Copy link
Member

AJenbo commented May 16, 2021

@vlolteanu you got an achievement:
image

The code now lives up to 3/10 out of ISO 25010 specifications for maintainable code.

@vlolteanu
Copy link
Contributor Author

Haha that was unexpected.

If I understand that correctly, this PR pushed devilutionX over the edge into 3/10, right?

@AJenbo
Copy link
Member

AJenbo commented May 16, 2021

Correct, you removed the last 21 lines of duplication for us to hit 95% unique code. When we forked from Devilution it was at 89%

@AJenbo
Copy link
Member

AJenbo commented May 17, 2021

The next mile stone is a lot further in to the future. Most likely it would be reducing the amount of code in functions with many parameters. This clean up did make a small jump on that graph as well, with some code in the 5-6 parameters tier dropping to 3-4 instead, probably due to Point being used instead of an x, y pair. But we will need to do 120x better to tick that box fully.

Splitting up long functions (like what I did for TalkToTowner() and OperateShrine()) is probably what is going to make the biggest advances over all.

I don't know ho much access you guys have to the list, but if you like I can generate issues for some of the functions that are listed as prime candidates for refactoring.

Here's an examples of an issue generated for the 4 basic categories.
Long functions: #1995
Complex functions: #1996
Duplicate code: #1997
Large interfaces: #1998

There are also more advanced lists relating to code coupling. Dealing with that is usually much more complicated and it also tends to get worse as we work on the basic issues and code sharing inevitably leads to more coupling. In my experience dealing with this comes much later when the general issues are mostly death with and you can better start to reason about application structure.

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.

5 participants