LemmaEOF

Your favorite chubby cuddlebot

Hey! I'm Lemma, and I'm a chubby queer robot VTuber who both makes and plays games on stream! I also occasionally write short stories and tinker with other projects, so keep an eye out! See you around~

Chubbyposting and IRL NSFW alt: @cuddlebot

name-color: #39B366


You must log in to comment.

in reply to @cactus's post:

Rust does cause me pain in the amount of wrapping and unwrapping every single thing has to undergo. Also the Result and Option types need to be dealt with differently causes me to suffer

Python’s Union and Optional types are really nice

thing is in rust you could just write let foo = Some(6_i8);
it's extremely rare that you actually need to specify types of anything and even if you do you can generally throw _ and .into() everywhere

i find optionals to be annoying most of the time in rust, but at the same time it feels like the more people try to avoid the issues of optionals while keeping the upsides, the closer it seems like we’re getting to trying to reinvent null. idk that’s just my very uneducated programmer experience tho

the problem with null isn't that it exists, it's that anything could be null and you always have to remember to check. if you have a real type system that lets you specify where things can or cannot be null, null is less of a problem

Yeah and the closer a type system gets to strongly specifying “this might be null” and “this can never be null” the more it feels to me like it’s trying to reinvent optional, type systems are a flat circle

Julia has arbitrary Union types and teh equivalent to Optional[T] would bee Union{T,Nothing}, andf it works teh same way, hehe

const Optional{T} = Union{T,Nothing}

function add_with_defaults(x::Optional{T}, y::Optional{T}) where T<:Number
    a::T = x === nothing ? zero(T) : x
    b::T = y === nothing ? zero(T) : y
    return a + b
end
add_with_defaults(x::Nothing, y::Nothing) = 0

I vaguely rememberf them having nominal optional types at one pointf but I am pretty sure they just scraped them, meowf.

yeah I figured that probably existed, will definitely fn foo(x: impl Into<Option<i8>>) next time I need to. unfortunately there is no impl From<&str> for Option<String> so you can only skip one of the two types of annoying boilerplate in that case

  • typescript: null | number where either null or number is valid
  • zig: ?i32 + implicit coercion from T to ?T
  • rust: Option<i32> + Some(T)

unions like typescript are really nice until you make a generic type and realise that to be safe you need to use "null | {some: T}" in case the user passed in a nullable type, or just hope the user doesn't. but you can't enforce a constraint on the type argument to say it's not allowed to be nullable so like.

every time I write null | {some: T}, I get sad and wish I had real optionals

rust Some(T) is usually not nice but nice for generic types and nested optionals

zig is kind of cool until you do ???T and then have to do @as(??T, @as(?T, null)) or something to set the innermost optional to null.