566
top 50 comments
sorted by: hot top controversial new old
[-] Ephera@lemmy.ml 121 points 1 day ago

For optimal performance, you should rewrite it in Rust:

inline_python::python! {
    print(js2py.eval_js("(number) => number % 2 ? 'odd' : 'even'")(number))
};
[-] ATPA9@feddit.org 69 points 1 day ago* (last edited 1 day ago)

And now you can use wasm to run it in a browser!

[-] victorz@lemmy.world 24 points 1 day ago
[-] ulterno@programming.dev 12 points 1 day ago

Make sure the browser is made using Rust and run on a VM running on Linux, compiled to WASM.

[-] entropicdrift@lemmy.sdf.org 136 points 1 day ago
print("odd" if num % 2 else "even")

That's the native python version, for those curious

[-] laurelraven@lemmy.zip 3 points 19 hours ago

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.

[-] balsoft@lemmy.ml 22 points 1 day ago* (last edited 1 day ago)

Eh, reads pretty naturally to me. That said, (like I lisp)

[-] Shareni@programming.dev 13 points 1 day ago

Lisps makes more sense to me though

(if condition a b)

VS

a if condition else b

[-] balsoft@lemmy.ml 9 points 1 day ago

I was more talking about (+ a b) and such.

load more comments (2 replies)
[-] idunnololz@lemmy.world 4 points 1 day ago

At least you guys have ternary syntax cries in kotlin.

[-] Aqarius@lemmy.world 2 points 20 hours ago

It's really special to not have ternary, but have Elvis.

[-] rbos@lemmy.ca 12 points 1 day ago

It's kinda natural to me having used Perl a lot.

[-] SpaceNoodle@lemmy.world 20 points 1 day ago

That's not quite the argument you might think it is

load more comments (10 replies)
load more comments (5 replies)
[-] porous_grey_matter@lemmy.ml 1 points 1 day ago

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.

load more comments (9 replies)
[-] owl@infosec.pub 18 points 1 day ago

Just send pseudo code to AI and compile straight to binary.

[-] mdhughes@lemmy.sdf.org 39 points 1 day ago

print( ["even", "odd"][num % 2] )

If you need to avoid evaluating the wrong branch:

print( [lambda: "even", lambda: "odd"][num % 2]() )

[-] FireIced@lemmy.super.ynh.fr 8 points 1 day ago
[-] gamma@programming.dev 10 points 20 hours ago

Not as cursed as

print("eovdedn"[n%2::2]) 
[-] SpaceNoodle@lemmy.world 57 points 1 day ago

Please. That's C's ternary operator. JS is just a pile of garbage cosplaying as a programming language

[-] victorz@lemmy.world 4 points 1 day ago

Why do you say it's a pile of garbage?

[-] SpaceNoodle@lemmy.world 18 points 1 day ago

Because of all the garbage

[-] victorz@lemmy.world 2 points 22 hours ago

One example that's giving you problems? Maybe even on a daily basis if you use it for work? What's garbage about it?

[-] Fillicia@sh.itjust.works 7 points 1 day ago

Clearly the garbage collector is too effective

[-] filcuk@lemmy.zip 3 points 1 day ago

No they're not supposed to be piling it up

[-] piccolo@sh.itjust.works 6 points 1 day ago

Is a garbage collector not a garbage disposal. Smh.

Peak programming

[-] capuccino@lemmy.world 11 points 1 day ago

I love something = condition and result1 or result2 in lua

[-] PattyMcB@lemmy.world 10 points 1 day ago

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

load more comments (1 replies)
load more comments
view more: next ›
this post was submitted on 12 Jun 2025
566 points (98.6% liked)

Programmer Humor

24143 readers
2879 users here now

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.

Rules

founded 2 years ago
MODERATORS