News for hackers. Stuff that matters.
Re:Fixing a memory leak of xmlEntityPtr in librsvg by Panzer04 on Sunday June 23, 2024 @08:30PM (#40771796)
fwiw, I have to agree that having "?" at the end of a call act (as I parse the explanation) as a "return" statement seems like a very odd and deceptive semantic to have (and as you say, harder to spot).

It seems to derive from the same reason why breaks and goto are generally frowned upon if not used judiciously - they lead to unexpected control flow.

Re:Fixing a memory leak of xmlEntityPtr in librsvg by dralley on Sunday June 23, 2024 @11:08PM (#40772402)
It's not comparable to "goto" for the same reason that an early return isn't comparable to "goto". It's the furthest thing from "unexpected" control flow if you know what it does. And unlike "break" you can't accidentally mess it up. You HAVE to handle that error one way or another, and ? means "early return".

I can understand it not being intuitive to someone who has never seen it before, but that's purely a familiarity thing.

Re:Fixing a memory leak of xmlEntityPtr in librsvg by wizardforhire on Monday June 24, 2024 @02:00AM (#40772961)
I really want to upvote you but you're at 13377 karma and I would hate to fuck that up!
Re:Fixing a memory leak of xmlEntityPtr in librsvg by Panzer04 on Monday June 24, 2024 @03:25AM (#40773327)
Handling it with early return in this way still seems odd. I guess if everything is built to be done with automatic handling via scope, I can see why this way is OK. The way this would be done in my experience is just checking a return code, which feels like it's a bit more explicit if you want to early-return.

Still, lots of incorrect code has been written with that pattern as well due to incomplete cleanup, so it's not really fair to blame this syntax for it XD.

(I think most mechanisms that can jump far, including returns, need to be used carefully - nesting a return deep into a bunch of loops is just as bad)