zlacker

[parent] [thread] 2 comments
1. bccdee+(OP)[view] [source] 2025-08-22 15:35:49
You can write `Optional`, sure, but you can't un-write `nil`, which is what I really want. I use `Optional<T>` in Java as much as I can, and it hasn't saved me from NullPointerException.
replies(1): >>Mawr+PT
2. Mawr+PT[view] [source] 2025-08-22 20:20:13
>>bccdee+(OP)
You're not being very precise about your exact issues. `nil` isn't anywhere as much of an issue in Go as it is in Java because not everything is a reference to an object. A struct cannot be nil, etc. In Java you can literally just `return null` instead of an `Optional<T>`, not so in Go.

There aren't many possibilities for nil errors in Go once you eliminate the self-harm of abusing pointers to represent optionality.

replies(1): >>bccdee+bo4
◧◩
3. bccdee+bo4[view] [source] [discussion] 2025-08-24 09:24:19
>>Mawr+PT
Pointers are pretty common in Go though. Not as common as Java, granted—you're not NPEing on an integer—but they still get passed around a decent amount.
[go to top]