Skip to content

hello-world: simplify to unconditional "Hello, World!" #255

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

Merged
merged 1 commit into from
Feb 20, 2017
Merged

hello-world: simplify to unconditional "Hello, World!" #255

merged 1 commit into from
Feb 20, 2017

Conversation

petertseng
Copy link
Member

The introductory exercise should require as little Rust knowledge as
necessary. We'd like to introduce cargo test here since it will be
used for all exercises, but introducing Option is too much.

exercism/problem-specifications#520


I wouldn't recommend merging this until the corresponding change is made in x-common.
Let's get it ready to go before then.

@ijanos
Copy link
Contributor

ijanos commented Feb 1, 2017

I'm in favour of simplification but looking at this got me thinking. Strings in rust are not simple, while the classic tutorial work with a simple println!("Hello, world!"); here we have to call .to_string() or .into() or String::from() to satisfy the test.

If the purpose of this exercise is just to test that everything works then I'm starting to lean in the direction to use a primitive type here, a bool could work with something like this:

pub fn everything_works() -> bool {
    true
}

At this point however we have no connection to the common description. So another approach could be accepting a static string slice in the test. No conversion to String required but the type signature could be confusing or hard to guess if we don't provide a stub.

pub fn hello() -> &'static str {
    "Hello, World!"
}

Thoughts?

@petertseng
Copy link
Member Author

Hmm, good point. I would say there are various measures we can take to lighten the load. We might combine some of these measures:

  • static str, so we don't have to do to_string
  • provide a stub
  • provide a failing implementation that says "Goodbye, world" - then the student only has to change the Goodbye to Hello, should give the idea.

@petertseng
Copy link
Member Author

Let's take all three. Note that using &'static str did not require any change to the test.

Copy link
Contributor

@ijanos ijanos left a comment

Choose a reason for hiding this comment

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

I'm OK with this version. Maybe add a comment to the stub with this info: "the type of the return value looks funny because it has a static lifetime, this is a rust feature, dont mind it now"

@petertseng
Copy link
Member Author

OK, take a look at that comment. Feel free to suggest changes to the wording.

@ijanos
Copy link
Contributor

ijanos commented Feb 2, 2017

Looks good to me, but keep in mind that I am not a native English speaker :)

The introductory exercise should require as little Rust knowledge as
necessary. We'd like to introduce `cargo test` here since it will be
used for all exercises, but introducing Option is too much.

We add a stub in case it is not clear how to return a string. That way,
the student only has to change the string provided.

exercism/problem-specifications#520
@petertseng
Copy link
Member Author

Also removed Some/None from the config.json for hello-world.

@petertseng petertseng merged commit 3275c18 into exercism:master Feb 20, 2017
@petertseng petertseng deleted the hello-world branch February 20, 2017 06:31
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.

2 participants