▲ 651 ▼ functions (lemmy.ml) submitted 9 months ago by cipherd@lemmy.ml to c/programmer_humor@programming.dev 118 comments fedilink hide all child comments cross-posted from: https://lemmy.ml/post/39334581
[–] joyjoy@lemmy.zip 14 points 9 months ago* (1 child) Kotlin also lets you do fun x() = y() permalink fedilink source hideshow 2 child comments replies: [–] spongebue@lemmy.world 5 points 9 months ago (2 children) I have no idea why you'd need that especially since return y() is pretty easy, but... I want it! (Actually, I guess a super simple way of overloading a method, like fun x() = x(defaultValue) could be neat) permalink fedilink source parent hideshow 4 child comments replies: [–] calcopiritus@lemmy.world 9 points 9 months ago (1 child) This can also be a side product for code blocks being expressions instead of statements. In rust for example they are, so it's not rare to see functions like: fn add_one(x: i32) -> i32 { x+1 } This lets you do amazing things like: let x = if y < 0.0 { 0.0 } else { y } which is the same as x = y < 0.0 ? 0.0 : y But is much better for more complex logic. So you can forget about chaining 3-4 ternary operations in a single line. permalink fedilink source parent hideshow 2 child comments replies: [–] SlurpingPus@lemmy.world 3 points 9 months ago* (last edited 9 months ago) Lisp programmers seeing these ‘amazing things’: But yeah, every time I'm trying to do a ternary in Lua, I miss being able to just throw in an if. Thankfully it can be amended with Fennel. permalink fedilink source parent [–] eager_eagle@lemmy.world 4 points 9 months ago* (2 children) default values is one of my pet-peeves after using Python regularly. I wish more languages would let you just do something like def do_thing(arg=default_value) without hoops like builder pattern, function overloading, or whatnot permalink fedilink source parent hideshow 4 child comments replies: [–] PoolloverNathan@programming.dev 2 points 9 months ago (Kotlin does support that, with the same fun do_thing(arg: Int = 2) syntax.) permalink fedilink source parent [–] SlurpingPus@lemmy.world 2 points 9 months ago* (1 child) I mean, the go-to approach in Lisp, for example, is to have null as the default value (which doubles for false in there). And check for that in the function. permalink fedilink source parent hideshow 2 child comments replies: [–] joyjoy@lemmy.zip 1 point 9 months ago (1 child) That sounds awfully similar to JavaScript, which uses undefined as default values. permalink fedilink source parent hideshow 2 child comments replies: [–] SlurpingPus@lemmy.world 1 point 9 months ago (1 child) In Lisp, at least the Emacs Lisp with which I have experience, it's customary to put in nil (Lisp's null) for any omitted arguments in the middle that you can't be arsed to specify — aside from just leaving off arguments at the end. In JS, typing in undefined in every such case would probably be an annoyance, so I'm guessing coders need to check for both undefined and null in these circumstances. Overall, it's remarkable how Lisp teaches one to be much more relaxed about programming practices than is typical for mainstream languages. Design patterns? Data structures? Shit, just pass in a list or an assoc array, and maybe a function here and there. Also everything is an expression, enjoy your ternary (if) at any point anywhere. permalink fedilink source parent hideshow 2 child comments replies: [–] eager_eagle@lemmy.world 1 point 9 months ago Design patterns? Data structures? Shit, just pass in a list or an assoc array, and maybe a function here and there After trying to be relaxed about data structures in python, I can say that, IMO, this is more harmful than beneficial. Good types and structures lead to good code designs. permalink fedilink source parent
[–] spongebue@lemmy.world 5 points 9 months ago (2 children) I have no idea why you'd need that especially since return y() is pretty easy, but... I want it! (Actually, I guess a super simple way of overloading a method, like fun x() = x(defaultValue) could be neat) permalink fedilink source parent hideshow 4 child comments replies: [–] calcopiritus@lemmy.world 9 points 9 months ago (1 child) This can also be a side product for code blocks being expressions instead of statements. In rust for example they are, so it's not rare to see functions like: fn add_one(x: i32) -> i32 { x+1 } This lets you do amazing things like: let x = if y < 0.0 { 0.0 } else { y } which is the same as x = y < 0.0 ? 0.0 : y But is much better for more complex logic. So you can forget about chaining 3-4 ternary operations in a single line. permalink fedilink source parent hideshow 2 child comments replies: [–] SlurpingPus@lemmy.world 3 points 9 months ago* (last edited 9 months ago) Lisp programmers seeing these ‘amazing things’: But yeah, every time I'm trying to do a ternary in Lua, I miss being able to just throw in an if. Thankfully it can be amended with Fennel. permalink fedilink source parent [–] eager_eagle@lemmy.world 4 points 9 months ago* (2 children) default values is one of my pet-peeves after using Python regularly. I wish more languages would let you just do something like def do_thing(arg=default_value) without hoops like builder pattern, function overloading, or whatnot permalink fedilink source parent hideshow 4 child comments replies: [–] PoolloverNathan@programming.dev 2 points 9 months ago (Kotlin does support that, with the same fun do_thing(arg: Int = 2) syntax.) permalink fedilink source parent [–] SlurpingPus@lemmy.world 2 points 9 months ago* (1 child) I mean, the go-to approach in Lisp, for example, is to have null as the default value (which doubles for false in there). And check for that in the function. permalink fedilink source parent hideshow 2 child comments replies: [–] joyjoy@lemmy.zip 1 point 9 months ago (1 child) That sounds awfully similar to JavaScript, which uses undefined as default values. permalink fedilink source parent hideshow 2 child comments replies: [–] SlurpingPus@lemmy.world 1 point 9 months ago (1 child) In Lisp, at least the Emacs Lisp with which I have experience, it's customary to put in nil (Lisp's null) for any omitted arguments in the middle that you can't be arsed to specify — aside from just leaving off arguments at the end. In JS, typing in undefined in every such case would probably be an annoyance, so I'm guessing coders need to check for both undefined and null in these circumstances. Overall, it's remarkable how Lisp teaches one to be much more relaxed about programming practices than is typical for mainstream languages. Design patterns? Data structures? Shit, just pass in a list or an assoc array, and maybe a function here and there. Also everything is an expression, enjoy your ternary (if) at any point anywhere. permalink fedilink source parent hideshow 2 child comments replies: [–] eager_eagle@lemmy.world 1 point 9 months ago Design patterns? Data structures? Shit, just pass in a list or an assoc array, and maybe a function here and there After trying to be relaxed about data structures in python, I can say that, IMO, this is more harmful than beneficial. Good types and structures lead to good code designs. permalink fedilink source parent
[–] calcopiritus@lemmy.world 9 points 9 months ago (1 child) This can also be a side product for code blocks being expressions instead of statements. In rust for example they are, so it's not rare to see functions like: fn add_one(x: i32) -> i32 { x+1 } This lets you do amazing things like: let x = if y < 0.0 { 0.0 } else { y } which is the same as x = y < 0.0 ? 0.0 : y But is much better for more complex logic. So you can forget about chaining 3-4 ternary operations in a single line. permalink fedilink source parent hideshow 2 child comments replies: [–] SlurpingPus@lemmy.world 3 points 9 months ago* (last edited 9 months ago) Lisp programmers seeing these ‘amazing things’: But yeah, every time I'm trying to do a ternary in Lua, I miss being able to just throw in an if. Thankfully it can be amended with Fennel. permalink fedilink source parent
[–] SlurpingPus@lemmy.world 3 points 9 months ago* (last edited 9 months ago) Lisp programmers seeing these ‘amazing things’: But yeah, every time I'm trying to do a ternary in Lua, I miss being able to just throw in an if. Thankfully it can be amended with Fennel. permalink fedilink source parent
[–] eager_eagle@lemmy.world 4 points 9 months ago* (2 children) default values is one of my pet-peeves after using Python regularly. I wish more languages would let you just do something like def do_thing(arg=default_value) without hoops like builder pattern, function overloading, or whatnot permalink fedilink source parent hideshow 4 child comments replies: [–] PoolloverNathan@programming.dev 2 points 9 months ago (Kotlin does support that, with the same fun do_thing(arg: Int = 2) syntax.) permalink fedilink source parent [–] SlurpingPus@lemmy.world 2 points 9 months ago* (1 child) I mean, the go-to approach in Lisp, for example, is to have null as the default value (which doubles for false in there). And check for that in the function. permalink fedilink source parent hideshow 2 child comments replies: [–] joyjoy@lemmy.zip 1 point 9 months ago (1 child) That sounds awfully similar to JavaScript, which uses undefined as default values. permalink fedilink source parent hideshow 2 child comments replies: [–] SlurpingPus@lemmy.world 1 point 9 months ago (1 child) In Lisp, at least the Emacs Lisp with which I have experience, it's customary to put in nil (Lisp's null) for any omitted arguments in the middle that you can't be arsed to specify — aside from just leaving off arguments at the end. In JS, typing in undefined in every such case would probably be an annoyance, so I'm guessing coders need to check for both undefined and null in these circumstances. Overall, it's remarkable how Lisp teaches one to be much more relaxed about programming practices than is typical for mainstream languages. Design patterns? Data structures? Shit, just pass in a list or an assoc array, and maybe a function here and there. Also everything is an expression, enjoy your ternary (if) at any point anywhere. permalink fedilink source parent hideshow 2 child comments replies: [–] eager_eagle@lemmy.world 1 point 9 months ago Design patterns? Data structures? Shit, just pass in a list or an assoc array, and maybe a function here and there After trying to be relaxed about data structures in python, I can say that, IMO, this is more harmful than beneficial. Good types and structures lead to good code designs. permalink fedilink source parent
[–] PoolloverNathan@programming.dev 2 points 9 months ago (Kotlin does support that, with the same fun do_thing(arg: Int = 2) syntax.) permalink fedilink source parent
[–] SlurpingPus@lemmy.world 2 points 9 months ago* (1 child) I mean, the go-to approach in Lisp, for example, is to have null as the default value (which doubles for false in there). And check for that in the function. permalink fedilink source parent hideshow 2 child comments replies: [–] joyjoy@lemmy.zip 1 point 9 months ago (1 child) That sounds awfully similar to JavaScript, which uses undefined as default values. permalink fedilink source parent hideshow 2 child comments replies: [–] SlurpingPus@lemmy.world 1 point 9 months ago (1 child) In Lisp, at least the Emacs Lisp with which I have experience, it's customary to put in nil (Lisp's null) for any omitted arguments in the middle that you can't be arsed to specify — aside from just leaving off arguments at the end. In JS, typing in undefined in every such case would probably be an annoyance, so I'm guessing coders need to check for both undefined and null in these circumstances. Overall, it's remarkable how Lisp teaches one to be much more relaxed about programming practices than is typical for mainstream languages. Design patterns? Data structures? Shit, just pass in a list or an assoc array, and maybe a function here and there. Also everything is an expression, enjoy your ternary (if) at any point anywhere. permalink fedilink source parent hideshow 2 child comments replies: [–] eager_eagle@lemmy.world 1 point 9 months ago Design patterns? Data structures? Shit, just pass in a list or an assoc array, and maybe a function here and there After trying to be relaxed about data structures in python, I can say that, IMO, this is more harmful than beneficial. Good types and structures lead to good code designs. permalink fedilink source parent
[–] joyjoy@lemmy.zip 1 point 9 months ago (1 child) That sounds awfully similar to JavaScript, which uses undefined as default values. permalink fedilink source parent hideshow 2 child comments replies: [–] SlurpingPus@lemmy.world 1 point 9 months ago (1 child) In Lisp, at least the Emacs Lisp with which I have experience, it's customary to put in nil (Lisp's null) for any omitted arguments in the middle that you can't be arsed to specify — aside from just leaving off arguments at the end. In JS, typing in undefined in every such case would probably be an annoyance, so I'm guessing coders need to check for both undefined and null in these circumstances. Overall, it's remarkable how Lisp teaches one to be much more relaxed about programming practices than is typical for mainstream languages. Design patterns? Data structures? Shit, just pass in a list or an assoc array, and maybe a function here and there. Also everything is an expression, enjoy your ternary (if) at any point anywhere. permalink fedilink source parent hideshow 2 child comments replies: [–] eager_eagle@lemmy.world 1 point 9 months ago Design patterns? Data structures? Shit, just pass in a list or an assoc array, and maybe a function here and there After trying to be relaxed about data structures in python, I can say that, IMO, this is more harmful than beneficial. Good types and structures lead to good code designs. permalink fedilink source parent
[–] SlurpingPus@lemmy.world 1 point 9 months ago (1 child) In Lisp, at least the Emacs Lisp with which I have experience, it's customary to put in nil (Lisp's null) for any omitted arguments in the middle that you can't be arsed to specify — aside from just leaving off arguments at the end. In JS, typing in undefined in every such case would probably be an annoyance, so I'm guessing coders need to check for both undefined and null in these circumstances. Overall, it's remarkable how Lisp teaches one to be much more relaxed about programming practices than is typical for mainstream languages. Design patterns? Data structures? Shit, just pass in a list or an assoc array, and maybe a function here and there. Also everything is an expression, enjoy your ternary (if) at any point anywhere. permalink fedilink source parent hideshow 2 child comments replies: [–] eager_eagle@lemmy.world 1 point 9 months ago Design patterns? Data structures? Shit, just pass in a list or an assoc array, and maybe a function here and there After trying to be relaxed about data structures in python, I can say that, IMO, this is more harmful than beneficial. Good types and structures lead to good code designs. permalink fedilink source parent
[–] eager_eagle@lemmy.world 1 point 9 months ago Design patterns? Data structures? Shit, just pass in a list or an assoc array, and maybe a function here and there After trying to be relaxed about data structures in python, I can say that, IMO, this is more harmful than beneficial. Good types and structures lead to good code designs. permalink fedilink source parent