this post was submitted on 12 Jun 2025
7 points (100.0% liked)

Programmer Humor

24984 readers
1101 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
 
top 29 comments
sorted by: hot top controversial new old
[–] [email protected] 1 points 1 month ago (1 children)

For optimal performance, you should rewrite it in Rust:

inline_python::python! {
    print(js2py.eval_js("(number) => number % 2 ? 'odd' : 'even'")(number))
};
[–] [email protected] 1 points 1 month ago* (last edited 1 month ago)

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

[–] [email protected] 3 points 1 month ago (1 children)

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

If you need to avoid evaluating the wrong branch:

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

[–] [email protected] 1 points 1 month ago (1 children)
[–] [email protected] 2 points 1 month ago

Not as cursed as

print("eovdedn"[n%2::2]) 
[–] [email protected] 0 points 1 month ago* (last edited 1 month ago) (1 children)

num % 2 isn't a boolean result in any of these languages, so I feel like it would always output "odd"

Edit: 0 is false, everything else is true.

[–] [email protected] -1 points 1 month ago

0 is false in C, Python, and JS. It should work

[–] [email protected] 1 points 1 month ago (2 children)
print("odd" if num % 2 else "even")

That's the native python version, for those curious

[–] [email protected] 1 points 1 month ago (3 children)

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.

[–] [email protected] 0 points 1 month ago (1 children)

At least you guys have ternary syntax cries in kotlin.

[–] [email protected] 1 points 2 weeks ago

in Scala, everything is an expression, including “if”, maybe kotlin is the same?

[–] [email protected] 0 points 1 month ago* (last edited 1 month ago) (2 children)

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

[–] [email protected] 1 points 1 month ago

Lisps makes more sense to me though

(if condition a b)

VS

a if condition else b

[–] [email protected] -1 points 1 month ago

Oh, (you) (really) (like) (Lisp)? (That's) (great!)

[–] [email protected] 0 points 1 month ago (2 children)

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

[–] [email protected] 0 points 1 month ago* (last edited 1 month ago) (1 children)

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.

[–] [email protected] 0 points 1 month ago (1 children)

You do get the if in the middle of stuff though in the form print(debug message) if $debug

[–] [email protected] 0 points 1 month ago

Wait until you learn that postfix conditionals are syntactic sugar and the compiler* turns that line into the equivalent of $debug and print(debug message), putting the conditional in first place, a lot like the ternary operator.

* Perl compiles to bytecode before running.

The ternary operator itself isn't implemented in terms of and (and or) but it could be.

[–] [email protected] 0 points 1 month ago (1 children)

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

[–] [email protected] 0 points 1 month ago (1 children)
[–] [email protected] 0 points 1 month ago

You know, the stuff in @_

[–] [email protected] -1 points 1 month ago

Why is the return first?

[–] [email protected] 1 points 1 month ago (1 children)

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

[–] [email protected] 0 points 1 month ago (1 children)

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

[–] [email protected] 1 points 1 month ago (2 children)

Because of all the garbage

[–] [email protected] 0 points 1 month 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?

[–] [email protected] 1 points 1 month ago (1 children)

Clearly the garbage collector is too effective

[–] [email protected] 1 points 1 month ago (1 children)

No they're not supposed to be piling it up

[–] [email protected] 1 points 1 month ago

Is a garbage collector not a garbage disposal. Smh.