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

Change var to const in some exercises #329

Merged
merged 3 commits into from Jun 22, 2023

Conversation

lorrding
Copy link
Contributor

As explained in #324 , I changed some variable declaration to constants. I also tried to update the comments when it made sense.
Some variable could be changed to constant like num1 here in 039_pointers.zig but it would require to also change num1_pointer to be *const u8.

pub fn main() void {
var num1: u8 = 5;
var num1_pointer: *u8 = &num1;
var num2: u8 = undefined;
// Please make num2 equal 5 using num1_pointer!
// (See the "cheatsheet" above for ideas.)
num2 = ???;
std.debug.print("num1: {}, num2: {}\n", .{ num1, num2 });
}

Since this exercise is trying to explain how pointers works I assumed it would not be a good idea to make the change. The same applies to exercise 066_comptime.zig and after, where we already make use of const and comptime.

I also understand that changing variables to constants may give away the answer to some exercise. Feel free to not merge some changes to some exercises if you think it's not worth it.

Everything was built and run with zig 0.11.0-dev.3747

NB: I also updated outdated comments referencing the change in builtin casts as I forgot to check those in my previous PR. (see: #327)

@lorrding lorrding changed the title Refactor var to const in some exercises Change var to const in some exercises Jun 22, 2023
@chrboesch chrboesch merged commit 371beb1 into ratfactor:main Jun 22, 2023
11 checks passed
@chrboesch
Copy link
Collaborator

Thanks!

@lorrding lorrding deleted the refactor-var-to-const branch June 29, 2023 14:39
vamega pushed a commit to vamega/ziglings that referenced this pull request Jul 25, 2023
Change `var` to `const` in some exercises
fleimgruber pushed a commit to fleimgruber/ziglings that referenced this pull request Oct 26, 2023
Change `var` to `const` in some exercises
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.

None yet

2 participants