ratfactor/ziglings

Exercise 50 doesn't require usage of `null` or `Err`

nihohit opened this issue · 7 comments

I expected the exercise to require using all 4 types, but line 81 can take either undefined or null, and line 71 can take either Err or undefined.

Which exercise do you mean?

050_no_value.zig. Sorry, amended issue name. 🤦

I can't really understand what your point is here. In line 68 we have undefined, in line 71 error, in line 80 void and in line 81 null. So all four are used in this exercise. What are you missing?

In short - the exercise aims to teach the user about 4 different no-value values, but in practice doesn't require it.

You're right that what you propose is a valid solution to the problem. The issue I see is that it's only one of the possible valid solutions - you could also use undefined in lines 68, 71, and 80. If you're new to the language, and the goal is to teach the differences between the different no-value values, then the exercise does the opposite of that - it shows that these values are interchangeable, because the set values in lines 71 & 80 are always overwritten, so undefined fits all 3 scenarios.

Now, as a neophyte to the language, I assume that the different values aren't interchangeable. I believe the exercise should demonstrate the differences between the similar values.

I believe the exercise should demonstrate the differences between the similar values.

I see, then please make a suitable suggestion to improve this exercise.

Update: But in principle, the goal of the exercise is achieved, you have dealt with the types. Ziglings does not want to and cannot achieve more.

As I mentioned, I'm not an expert in the language. Would something like

    var first_line2: Err!*const [21]u8 = ???;
    first_line2 = if (first_line2 == Err::Cthulhu} "which can eternal lie" else undefined;

be acceptable? It's a bit contrived, but at least it forces the user to use the correct type.

That's not really helpful, because it's far too complicated. And what is to be achieved is also not clear to me. The goal of Ziglings is not to be perfect, but to support people in learning the Zig language with beautiful and fun exercises. It is normal that one or the other exercise is not 100% convincing for some people. But we try as much as possible to present a balanced mixture to everyone, which is why every change after such a long and - in my opinion - successful time has to be considered carefully. And as I said before, even if you are not fully satisfied with this exercise now, at least it has not missed its goal and has been able to convey something to you, and also to many others before.