this post was submitted on 14 Jul 2023
4 points (70.0% liked)

Programmer Humor

32054 readers
1392 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

founded 5 years ago
MODERATORS
 
top 20 comments
sorted by: hot top controversial new old
[–] kibiz0r@lemmy.world 7 points 1 year ago (1 children)

To be fair: If you are chaining ternary expressions, you deserve to suffer whatever pain the language happens to inflict upon you tenfold.

[–] Serdan@lemm.ee -1 points 1 year ago (1 children)

Why?

It's perfectly readable.

[–] lowleveldata@programming.dev 1 points 1 year ago (1 children)

It is sort of readable. A switch is "perfectly" readable for switching.

[–] Serdan@lemm.ee -1 points 1 year ago (1 children)

Ternary expressions aren't switches though

[–] Kryomaani@sopuli.xyz 1 points 1 year ago

Which is exactly why you shouldn't be using them in a situation that clearly calls for a switch.

[–] mikegioia@lemmy.ml 3 points 1 year ago (1 children)

Hating on php is one of the reasons i left reddit. This is just people who don’t use php hating php for some reason. You can do dumb examples like this for any language. Low effort and funny for children.

[–] deaf_fish@lemm.ee 1 points 1 year ago (1 children)

Your feelings are valid. I wonder though, would you put up this level of defense for posts making fun of arbitrary parts of non PHP languages?

You are not your favorite language. And I find most criticisms of most languages to be very valid. I don't think the intent of OP is to insult all PHP programmers. It's okay to like a language that has problems. All languages do.

[–] Doug@midwest.social 1 points 1 year ago

I'd wager prevalence is part of their problem. Jokes get tired after a while, but that doesn't always mean they stop.

PHP, like any language, has its problems, but it seems to get poked at a lot more often. But making the same joke over and over has been a problem long before reddit was a thing.

[–] skullgiver@popplesburger.hilciferous.nl 2 points 1 year ago* (last edited 9 months ago)

[This comment has been deleted by an automated system]

[–] cupcakezealot@lemmy.blahaj.zone 2 points 1 year ago (1 children)

The fault is the programmer for not using a switch statement.

[–] thatwill@lemmy.world 4 points 1 year ago (2 children)

"php doesn't stop me from coding like a moron, therefore php sucks"

[–] Araozu@lemmy.world -2 points 1 year ago

How about "php enables me to code like a moron", or even better, "php breaks common conventions and forces me to think about every little detail and special edge case, slowing me down if I don't want to accidentally 'code like a moron' "

Nested ternary operators emerge because of the lack of if/switch expressions (which is C fault), so they are "useful" (they shouldn't be). However, PHP is the only language that treats it as left associative. This has 2 problems:

  • You are forced to use parenthesis. Some (insane) people might do: (cond1) ? "A" : (cond2) ? "B" : "C" And it makes sense. Its ugly af, but it makes sense. But PHP now forces you to use more parethesis. It's making you work more.
  • It breaks convention. If you come from any other language and use ternary operators, you will get unexpected results. After hours of banging your head against the wall, you realize the problem. And now you have to learn a new edge case in the language, and what to do to actually use the language.

"But you shouldn't use ternary operators anyway! Use if/switch/polymorphic dispatch/goto/anything else"

True, but still, the feature is there, and its bad. The fact that there are other alternatives doesn't make the PHP ternary operator worse than other languages' ternary operator.

PHP works against you. That's the problem. The ternary operator is not a good example, since there are alternatives. But look at something so simple, so mundane like strpos.

If strpos doesn't find returns false. Every other language returns -1. And if you then use this value elsewhere, PHP will cast it to 0 for you. Boom, your program is broken, and you have to stare at the screen for hours, looking for the error.

"BuT yOU sHoUlD AlwAyS cHEcK tHe rETurN eRRor!"

And even if that's true, if we all must check the return value, does PHP force you to do so? Like checked exceptions in Java? Or all the Option & Result in Rust? throws, throws, throws... unwrap, unwrap, unwrap... (Many) people hate those features

PHP works against you. And that's why its bad.

[–] bastian_5@sh.itjust.works -2 points 1 year ago

I say that php breaks math entirely, and is therefore bad. "" == null returns true null == [] returns true "" == [] returns false.

In more recent versions it gets worse, because it has 0 == "any text" return true, "any text" == true return true, and 1 == true return true So indirectly 1 = 0, and now math is more directly broken.

[–] NorwegianBlues@sh.itjust.works 2 points 1 year ago (1 children)

Sure, it's counterintuitive, but so is not bracketing things in ternary operations.

[–] ezchili@iusearchlinux.fyi -1 points 1 year ago (1 children)

You know that programmers of other languages don't have to find excuses for their tool constantly, right?

[–] rikudou@lemmings.world 1 points 1 year ago

You don't know many languages, huh?

[–] Arotrios@kbin.social 1 points 1 year ago

Now do CGI.

Please. I worked with it for five years and I still don't understand it.

[–] xedrak@kbin.social 1 points 1 year ago (1 children)

I get hating on PHP is a meme, and the language certainly has faults, but I feel like it’s no more arbitrary than how JavaScript behaves. And just like JavaScript, if you follow modern standards and use a modern version, it’s a much better experience. The language is only as good as the programmer.

[–] CanadaPlus@lemmy.sdf.org 0 points 1 year ago* (last edited 1 year ago)

but I feel like it’s no more arbitrary than how JavaScript behaves

This is not the flex you think it is.

[–] Lemmypy@feddit.nl 1 points 1 year ago

Finally got it...

$a == 1 ? "one" : ( ( $a == 2 ? "two" : $a == 3 ) ? "three" : "other" )