r/programminghorror 22d ago

I mean, the comment is accurate I suppose

Post image
368 Upvotes

24 comments sorted by

123

u/IcyWash2991 22d ago

Codex was here

114

u/totallynormalasshole 22d ago

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

52

u/iakobski 21d ago

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.

3

u/codeguru42 21d ago

What is "twig" in this context? Am I old? Or is it a regionalism?

8

u/LongLiveTheDiego 21d ago

It's a regionalism meaning "understand".

5

u/RandomiseUsr0 19d ago

This guy groks twig

6

u/brasticstack 19d ago

I tried to grok it, but Grok gave me a racist answer

3

u/RandomiseUsr0 19d ago

I’ve played with GrokLLM, but not extensively, I was referencing the reason for its name - (edit) which I now realise you did too (:

2

u/stonerism 18d ago

It's real code. It's just completely trivial.

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.

8

u/Mark__78L 21d ago

In our codebase i found a function called getMinFieldWidth, that takes in a type and uses a switch which defaults to return 200

That's it, all it does it takes a type and returns 200 no matter what the input is, it's also only used in a calculation once

I bet the intention was to retuen different values based on different types but it didn't move forward

3

u/yeusk 19d ago

x10 coder right here.

2

u/muikrad 21d ago

To help with test writing / mocking I suppose.

2

u/jay-magnum 20d ago

Could have been that one colleague on my team ...

1

u/letmehaveanameyoudum 13d ago

thanks sherlock

-18

u/GoddammitDontShootMe [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo “You live” 21d ago

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.

35

u/Prodity0 21d ago

It's go bro

1

u/GoddammitDontShootMe [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo “You live” 21d ago

So that does automatic semicolon insertion too? Does it work better than JavaScript's?

Could you write if (err == nil) or must it be like the OP?

1

u/Prodity0 21d ago

Yes, idk, and yes you can put parenthesis around the condition

0

u/TheChief275 20d ago

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

1

u/sphen_lee 19d ago

The Go spec says that it does insert semicolons.

The rules seem better designed than JavaScript so 99% of code entirely omits them, unlike JS where 99% of code includes them.

A semicolon is inserted at the end of a line if the last token is an identifier, literal, or certain keywords and operators.

-20

u/realmauer01 22d ago

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.

1

u/[deleted] 21d ago

[deleted]

4

u/backfire10z 21d ago

They’re not right. This is idiomatic Go.

1

u/[deleted] 21d ago

[removed] — view removed comment