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

Rework generic fn examples to show monomorphized versions #2671

Merged
merged 3 commits into from
Mar 3, 2025

Conversation

randomPoison
Copy link
Collaborator

@randomPoison randomPoison commented Feb 28, 2025

Something I always do when covering generic fns is I like to show the monomorphized versions of pick to make it clear to students what generics are doing behind the scenes. In my most recent class I tried going the other way around, showing the monomorphized versions first to more clearly motivate what generics are used for, and I liked the way it went. I think motivating generics by first showing code duplication and then showing how generics allow us to de-duplicate makes for a good teaching flow, and I think it also helps make things clearer to students coming from more dynamic languages that don't have an equivalent to generics.

I also changed the pick fns to take a bool as the first argument because I think that makes things slightly clearer/cleaner, but I'm not married to that change either.

Copy link
Collaborator

@djmitche djmitche left a comment

Choose a reason for hiding this comment

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

I like the change, but it probably deserves a speaker note regarding how to use the slide.

@mgeisler
Copy link
Collaborator

The idea of showing the result of monomorphization is great, but I'm afraid the slide become too tall now?

I would suggest putting this into the speaker notes instead: keep the pick<T> function in the slide and let the speaker notes explain that it expands to pick_i32 and pick_char depending on how it's called.

@randomPoison
Copy link
Collaborator Author

Both of your comments make sense to me, so I've moved the monomorphized versions into the speaker notes and added a note explaining that they can be used to both motivate the generic pick and demonstrate monomorphization. Let me know how it looks!

@djmitche djmitche merged commit 7f45460 into main Mar 3, 2025
37 checks passed
@djmitche djmitche deleted the legare/generic-fn-example branch March 3, 2025 15:03
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