Move stdlib imports to struct scope in hello_world examples - #362
Merged
Conversation
📝 WalkthroughWalkthroughThe hello-world examples now receive ChangesHello-world I/O flow
Estimated code review effort: 3 (Moderate) | ~20 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@course/code/16/hello_world.zig`:
- Around line 3-6: Add independent Zig tests for the One, Two, and Three regions
in both course/code/16/hello_world.zig (lines 3-6) and
course/code/release/hello_world.zig (lines 3-6), producing one test per region
per file. Ensure the tests are discoverable by zig test and exercise each
corresponding entry point independently.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: a1687247-a38e-48e9-974a-1874f4c3cfe7
📒 Files selected for processing (3)
course/code/16/hello_world.zigcourse/code/release/hello_world.zigcourse/hello-world.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Refactor the hello_world examples to move stdlib imports from file-level to struct-level scope. Each struct now independently imports std, eliminating ambiguous reference errors and making each code snippet self-contained for copy-pasting into user projects.
Changes
Code changes (16/hello_world.zig and release/hello_world.zig):
const std = @import("std")into each struct (One, Two, Three)@import("std").process.Inittype referenceTwoandThreefunction signatures to acceptinit: std.process.Initdirectly, extractingioinside each functionTwoexample to use unbuffered output (&.{}) for clarityflush()calls from the unbuffered exampleDocumentation updates (hello-world.md):
init: std.process.Initparameter and its role&.{}means unbuffered (direct) outputflush()when using buffered I/OWhy
Each code snippet in the course is intended to be copyable directly into user projects. Moving imports to struct scope allows independent code samples without file-level import conflicts, and makes the relationship between initialization and I/O operations clearer for learners.
Summary by CodeRabbit