Skip to content
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

gigasecond: Update dependency to conform to usage guidelines #436

Merged
merged 1 commit into from
Mar 7, 2018
Merged

gigasecond: Update dependency to conform to usage guidelines #436

merged 1 commit into from
Mar 7, 2018

Conversation

cbzehner
Copy link
Contributor

This updates the dependencies for the gigasecond exercise to conform to the usage guidelines for the chrono cargo package:

Avoid using use chrono::*; as Chrono exports several modules other than types. If you prefer the glob imports, use the following instead:

I realize using chrono::* might have been an intentional decision to avoid having to expose beginners to importing time::Duration as well, but I think it probably makes more sense to mirror a real environment closely when exposing people to these exercises.

I tried to make the minimum number of changes here and ensured that _test/check-exercises.sh was able to validate the gigasecond exercise before submitting.

Copy link
Member

@coriolinus coriolinus left a comment

Choose a reason for hiding this comment

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

Great idea, and thanks for this PR, @cbzehner!

There are a few things I'd like to see improved here before merging. Those are listed below.

@@ -4,4 +4,5 @@ version = "1.1.0"

[dependencies]
chrono = "0.4"
time = "0.1"
Copy link
Member

Choose a reason for hiding this comment

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

The time crate has been depreciated. We shouldn't be adding new dependencies to it. Instead, let's use the chrono reexport of Duration; that way, when that library updates to use std::time::Duration, we upgrade with it for free.

@@ -1,7 +1,10 @@
extern crate chrono;
use chrono::*;
Copy link
Member

Choose a reason for hiding this comment

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

Agree that we should remove the glob import as bad style, but I think we can do better. What about:

use chrono::{DateTime, Duration};

This way we don't have to mess with a second dependency or globs.

Copy link
Member

Choose a reason for hiding this comment

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

This applies both to the lib stub and the example.

@cbzehner
Copy link
Contributor Author

Ah! That's much cleaner. I didn't realize time was deprecated. I'll update this PR with your suggestions.

unimplemented!()
}
extern crate chrono;
use chrono::{DateTime, Duration, Utc};
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Duration is an unused import here, but when I ran cargo check from exercises/gigasecond it didn't output any warnings so I left in in since it's a useful hint. Lmk what you think of this.

Copy link
Member

Choose a reason for hiding this comment

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

I have a mild preference to exclude Duration based only on an instinct that it's good for students to have to look at the docs at least a little bit. By providing the appropriate dependency crate and the stub which we have, we've already reduced the required work from the student to near nothing.

I'm willing to be overridden on this if people feel strongly otherwise, though.

Copy link
Member

Choose a reason for hiding this comment

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

The original angle that I wanted this exercise to take was to be some sort of introduction to crates (specifically for Rust) in addition to time/duration (applies to this exercise no matter what the language). That is what I thought in #79 (comment). Note that at the time there was no stub at all. I may have forgotten about that when reviewing #306 which added the stub. Encouraging a look at the docs seems good. As demonstrated by my having implicitly changed my mind about this a few times over the years, I don't feel strongly about it.

Copy link
Contributor

Choose a reason for hiding this comment

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

I say remove it but add a note to the hints file with a link to the documentation, so students who get lost in the documentation (or don't know how to use it yet) won't get stuck.

@cbzehner
Copy link
Contributor Author

I'll update this to remove Duration and provide a hint linking to the documentation.

@@ -0,0 +1 @@
If you're unsure what operations you can perform on `DateTime<Utc>` take a look at the [chrono crate](https://docs.rs/chrono/0.4.0/chrono/) which is listed as a dependency in the `Cargo.toml` file for this exercise.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wasn't sure if there was a specific format for .meta/hints.md files. I looked at a couple exercism repos on Github but didn't see any. Let me know if this is alright.

Copy link
Member

Choose a reason for hiding this comment

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

There's no specific format necessary there; it's all just human-readable text.

You will, however, need to regenerate the README for this to pass CI:

  • Get the configlet tool. On mac/linux you can just use the bin/fetch-configlet script; on Windows, you have to find it and install it manually.
  • Run bin/configlet generate . --only gigasecond to regenerate the readme
  • Commit the new README.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the guidance. I just updated the README.

@@ -4,6 +4,9 @@ Calculate the moment when someone has lived for 10^9 seconds.

A gigasecond is 10^9 (1,000,000,000) seconds.

If you're unsure what operations you can perform on `DateTime<Utc>` take a look at the [chrono crate](https://docs.rs/chrono/0.4.0/chrono/) which is listed as a dependency in the `Cargo.toml` file for this exercise.
Copy link
Contributor Author

@cbzehner cbzehner Mar 1, 2018

Choose a reason for hiding this comment

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

I'm still a bit concerned this isn't a clear enough hint to walk users to adding Duration as an import from the chrono crate. When I look at the crate documentation on Duration:

Chrono currently uses the time::Duration type from the time crate to represent the magnitude of a time span...

It implies to me as a beginner in Rust that I should be doing the same thing chrono does and adding time to my Cargo.toml so I can also use the time::Duration type.

Duration doesn't appear in reexports and the function most people end up using for this exercise Duration::from isn't apparent anywhere on the page.

Do y'all have any suggestions on how to help this hint provide a bit more structured guidance for people new to the Cargo ecosystem?

Copy link
Member

Choose a reason for hiding this comment

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

I'm still a bit concerned this isn't a clear enough hint to walk users to adding Duration as an import from the chrono crate.

I see what you mean because there's a big dedicated section about durations being from time and being unclear on what relationship this has with https://docs.rs/chrono/0.4.0/chrono/struct.Duration.html.

I don't have any definitive answers, but how about some ideas?

@coriolinus
Copy link
Member

coriolinus commented Mar 1, 2018 via email

@cbzehner
Copy link
Contributor Author

cbzehner commented Mar 1, 2018

Failed the test due to removing Duration from the example.rs file. Updated to resolve test failures.

Copy link
Member

@coriolinus coriolinus left a comment

Choose a reason for hiding this comment

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

Thanks @cbzehner, I think this is in a good state!

I intend to merge this on the 6th, unless further discussion in the interim reveals blocking changes.

@coriolinus coriolinus merged commit 6615150 into exercism:master Mar 7, 2018
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