Skip to content

Long Method - CraftEventFactory.java#9

Open
Paul-Schliep wants to merge 1 commit intoNicMcPhee:masterfrom
Paul-Schliep:LongMethod-craftbukkit/event/CraftEventFactory.java
Open

Long Method - CraftEventFactory.java#9
Paul-Schliep wants to merge 1 commit intoNicMcPhee:masterfrom
Paul-Schliep:LongMethod-craftbukkit/event/CraftEventFactory.java

Conversation

@Paul-Schliep
Copy link
Copy Markdown

Extracted chunks of code into separate methods in CraftEventFactory.java. The extractions were done by hand to avoid formatting issues with automated "extract method" tools.

This code has no test coverage at all.

This is a change that CraftBukkit should seriously consider accepting because there was little readability in the code before. Now, there are chunks of logic that are appropriately relocated into their own methods. This makes the code much more readable and maintainable.

due to a long elseif block from lines 423-441.  Another fair chunk was
from nested if/else blocks from 396-420.  The following was extracted
into the method checkMagicOrProjectile(), located at line 429:

if (damager.getBukkitEntity() instanceof ThrownPotion) {
                    cause = DamageCause.MAGIC;
                } else if (damager.getBukkitEntity() instanceof
Projectile) {
                    cause = DamageCause.PROJECTILE;
                }

The following was extracted into the method setCause(), located at line
439:

DamageCause cause = null;
        if (source == DamageSource.FIRE) {
            cause = DamageCause.FIRE;
        } else if (source == DamageSource.STARVE) {
            cause = DamageCause.STARVATION;
        } else if (source == DamageSource.WITHER) {
            cause = DamageCause.WITHER;
        } else if (source == DamageSource.STUCK) {
            cause = DamageCause.SUFFOCATION;
        } else if (source == DamageSource.DROWN) {
            cause = DamageCause.DROWNING;
        } else if (source == DamageSource.BURN) {
            cause = DamageCause.FIRE_TICK;
        } else if (source == MELTING) {
            cause = DamageCause.MELTING;
        } else if (source == POISON) {
            cause = DamageCause.POISON;
        } else if (source == DamageSource.MAGIC) {
            cause = DamageCause.MAGIC;
        }

handleEntityDamageEvent() is now 32 lines.
@Boidkan
Copy link
Copy Markdown

Boidkan commented May 10, 2014

Do they follow the CraftBukkit guidelines?
For the most part it does. The push and commit messages seem to fall a bit short though. The push request is lacking the proper format requested by CraftBukkit.

Is the English clear and professional?
Yes, the english is clear.

Is it clear what this pull request does, and why the CraftBukkit team should seriously consider accepting the pull request?
Yes, It seems clear to me why this refactoring is important and why they should accept it.

Are the commit messages clear and helpful? (git allows you to edit commit messages after the fact.)
The commit message is a bit awkward since they inserted chunks of code in to it. This might be me being picky but I honestly feel just saying the method name and maybe the line number should be enough.

Are there commits that should perhaps be merged into a single commit (which git allows you to do after the fact).
No, there is only one commit.

Does the English description accurately and usefully capture the actual changes to the code?
Yes, as long as you have taken refactoring and know that ‘Long Method’ is code word for a smell.

Does the pull request appropriately use the language of refactoring (e.g., names of smells, refactorings, and patterns)?
Yes.

Does the pull request describe what tests (if any) exist to support the change? (This would be important in helpful assess the associated risks.)
Yes, they state that there is no test coverage for the changes.

Does the pull request represent a single, clearly definable change?
Yes, they did one smell but made a couple of changes/extractions.

Do the changes in the pull request represent a meaningful change that would justify the effort of the CraftBukkit team to process and incorporate the pull request?
The refactoring itself seems good. However the pull request seems to be lacking. Even though the refactoring is good enough to be accepted in my opinion, I can see someone just skipping this pull request do to the lack of proper formatting and hy this is important.

To what degree do the changes in the pull request reflect an "interesting" refactoring, i.e., reflect an understanding of the concepts and techniques we've been working with this semester?
This refactoring isn't super interesting since it was a common refactoring all semester. However, It is still a good and important refactoring.

To what degree do you believe that the changes are correct? Why/why not?
The changes look correct to me. Well done.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

You don't really need cause as an argument here since you never use the value that's passed in. It's really just a local variable inside checkMagicOrProjectile that happens to have the same name as the variable out here.

@NicMcPhee
Copy link
Copy Markdown
Owner

This doesn't really do a lot. From your description I'd expected more extraction and improvement than the one little method. It's a nice little extraction, to be sure, just not a major deal. (And it has an unnecessary argument as I described in the note on the code.)

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