-
Notifications
You must be signed in to change notification settings - Fork 67
Extract runtime detection constants into separated module #138
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
Conversation
and import them as needed
|
I think adding the platform definitions make sense (though I'm not sure Firstly, it looks to me like the Time::HiRes logic is kind of failing to actually make things simpler than they were before. Secondly, Time::HiRes has been in core since 5.8.0; instead of improving this logic we may be able to remove the eval logic entirely (though I would need to double-check if core needs a pure-perl mode). |
|
Also, the conditional loading of |
8a44bd2 - forgotten quoting
this PR is only about moving things around ... I'll update PR message |
The point of refactoring is not to make the code prettier, it's to make it more maintainable. This part of the proposed change is not doing that at all for me. |
|
I don't understand what you meant. Can you explain? Removing duplicated code is always improving maintainability. |
lib/TAP/Harness/Runtime.pm
Outdated
| use base q (Exporter); | ||
|
|
||
| use constant HAS_TIME_HIRES => !! eval { use Time::HiRes qw (time); 1 }; | ||
| use constant HAS_TIME_HIRES => !! eval q { use Time::HiRes qw (time); 1 }; |
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 changes the eval from a block style evaluation to a string, which is not a good change.
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.
Block eval would not be able to test a use statement, but this can easily be done with a block eval: eval { require Time::HiRes; Time::HiRes->import('time'); 1 }
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.
@karenetheridge original code had string evaluation.
I'm using form q { } for string containing code (hence { as paired delimiter).
commit introducing this change is fixup! of original commit. I'm using such approach to show reaction to code review comment, referring fixup commit(s) dealing with given issue raised in given comment.
(when I was taught this approach I hesitated but at the end, in many PR-review cycles, I found out that review by commit and reacting with fixups saved lot of time especially on reviewer's side)
@Grinnz my aim was only to extract existing runtime detection into dedicated library, but your suggestion is too good to be omitted ... 033f677
I've done just that in #141 |
You're deduplicating 3 lines of code around Time::HiRes. If you need a multitude of those 3 lines (and in this case a custom importer) to do so you're not necessarily improving maintainability.
It's already doing that right now. |
|
I agree with @Leont -- moving these checks to a separate file does not enhance readability, but diminishes it. Defining the constants in the file where they are used makes more sense to me. I also agree that the Time::HiRes usage can probably be improved, but moving it to another file doesn't do that. |
As I perceive this: it's about encapsulation, about expressing intention vs implementing behaviour. Importing well named symbol is same way as declaring such symbol on your own, but fixing symbol is much easier than Some stats from CPAN (using metacpan/metacpan-cpan-extracted) Without |
Runtime detection code was implemented in multiple sources many times using same logic.
Extracting such logic into module and import required behaviour as symbols improves reliability of source code (using symbols instead of constants, write logic only once) as well as (usually) shows some improvements possibilities.