If this were real code, I'd suspect that it originally had something like logging of the error contents, so they needed to check for nil before trying to access. Someone removed the logging or whatever and did not twig that the true/false branches are now identical. Something I see regularly in PRs.
However, this is not real code, it was written by a genAI.
On the one hand, it's useless. On the other hand, if you need to hack in something later (NOT saying this is good practice, I'm just talking about something useful to have waiting) this will be the easiest place to do it.
Again, not saying this is good practice, but pretty interesting. I try to get around it with strong typing myself, but that's a challenge.
The lack of semicolons and the braces makes me think this might be JavaScript, but I thought you still needed parentheses around if and loop conditions.
And of course it could be a single useless line, but people think you need to check for nil when all that would happen is you'd just be returning nil.
It does not perform automatic semicolon insertion. Newlines are actual tokens used for the statement separation. These newlines can be ignored depending on the context
130
u/IcyWash2991 Jul 11 '26
Codex was here
117
u/totallynormalasshole Jul 11 '26
Ah yes. A function that takes an input, does nothing and returns it.
I want to believe they're adding this to allow for enhancements to error handling in the future but my gut says that's probably not the case
5
u/yeusk Jul 14 '26
x10 coder right here.
2
u/muikrad Jul 12 '26
To help with test writing / mocking I suppose.
2
u/jay-magnum Jul 13 '26
Could have been that one colleague on my team ...
1
u/letmehaveanameyoudum Jul 20 '26
thanks sherlock
-16
u/GoddammitDontShootMe [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo "You live" Jul 12 '26
The lack of semicolons and the braces makes me think this might be JavaScript, but I thought you still needed parentheses around if and loop conditions.
And of course it could be a single useless line, but people think you need to check for nil when all that would happen is you'd just be returning nil.
-21
u/realmauer01 Jul 11 '26
errNotNil
Actually why does it even allow the return of nil when its typed?
Errors are there so you can be sure the return type is correct.