←back to thread

327 points AareyBaba | 2 comments | | HN request time: 0.479s | 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 #
ErroneousBosh ◴[] No.46185933[source]
Golang is exactly the same.

It's extremely annoying until it's suddenly very useful and has prevented you doing something unintended.

replies(2): >>46186034 #>>46186865 #
bluecalm ◴[] No.46186034[source]
I fail to see how a warning doesn't achieve the same thing while allowing you to iterate faster. Unless you're working with barbarians who commit code that complies with warnings to your repo and there is 0 discipline to stop them.
replies(3): >>46188913 #>>46189743 #>>46191081 #
ErroneousBosh ◴[] No.46189743[source]
Go is a very opinionated language. If you don't like K&R indentation, tough - anything else is a syntax error.

It's kind of like the olden days.

replies(1): >>46190022 #
1. bluecalm ◴[] No.46190022[source]
Yeah but this case just seem to be strictly worse. It makes experimenting worse and it makes it more likely (not less) that unused variables end up in the final version. I get being opinionated about formatting, style etc. to cut endless debates but this choice just seem strictly worse for two things it influences (experimenting and quality of the final code).
replies(1): >>46190131 #
2. ErroneousBosh ◴[] No.46190131[source]
If you want to leave a variable unused, you can just assign it to _ (underscore) though. IIRC gofmt (which your editor should run when you save) will warn you about it but your code will compile.

It's a slightly different mindset, for sure, but having gofmt bitch about stuff before you commit it rather than have the compiler bitch about it helps you "clean as you go" rather than writing some hideous ball of C++ and then a day of cleaning the stables once it actually runs. Or at least it does for me...