←back to thread

327 points AareyBaba | 5 comments | | HN request time: 0.827s | source
Show context
time4tea ◴[] No.46184345[source]
a = a; // misra

Actual code i have seen with my own eyes. (Not in F-35 code)

Its a way to avoid removing an unused parameter from a method. Unused parameters are disallowed, but this is fine?

I am sceptical that these coding standards make for good code!

replies(11): >>46184442 #>>46184460 #>>46184571 #>>46185232 #>>46185373 #>>46186276 #>>46186377 #>>46186457 #>>46186510 #>>46186705 #>>46189488 #
ivanjermakov ◴[] No.46184571[source]
Zig makes it explicit with

    _ = a;
And you would encounter it quite often because unused variable is a compilation error: https://github.com/ziglang/zig/issues/335
replies(2): >>46185933 #>>46185991 #
bluecalm ◴[] No.46185991[source]
Doesn't it make it more likely unused variables stay in the codebase? You want to experiment, the code doesn't compile, you add this (probably by automatic tool), the code now compiles. You're happy with your experiment. As the compiler doesn't complain you commit and junk stays in the code.

Isn't it just bad design that makes both experimenting harder and for unused variables to stay in the code in the final version?

replies(1): >>46186502 #
1. ivanjermakov ◴[] No.46186502[source]
It is indeed quite controversial aspect of Zig's design. I would rather prefer it be a warning. Argument "warnings are always ignored" just doesn't hold because anything can be ignored if there is a way to suppress it.
replies(1): >>46186887 #
2. dnautics ◴[] No.46186887[source]
there was a recent interview where andrew suggested if i understood correctly: the future path of zig is to make all compilations (successful or not) produce an executable. if theres something egregious like a syntax or type error, the produced artifact just prints the error and returns nonzero. for a "unused parameter", the compiler produces the artifact you expect, but returns nonzero (so it gets caught by CI for example.
replies(1): >>46186929 #
3. sumalamana ◴[] No.46186929[source]
Why would the compiler do that, instead of just printing the error at compile-time and exiting with a non-zero value? What is the benefit?
replies(2): >>46188398 #>>46193620 #
4. j16sdiz ◴[] No.46188398{3}[source]
It is more a debug/development feature. You can try out some idea without fixing the whole code base.
5. dnautics ◴[] No.46193620{3}[source]
if you have a syntax error in file A, and file B is just peachy keen, you can keep compiling file B instead of stopping the world. Then the next time you compile, you have already cached the result of file B compilation.