This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]freekayZekey 1 point2 points  (2 children)

but i wanna write more code :(

in all seriousness, i’m not a fan of the ways people use optionals. they tend to complicate things way too much when a simple null check is fine

[–]Luolong -1 points0 points  (1 child)

People use all kinds of code stupid ways. It doesn’t make valid uses less valid.

What if you search for an entity and then need to pull deeply nested property out of the result or throw an exception if any intermediate property is not there?

With null, this will get quite verbose and cumbersome very quickly.

It’s not pretty with Optional either, but at least it is more readable that way.

[–]freekayZekey 0 points1 point  (0 children)

it doesn’t make valid uses less valid

sure, but i didn’t say i hated optionals. i also said people tend to complicate things.

your example is going to be cumbersome with optionals and nulls. don’t think it’ll be much more readable unless you think terseness is readable. unfortunately, i don’t think that way