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

✨ (concept) Add new concept exercise cars-assemble #1675

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

devkabiir
Copy link

This is inspired by the same in csharp track. Provides a gentle introduction to variable assignment, if-statements and numbers.

@devkabiir devkabiir force-pushed the concept-if-statements-integers branch 4 times, most recently from a0d86e5 to d22c6f9 Compare April 10, 2023 13:56
@devkabiir devkabiir marked this pull request as ready for review April 10, 2023 14:02
}

fn round_to_1_decimal(input: f64) -> f64 {
return (input * 10.0).round() / 10.0;

Choose a reason for hiding this comment

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

Suggested change
return (input * 10.0).round() / 10.0;
(input * 10.0).round() / 10.0

Comment on lines 22 to 38
if speed == 10 {
return 0.77;
}

if speed == 9 {
return 0.8;
}

if speed >= 5 {
return 0.9;
}

if speed <= 0 {
return 0.0;
}

return 1.0;

Choose a reason for hiding this comment

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

We can avoid explicit return entirely.

Suggested change
if speed == 10 {
return 0.77;
}
if speed == 9 {
return 0.8;
}
if speed >= 5 {
return 0.9;
}
if speed <= 0 {
return 0.0;
}
return 1.0;
if speed == 10 {
0.77
} else if speed == 9 {
0.8
} else if speed >= 5 {
0.9
} else if speed <= 0 {
0.0
} else {
1.0
}

unimplemented!("Implement working_items_per_minute")
}

pub fn success_rate(_speed: u8) -> f32 {
Copy link
Contributor

Choose a reason for hiding this comment

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

This function signature does not match the exemplar.rs

@@ -0,0 +1,11 @@
pub fn production_rate_per_hour(_speed: u8) -> f32 {
Copy link
Contributor

Choose a reason for hiding this comment

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

This function signature does not match the exemplar.rs

unimplemented!("Implement production_rate_per_hour")
}

pub fn working_items_per_minute(_speed: u8) -> u8 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
pub fn working_items_per_minute(_speed: u8) -> u8 {
pub fn working_items_per_minute(_speed: i32) -> f64 {

Returning a f64 will allow us to avoid talking about type casting with as entirely in this exercise, which would be consistent with the book.

}

fn production_rate_per_hour_for_speed(speed: i32) -> f64 {
(PRODUCTION_RATE_PER_HOUR_FOR_DEFAULT_SPEED * speed) as f64
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
(PRODUCTION_RATE_PER_HOUR_FOR_DEFAULT_SPEED * speed) as f64
(PRODUCTION_RATE_PER_HOUR_FOR_DEFAULT_SPEED * speed).into()

@devkabiir devkabiir force-pushed the concept-if-statements-integers branch 2 times, most recently from 778289e to ed689eb Compare May 1, 2023 20:09
@MatthijsBlom
Copy link

@devkabiir I don't think there is a need for force-pushes. The commits will probably be squashed at the end anyway. On the other hand force-pushes make it slightly harder for observers to follow developments in the PR.

This is inspired by the same in csharp track. Provides a gentle introduction to variable assignment, if-statements and numbers.
@devkabiir devkabiir force-pushed the concept-if-statements-integers branch from ed689eb to 0b5dbdb Compare May 1, 2023 20:37
Copy link
Contributor

@senekor senekor left a comment

Choose a reason for hiding this comment

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

On a general note, this exercise seems a bit overloaded with concepts to me. I'm counting five in total:

  • number types
  • constants
  • variable declaration
  • type conversion
  • arithmetic operators
  • if statements

I wonder if one or more other exercises should come before this, introducing a subset of these concepts to the students can make smaller steps.

Comment on lines +44 to +46
"if-statements",
"assignment",
"numbers"
Copy link
Contributor

Choose a reason for hiding this comment

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

As far as I can tell, these concepts do not exist? I'm assuming these need to reference some actual concept, I didn't find precise documentation on the purpose of this key here.

Comment on lines +17 to +19
pub fn working_items_per_minute(speed: i32) -> i32 {
(production_rate_per_hour(speed) / 60.0) as i32
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
pub fn working_items_per_minute(speed: i32) -> i32 {
(production_rate_per_hour(speed) / 60.0) as i32
}
pub fn working_items_per_minute(speed: i32) -> f64 {
production_rate_per_hour(speed) / 60.0
}

As discussed here.


```rust
let my_int = 5;
let my_float = my_int; // => panic
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
let my_float = my_int; // => panic
let my_float = my_int; // => compiler error

let my_float = my_int; // => panic

let my_float2 = 5.0;
let my_int2 = my_float2; // => panic
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
let my_int2 = my_float2; // => panic
let my_int2 = my_float2; // => compiler error

- Integers: numbers with no digits behind the decimal separator (whole numbers). Examples are `-6`, `0`, `1`, `25`, `976` and `500000`.
- Floating-point numbers: numbers with zero or more digits behind the decimal separator. Examples are `-2.4`, `0.1`, `3.14`, `16.984025` and `1024.0`.

The two default numeric types in Rust are `i32` and `f64`. An `i32` is a 32-bit integer and a `f64` is a 64-bit floating-point number.
Copy link
Contributor

Choose a reason for hiding this comment

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

They aren't used in the exercise, but it might be appropriate to include a note about the other number types? Something like:

There are other number types with different precision, like f32 and i16. Unsigned (always positive) integers start with a u instead of i. For example, a byte is expressed as u8. Another number type you'll come across is usize, its precision depends on your computer (usually 64 bits) and is used for lengths and indexes.

@senekor
Copy link
Contributor

senekor commented Dec 14, 2023

The author of this PR has stopped responding in the discussions planning the work on the syllabus. But there's been a lot of work put into reviews already, so I'm keeping it open in case it can be salvaged in a future attempt to create a good syllabus.

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.

3 participants