-
-
Notifications
You must be signed in to change notification settings - Fork 399
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
date-parser improvements #941
Comments
So you are correct, there are more ways to tackle this problem with more use of the standard lib and less use of regex, but the concept exercise is contrived to teach regex patterns. So while I agree that if doing this for myself I might use a different route, how can we focus on making this a better regex learning exercise? Whether we adapt and improve this exercise or deprecate and create a new one is fine, but there does need to be a progression of simple patterns to complex patterns and I think constraining it to simple matching makes it easier than opening up the flood gates to |
I think one way would be to let them use Regex.match? directly instead of passing the regex returned by the match_* functions into it. E.g, instead of writing
we could have them write:
More generally, I think what I'm really feeling is that if I were to teach people regex, I'd want them to use std lib and write just a few, simple regexes, but here I'm not using std lib and I end up making a lot of different regexes with interpolation. |
I also found this exercise weird too as it's possible to get all the tests to pass even if the first function @spec day() :: String.t()
def day do
"\\d{1,2}"
end |
Adding @ErikSchierboom's feedback:
|
I have started working on replacing |
I did the log-parser exercise and liked it a lot better! Great work. |
As mentioned on slack:
Doing the date-parser exercise has been weird for me. Whenever I do regex, I try to use the std lib as much as possible and keep my regex as simple as possible. I find this makes much more maintainable code. But this exercise was exclusively writing regexes to pass certain inputs, and almost all as Strings being
Regex.compile!
ed instead of actual regexes.I think the general way I would have approached this would have been to take the input formats:
"01/01/1970"
"January 1, 1970"
"Thursday, January 1, 1970"
and try to parse a
Date
from each. So for example for 1, I would probably avoid Regex altogether and do something like:If that came back error, I would try to parse 2 and 3 with regex:
Then I can take the last 3 elements and feed them into Date.new after integerizing and reordering them.
But... I don't know if the above would accomplish the learning objectives of the exercise.
As a smaller fix, I noticed my test output wasn't particularly helpful in my workflow.
My workflow was basically implement a function, run the tests, then see the next failing test to inform me on how to proceed. But since the functions are being piped into
Regex.compile!
, I would just get function clause errors. Very late I caught on that I could get more helpful errors if I just put""
as the body of the next function.I also took a look at the exemplar code and liked the grouping it achieved, but unfortunately that grouping isn't natural the way the stub lib file comes.
The text was updated successfully, but these errors were encountered: