▲ 624 ▼ know the features of your language (lemmy.world) submitted 2 years ago by jroid8@lemmy.world to c/programmerhumor@lemmy.ml 145 comments fedilink hide all child comments
[–] Knusper@feddit.de 33 points 2 years ago (4 children) I enjoy this: return a.or(b); But yeah, that requires an Option type rather than null pointers... permalink fedilink source hideshow 4 child comments replies: [–] Baizey@feddit.dk 6 points 2 years ago (1 child) a?.or(b) Kotlin go brr permalink fedilink source parent hideshow 1 child comment replies: [–] GissaMittJobb@lemmy.ml 10 points 2 years ago a ?: b permalink fedilink source parent [–] mea_rah@lemmy.world 6 points 2 years ago (1 child) Is that Rust? Assuming a is an Option (which would be close approximation of OP's nullable type) and assuming b is not null, then this would be closer to the original idea: a.unwrap_or(b) It returns value of a if it's not None rather than Option. permalink fedilink source parent hideshow 1 child comment replies: [–] Knusper@feddit.de 1 point 2 years ago Ah, true. Thanks. Theoretically, it was supposed to be pseudo-code, secretly inspired by Rust, but I did get that one mixed up. And I am actually even a fan of the word unwrap there, because it follows a schema and you can have your IDE auto-complete all the things you can do with an Option. In many of these other languages, you just get weird collections of symbols which you basically have to memorize and which only cover rather specific uses. permalink fedilink source parent
[–] Baizey@feddit.dk 6 points 2 years ago (1 child) a?.or(b) Kotlin go brr permalink fedilink source parent hideshow 1 child comment replies: [–] GissaMittJobb@lemmy.ml 10 points 2 years ago a ?: b permalink fedilink source parent
[–] mea_rah@lemmy.world 6 points 2 years ago (1 child) Is that Rust? Assuming a is an Option (which would be close approximation of OP's nullable type) and assuming b is not null, then this would be closer to the original idea: a.unwrap_or(b) It returns value of a if it's not None rather than Option. permalink fedilink source parent hideshow 1 child comment replies: [–] Knusper@feddit.de 1 point 2 years ago Ah, true. Thanks. Theoretically, it was supposed to be pseudo-code, secretly inspired by Rust, but I did get that one mixed up. And I am actually even a fan of the word unwrap there, because it follows a schema and you can have your IDE auto-complete all the things you can do with an Option. In many of these other languages, you just get weird collections of symbols which you basically have to memorize and which only cover rather specific uses. permalink fedilink source parent
[–] Knusper@feddit.de 1 point 2 years ago Ah, true. Thanks. Theoretically, it was supposed to be pseudo-code, secretly inspired by Rust, but I did get that one mixed up. And I am actually even a fan of the word unwrap there, because it follows a schema and you can have your IDE auto-complete all the things you can do with an Option. In many of these other languages, you just get weird collections of symbols which you basically have to memorize and which only cover rather specific uses. permalink fedilink source parent