- Oro [she/they] ( @orowith2os@beehaw.org ) 7•1 year ago
The whole idea of expressions is very nice, and I can’t imagine using ternary expressions anywhere after learning Rust.
Also implicit returns ❤️
- msage ( @msage@programming.dev ) 1•1 year ago
I never got to like implicit anything.
Not even returns. Ever.
- Oro [she/they] ( @orowith2os@beehaw.org ) 1•1 year ago
Doing everything explicitly can get to be annoying, especially when it comes to what you had to do before without Vulkan’s VK_EXT_shader_object.
It’s clear that some stuff should be implicit - most types in programming languages, for example; needing to specify a struct type and then the struct itself can be annoying - and other stuff explicit, like low level operations.
Returns are something that usually fall into that “implicit” category. Why should I do
let a = function(); return a;
when I can just dofunction()
? It’s shorter, simpler, and I don’t waste keystrokes.
- james ( @james@lurk.fun ) 4•1 year ago
I like using if expressions in kotlin, but secretly sometimes I miss ternaries
- Marxine ( @Marxine@lemmy.ml ) 3•1 year ago
Having some experience with both Python and JS/TS, I don’t have much preference about ternaries or expressions. Although I always break lines for ternary statements.
const testStuff = condition ? outcome(1) : outcome(2);
Having everything on the same line ruins readability for me.
- Knusper ( @Knusper@feddit.de ) 2•1 year ago
The if-else expression that Python has is quite different from (and significantly worse than) what people mean with if-else as an expression.
So, this is Python:
volume = 100 if user_is_deaf else 50
These are two examples of if-else as an expression (Rust and Scala):
let volume = if user_is_deaf { 100 } else { 50 };
val volume = if (user_is_deaf) 100 else 50
Crucially, these look essentially equivalent to normal if-else-statements in these languages.
- lee ( @lee@programming.dev ) 1•1 year ago
personally I prefer
const testStuff = condition ? outcome(1) : outcome(2);
- RobotToaster ( @RobotToaster@infosec.pub ) English2•1 year ago
For a long time I hated ternaries, partially due to my experience with them in PHP (Who thought left-associative ternaries was a good idea? seriously?).
OpenSCAD made me love them again. It’s purely functional so you’re encouraged to use nested ternaries.
- GTG3000 ( @GTG3000@programming.dev ) 1•1 year ago
and then you have lua
local result = condition and a or b
I’m not complaining, although it gets a little confusing when one of the results is falsey. Which is a rarity since only
false
andnil
are falsey in lua.Still less intuitive than Kotlin’s if expressions.
- Leyla :) ( @LeylaaLovee@lemmy.fmhy.ml ) 1•1 year ago
It’s amazing what people have made in Roblox with that language.