Re:Embedded Swift on the Raspberry Pi Pico
by secretsatan on Wednesday March 06, 2024 @07:17PM
(#39623530)
Tbh, i now look at optionals as another colour when i read this https://journal.stuffwithstuff.com/2015/02/01/what-color-is-...
You return an optional with no reason, it colours all subsequent calls.
When i was younger, i thought of them as an extension of bool, yes/no/maybe, but now, was it cancelled? Did an error occur? Did it just timed out? How many cpu cycles am i wasting throughout my code because every thing down the line checks it for null? It snowballs
`if let x { }`
Which while small, is great if you do it all the time.
Swift though made me question how much I used optionals, now I get annoyed if they're over used, it usually means someone down the line has not made a decision, they propagate through the program and eventually someone wonders why they didn't get a value.
I like the Result type and the Flexibility of the Enums a lot for this