Replace all enum to enum class
Needs RevisionPublic

Authored by rominf on Feb 25 2018, 12:57 PM.

Details

Reviewers
markg
Group Reviewers
Dolphin
Summary

Replace all enum to enum class. Rename some enum members where appropriate (for example: (RoleType)NameRole -> RoleType::Name).

Test Plan
  1. Run all tests.
  2. Check changes with your eyes.

Diff Detail

Repository
R318 Dolphin
Branch
enum-class
Lint
No Linters Available
Unit
No Unit Test Coverage
rominf created this revision.Feb 25 2018, 12:57 PM
Restricted Application added a subscriber: Dolphin. · View Herald TranscriptFeb 25 2018, 12:57 PM
rominf requested review of this revision.Feb 25 2018, 12:57 PM
rominf added a project: Dolphin.
rominf edited the summary of this revision. (Show Details)Feb 25 2018, 1:15 PM
rominf edited the summary of this revision. (Show Details)Feb 25 2018, 1:19 PM

Thanks for the patch.

I agree we should use enum class for new code, I'm not sure it's worth porting to old enums though.
The problem is that this diff is huge and it will make git blame harder to use, for little gain.
@markg @rkflx toughts?

That said, if we really want to do it, please get rid of those static_casts where possible, they will only reduce the readability of the code.

src/dolphincontextmenu.cpp
69

If we change the type of m_context, we don't need the static_cast.

That said, if we really want to do it, please get rid of those static_casts where possible, they will only reduce the readability of the code.

Agreed.

markg added a comment.Feb 25 2018, 2:43 PM

Thanks for the patch.

I agree we should use enum class for new code, I'm not sure it's worth porting to old enums though.
The problem is that this diff is huge and it will make git blame harder to use, for little gain.
@markg @rkflx toughts?

That said, if we really want to do it, please get rid of those static_casts where possible, they will only reduce the readability of the code.

Tricky one!
On one side i'm all in for code improvements and modernization.
On the other hand, only if it makes sense.

As it's done now (with all the added static_casts's) it's imho not worth it as the new code looks less clean then the old one, but that can be fixed.

I personally would not bother making a patch for it, but now that the patch is there. Why not :)
New code should certainly use enum class!

Lastly, please do get the permission of the Dolphin maintainer as this is quite a refactoring.

rkflx added a comment.Feb 25 2018, 5:23 PM

Late to the party, here are my thoughts:

There's some value in the explicitness enum class sometimes provides, but counteracting it immediately with static_cast is not really useful.

I'd vote to apply this to new code only for now. Speaking from recent experience, it's easy to get things wrong regarding an enum refactoring ;) Better not to perform a mass change, unless there is a reviewer checking very thoroughly (I won't).

Late to the party, here are my thoughts:

There's some value in the explicitness enum class sometimes provides, but counteracting it immediately with static_cast is not really useful.

I'd vote to apply this to new code only for now. Speaking from recent experience, it's easy to get things wrong regarding an enum refactoring ;) Better not to perform a mass change, unless there is a reviewer checking very thoroughly (I won't).

Another variant is to apply only obvious changes and skip all changes that require static_casts. It's not hard to do (I need just filter my changes), easy to check for a reviewer (verify that (X)SomethingPostfix -> X::Something) and better than nothing.

Another variant is to apply only obvious changes and skip all changes that require static_casts. It's not hard to do (I need just filter my changes), easy to check for a reviewer (verify that (X)SomethingPostfix -> X::Something) and better than nothing.

+1, sounds sane.

rominf added a comment.Mar 5 2018, 8:10 AM

What about this diff? Will this be accepted if I revert all enums that require static_cast?

markg added a comment.Mar 5 2018, 8:58 AM

What about this diff? Will this be accepted if I revert all enums that require static_cast?

Likely, yes. No promises though.

rominf updated this revision to Diff 28859.Mar 6 2018, 6:52 PM

Remove almost all static_cast (only 5 is left!)

rominf updated this revision to Diff 28884.Mar 7 2018, 7:39 AM

Fix compilation error

Please review.

markg requested changes to this revision.Mar 11 2018, 5:33 PM

Large review!
I was going to give a ship it till i compile tested it. It failed!
You can find the output here: https://p.sc2.nl/HJDBOJmtM

This revision now requires changes to proceed.Mar 11 2018, 5:33 PM

There is no reason to rush this in now, I'd suggest to wait the feature freeze on March 22 [1] so that we have enough time to be sure we don't break anything.

[1]: https://community.kde.org/Schedules/Applications/18.04_Release_Schedule

Large review!
I was going to give a ship it till i compile tested it. It failed!
You can find the output here: https://p.sc2.nl/HJDBOJmtM

It's strange. It builds even without additional warnings: https://gist.github.com/rominf/d3d55d85c23f83366a1ae7b5af525613

There is no reason to rush this in now, I'd suggest to wait the feature freeze on March 22 [1] so that we have enough time to be sure we don't break anything.

[1]: https://community.kde.org/Schedules/Applications/18.04_Release_Schedule

OK

meven added a subscriber: meven.Feb 17 2020, 4:59 PM

ping @rominf
It would probably need some rebasing after so long....

Restricted Application added a subscriber: kfm-devel. · View Herald TranscriptFeb 17 2020, 4:59 PM
This comment was removed by rominf.

ping @rominf
It would probably need some rebasing after so long....

Hi. Unfortunately, I don't have time and desire to do that now.