Modern Programming
-
Python does that, too.
https://docs.python.org/3/library/stdtypes.html#boolean-operations-and-or-not
Are you just referring to how Python uses the English
and
/or
instead of the more common&&
/||
? I think what the user above you was talking about was Lua's strange ternary syntax usingand
/or
. -
Ah that makes sense.
It doesn't make sense. I understand it, but it doesn't make sense.
-
Python is kinda like that in general, unless you try to make it read like ass
You would not believe the number of people I’ve interviewed who excel at making Python read like ass.
-
You would not believe the number of people I’ve interviewed who excel at making Python read like ass.
I mean, it does have enough ways to write the same thing that it can really allow for some funny code golf, but some people just have no sense of readability whatsoever.
-
It's kinda natural to me having used Perl a lot.
That's not quite the argument you might think it is
-
That's not quite the argument you might think it is
Argument?
-
This post did not contain any content.
print( ["even", "odd"][num % 2] )
If you need to avoid evaluating the wrong branch:
print( [lambda: "even", lambda: "odd"][num % 2]() )
-
This post did not contain any content.
For optimal performance, you should rewrite it in Rust:
inline_python::python! { print(js2py.eval_js("(number) => number % 2 ? 'odd' : 'even'")(number)) };
-
Argument?
You know, the stuff in @_
-
Are you just referring to how Python uses the English
and
/or
instead of the more common&&
/||
? I think what the user above you was talking about was Lua's strange ternary syntax usingand
/or
.wrote on last edited by [email protected]no, the linked table shows how python also returns the first non-falsey result of an
a or b
expression rather than just giving a boolean. it's useful for initialising optional reference args:def foo(a: list = None) a = a or []
works with
and
as well. -
For optimal performance, you should rewrite it in Rust:
inline_python::python! { print(js2py.eval_js("(number) => number % 2 ? 'odd' : 'even'")(number)) };
wrote on last edited by [email protected]And now you can use wasm to run it in a browser!
-
And now you can use wasm to run it in a browser!
Full circle
-
Please. That's C's ternary operator. JS is just a pile of garbage cosplaying as a programming language
Why do you say it's a pile of garbage?
-
The ternary syntax is really my only real gripe with python design -- putting the conditional BETWEEN the true and false values feels so very messy to me.
wrote on last edited by [email protected]Eh, reads pretty naturally to me. That said,
(like I lisp)
-
It's kinda natural to me having used Perl a lot.
wrote on last edited by [email protected]You clearly haven't used Perl a lot. Perl's ternary looks like:
$even = $num % 2 ? "nay" : "yay";
Incidentally, it is also the same as PHP's, but mainly because PHP stole it.
-
Eh, reads pretty naturally to me. That said,
(like I lisp)
Oh, (you) (really) (like) (Lisp)?
(That's) (great!) -
Eh, reads pretty naturally to me. That said,
(like I lisp)
Lisps makes more sense to me though
(if condition a b)
VS
a if condition else b
-
Why do you say it's a pile of garbage?
Because of all the garbage
-
You clearly haven't used Perl a lot. Perl's ternary looks like:
$even = $num % 2 ? "nay" : "yay";
Incidentally, it is also the same as PHP's, but mainly because PHP stole it.
You do get the if in the middle of stuff though in the form print(debug message) if $debug
-
Full circle
Make sure the browser is made using Rust and run on a VM running on Linux, compiled to WASM.