For optimal performance, you should rewrite it in Rust:
inline_python::python! {
print(js2py.eval_js("(number) => number % 2 ? 'odd' : 'even'")(number))
};
For optimal performance, you should rewrite it in Rust:
inline_python::python! {
print(js2py.eval_js("(number) => number % 2 ? 'odd' : 'even'")(number))
};
And now you can use wasm to run it in a browser!
Full circle 😆
Make sure the browser is made using Rust and run on a VM running on Linux, compiled to WASM.
print("odd" if num % 2 else "even")
That's the native python version, for those curious
Oh wow, I think I hate that... Condition between the results? Yuck.
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.
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
I was more talking about (+ a b)
and such.
At least you guys have ternary syntax cries in kotlin.
It's really special to not have ternary, but have Elvis.
I think it's just what you're used to. Imo it really matters that it's keywords and not operator symbols - it's meant to read closer to natural language. I prefer the c version when it's ? and :, but I like them this way round when it's if and else.
Just send pseudo code to AI and compile straight to binary.
print( ["even", "odd"][num % 2] )
If you need to avoid evaluating the wrong branch:
print( [lambda: "even", lambda: "odd"][num % 2]() )
Cursed
Not as cursed as
print("eovdedn"[n%2::2])
Indeed
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?
Because of all the garbage
One example that's giving you problems? Maybe even on a daily basis if you use it for work? What's garbage about it?
Clearly the garbage collector is too effective
No they're not supposed to be piling it up
Is a garbage collector not a garbage disposal. Smh.
Peak programming
I love something = condition and result1 or result2
in lua
Python does that, too.
https://docs.python.org/3/library/stdtypes.html#boolean-operations-and-or-not
Yeah... I played that "serial killer or programming language inventor" game.
The only one I was completely in disagreement with was the inventor of Python. He's definitely a mass-murderer
Welcome to Programmer Humor!
This is a place where you can post jokes, memes, humor, etc. related to programming!
For sharing awful code theres also Programming Horror.