Things I'm excited for in Go 1.21 (www.sethvargo.com)
from zik@lemmy.world to golang@programming.dev on 03 Aug 2023 00:56
https://lemmy.world/post/2553896

threaded - newest

BitSound@lemmy.world on 03 Aug 2023 04:13 next collapse

Calling one function and getting either an empty container or a container full of empty elements is very strange behavior.

hairyballs@programming.dev on 04 Aug 2023 08:41 next collapse

I honestly try and read Go news from time to time, with an open mind, but the amount of terrible footguns is astounding, especially when the language is marketed as “simple” and easy for beginner to grasp. I would pick C# or Java over it anytime.

CodeBlooded@programming.dev on 04 Aug 2023 15:10 collapse

Are you speaking about clear? It’s my understanding that clear doesn’t get you anything. It modifies the object passed to it, sure, but it doesn’t return different types back to the caller.

Edit: I notice this is downvoted- can someone provide feedback if my understanding of clear is incorrect? 🤔

BitSound@lemmy.world on 04 Aug 2023 15:40 collapse

Yeah, talking about clear. And “getting” is meant loosely, in the sense of “the state of the object after calling the function clear”. Regardless of whether the object is modified or a copy returned, that’s just weird behavior. Why not empty and zero to empty the container or reset objects in the container to their zero values respectively instead?

CodeBlooded@programming.dev on 04 Aug 2023 16:15 collapse

I see what you’re saying. Hmm. I do think that clear will be a nice addition. It does exactly what it says it’ll do, “clear” out the object. In that same vein, I think your suggestions would both be solid alternatives.

It sounds like clear is already on track to become a part of the language, but maybe you could be the first to put in a suggestion for a zero to accompany it in future releases?

mordred@lemmy.world on 04 Aug 2023 15:40 collapse

Much needed improvements to make code cleaner and smoother, especially with packages maps and slices