1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2025-03-19 22:19:29 +02:00

12 Commits

Author SHA1 Message Date
Martin Geisler
c45b291851
Clarify what "undefined behavior" means in arithmetic.md (#2139)
Undefined behavior does not just mean that the behavior can be different
on different platforms. It is much worse than that: the runtime behavior
can be completely nonsensical since the whole program has undefined
behavior.

The compiler will optimizer as if there is no undefined behavior and
will can lead to strange situations as the compiler concludes that
things like `a > a + 1000` can never be reached if `a` is a signed 8-bit
value (since reaching it would trigger undefined behavior).
2024-06-10 10:18:25 -04:00
Jannis Imhof
cb59f30a2e
Fix Fibonacci sequence i.e. fib(0) -> 0. (#1996)
related Issue #1985
2024-04-15 20:07:44 +00:00
Nicole L
7cd25c0262
Move slices and strings to references section (#1898)
This PR moves the slides for slices and strings into the day 1 section
on references. This seems like the more natural place to introduce
slices since slices are a type of reference. It then also made sense to
me to follow that with the introduction of `&str` and `String`, since
students now have the context to understand what a "string slice" is. I
also removed the strings slide from the types and values section since
it didn't make sense to cover the same topic twice in the same day. I
tested this new organization in my class on Wednesday and it didn't
cause day 1 to take too long.
2024-03-14 16:21:15 -04:00
Damiano Ferrari
9059a1aa38
Update fibonacci exercise.rs (#1909) 2024-03-11 14:09:47 +00:00
Nicole L
9023dd9caa
Tweak timings of exercises to better reflect teaching times (#1839)
A few of the early exercises had much larger estimates than were
actually necessary for the super simple early exercises. I've gone
through and reviewed the time estimates for exercises and tweaked the
estimates based on how much time students have actually needed in my
classes so far.
2024-02-22 10:21:39 -05:00
Nicole L
e7076af00f
Move hello world example to second section (#1838)
The current location for the hello world example is awkward since the
two surrounding pages are both talking about Rust from a high level
without talking about syntax at all. I think starting the second section
(types and values) with the hello world example would help the first
section flow more smoothly.
2024-02-21 16:54:11 -05:00
Dustin J. Mitchell
9f67c9b0e7
Adjust morning-session timings downward (#1786)
Based on feedback from @marshallpierce that mornings took about 2.5
hours, this adjusts a bunch of the morning times downward to try to
match that. In other words, this is trying to make the times in the
course more accurate, rather than reducing the amount of time available
for these slides.

This also updates the `course-schedule` tool to be able to show
per-segment timings.
2024-02-06 15:48:56 -05:00
Manichand Kondapaka
faea6894e7
Added an Alternative way for printing struct and declaring a string. (#1773)
Knowing to_string method is good for learner to use at some situation. 
Knowing print complete struct object can be useful while debug.

---------

Co-authored-by: Dustin J. Mitchell <djmitche@google.com>
2024-02-02 20:48:03 +00:00
Dustin J. Mitchell
43474d27d1
Fix typo in Fibonacci exercise (#1634)
Fixes #1633.
2024-01-02 18:15:15 -05:00
Martin Geisler
c9f66fd425
Format all Markdown files with dprint (#1157)
This is the result of running `dprint fmt` after removing `src/` from
the list of excluded directories.

This also reformats the Rust code: we might want to tweak this a bit in
the future since some of the changes removes the hand-formatting. Of
course, this formatting can be seen as a mis-feature, so maybe this is
good overall.

Thanks to mdbook-i18n-helpers 0.2, the POT file is nearly unchanged
after this, meaning that all existing translations remain valid! A few
messages were changed because of stray whitespace characters:

     msgid ""
     "Slices always borrow from another object. In this example, `a` has to remain "
    -"'alive' (in scope) for at least as long as our slice. "
    +"'alive' (in scope) for at least as long as our slice."
     msgstr ""

The formatting is enforced in CI and we will have to see how annoying
this is in practice for the many contributors. If it becomes annoying,
we should look into fixing dprint/check#11 so that `dprint` can annotate
the lines that need fixing directly, then I think we can consider more
strict formatting checks.

I added more customization to `rustfmt.toml`. This is to better emulate
the dense style used in the course:

- `max_width = 85` allows lines to take up the full width available in
our code blocks (when taking margins and the line numbers into account).
- `wrap_comments = true` ensures that we don't show very long comments
in the code examples. I edited some comments to shorten them and avoid
unnecessary line breaks — please trim other unnecessarily long comments
when you see them! Remember we're writing code for slides 😄
- `use_small_heuristics = "Max"` allows for things like struct literals
and if-statements to take up the full line width configured above.

The formatting settings apply to all our Rust code right now — I think
we could improve this with https://github.com/dprint/dprint/issues/711
which lets us add per-directory `dprint` configuration files. However,
the `inherit: true` setting is not yet implemented (as far as I can
tell), so a nested configuration file will have to copy most or all of
the top-level file.
2023-12-31 00:15:07 +01:00
J.Lunz
1ba88ba72e
Fix Fibonacci numbers example (#1529)
The exercise has n <= 2 for the base case, but it is n < 2 in the
solution.
You currently get fib(n) = 10946 for n = 20, but it should be 6765.
2023-11-30 09:46:13 -05:00
Dustin J. Mitchell
6d19292f16
Comprehensive Rust v2 (#1073)
I've taken some work by @fw-immunant and others on the new organization
of the course and condensed it into a form amenable to a text editor and
some computational analysis. You can see the inputs in `course.py` but
the interesting bits are the output: `outline.md` and `slides.md`.

The idea is to break the course into more, smaller segments with
exercises at the ends and breaks in between. So `outline.md` lists the
segments, their duration, and sums those durations up per-day. It shows
we're about an hour too long right now! There are more details of the
segments in `slides.md`, or you can see mostly the same stuff in
`course.py`.

This now contains all of the content from the v1 course, ensuring both
that we've covered everything and that we'll have somewhere to redirect
every page.

Fixes #1082.
Fixes #1465.

---------

Co-authored-by: Nicole LeGare <dlegare.1001@gmail.com>
Co-authored-by: Martin Geisler <mgeisler@google.com>
2023-11-29 16:39:24 +01:00