logoalt Hacker News

loeglast Saturday at 6:36 PM4 repliesview on HN

They named Result (or Expected) Optional? No, no, "optional" means "T or empty." Not "T or E."

https://c3-lang.org/language-fundamentals/functions/#functio...


Replies

turtletontinelast Saturday at 9:25 PM

I think there is an important difference here from both Option<T> and Result<T, E>: the C3 optional doesn’t allow an arbitrary error type, it’s just a C-style integer error code. I think that makes a lot of sense and fits perfectly with their “evolution, not revolution” philosophy. And the fact that the syntax is ‘type?’ rather than ‘Optional<type>’ also eases any confusion.

show 1 reply
jeremyjhyesterday at 1:18 AM

From what I can see there you never write the word “Optional” in your code. This is just what they named the feature which stays close to C semantics without the burden of *out params.

fwiplast Saturday at 6:47 PM

I share your distaste for arbitrarily renaming concepts. However, I think if you only have one of the two in the language, Optional is the clearer name.

A result is already the informal name of the outcome or return value of every regular operation or function call, whereas an Optional is clearly not a regular thing.

I also think, from a pragmatic systems-design point of view, it might make sense to only support the Either/Result pattern. It's not too much boilerplate to add a `faultdef KeyNotInMap`, and then it's clear to the consumer why a real answer was not returned.

show 1 reply
paulddraperyesterday at 12:37 AM

Oof.

You can name it "Result" or (questionably) "Either."

Not "Option," "Optional," or "Maybe;" those are something else.