frc-frecon / frecon

An API for building scouting apps for FRC competitions

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

MatchNumber#initialize(String): Redundant Validity Checks

rye opened this issue · comments

As of c075ed0, when running MatchNumber#initialize while supplying a String argument, (e.g. qf6m3r8) we parse the String via regular expression. This is quite alright, and is actually validated immediately by ensuring that match_data, the result of parsing, is present. However, there are a couple of cases which are then subsequently checked, (and, if the system finds error, raised) which are redundant.

An input will not match the regular expression, for example, if the match type does not match /(p|q|qf|sf|f)/i, because that is a required match group. The regular expression will also not match if this is not present.

Thus, the match type presence validation, and the match type validity validation can both be eliminated.

Similar validations can also be eliminated to slim the runtime profile of this; the match number presence validation as well.

Fixed in f3dce56. This issue will be automatically closed upon the merge of that commit.

Just confirming: if the regular expression fails to be matched, it will raise an exception?

In this context, or generally? In Ruby, Exceptions are not raised if RegExps are not matched, but there is an implicit truthiness check that ensures that match_data, the Object containing information about the RegExp match, is present. (Meaning that the input did match it)

In this way, as long as the regular expression is matched, we can infer that the necessary components are present, and we don't need to include other raises.

Sounds good 👍

This has been rectified #initialize no longer has any of these validity checks and .parse, which replaces this behavior, has also seen some facelifting.