this post was submitted on 14 Jul 2023
19 points (88.0% liked)

Programmer Humor

32000 readers
1744 users here now

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

Rules:

founded 5 years ago
MODERATORS
 
top 50 comments
sorted by: hot top controversial new old
[–] [email protected] 14 points 1 year ago (13 children)

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

load more comments (13 replies)
[–] [email protected] 5 points 1 year ago (1 children)

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

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

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

[–] [email protected] 4 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.

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

But if you code like a moron the code should still behave as expected. People who code like this deserve a special place in hell, next to languages that behave like that.

load more comments (1 replies)
[–] [email protected] 3 points 1 year ago* (last edited 1 year ago) (1 children)

This is not valid syntax as of 2020. PHP 8 fixed a lot of issue like this as well as a lot of function and variable type issues.

Also this was deprecated in PHP 7 (2015).

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

They deprecated nested ternaries?

[–] [email protected] 2 points 1 year ago* (last edited 1 year ago)

Not nested but 'Unparenthesized'

Also per the error message here is it working:

[–] [email protected] 3 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.

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

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

This is not the flex you think it is.

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

I didn’t mean it as a flex. It was a commentary on how the most commonly used programming language in current days is just as flawed as the most commonly used programming language in the past (in web development). Bad programmers are going to write bad code, regardless of the language.

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

I'd like to think Typescript does a lot of heavy lifting where JS fails when it comes to web development. On the otherhand there is no fixing fundamental flaws in PHP.

Sure bad programmers write bad code, but if a language tolerates something so obviously janky via implicit unseen magic, it's just encouraging bad practices. PHP makes this worse by tweaking core behaviours in weird and wacky ways that can easily lead to security vulnerabilities.

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

PHP Fatal error: Unparenthesized a ? b : c ? d : e is not supported. Use either (a ? b : c) ? d : e or a ? b : (c ? d : e)

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

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

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

that makes so much fucking sense

[–] [email protected] -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?

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

You don't know many languages, huh?

[–] [email protected] 2 points 1 year ago* (last edited 9 months ago)

[This comment has been deleted by an automated system]

[–] [email protected] 1 points 1 year ago (3 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.

[–] [email protected] 2 points 1 year ago (2 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.

[–] [email protected] 2 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.

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

PHP gets a totally disproportionate share of hate and that is the problem. Children like to dunk on PHP and a group mentality pushes it even more.

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

Maybe it does. Maybe it doesn't. This is the first post I have seen pointing out a flaw in PHP on Reddit or Lemmy. If you ask me JavaScript gets it the worst out of all of the languages. I don't see those guys whining.

What I will say is that the majority of PHP developers I interact with on this post has led me to believe that there is a number of PHP developers that take things way to personally that they really shouldn't. Seriously you guys aren't doing your language any favors. No one's going to want to join the whine club.

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

I took this more as a light-hearted poke at a silly edge case. As someone who used to build static analysis software for various languages, including PHP. This gets a chuckle out of me as it takes me back to having to deal with these exact types of edge cases.

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

The title of this post is calling php a “meme” did you read that part? Then it just uses some stupid ternary example no one does and that other languages exhibit so what is the point other than purely hating on php?

[–] [email protected] -1 points 1 year ago (1 children)

I used php for 2 years and I hate on it it's not just people who've never used it

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

no clue what your point is.

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

The comment above claimed only people who never used PHP hate on it. The point was a counter claim to that.

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

Ok I can add another group to my list then: bad php developers

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

Good developers don't get tribal about the tools they use

It makes them able to switch away from them for better ones

I use typescript now

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

This entire thread is a tribal post that I had a problem with!! You don’t seem to understand this but I don’t care.

load more comments (3 replies)
[–] [email protected] -1 points 1 year ago (1 children)

level 1: "this argument is worthless because you are stupid!"

level 300: "everyone who hates php is just an idiot tbh"

Just standard discourse from the php community

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

There are reasons to dislike a language, but there are no reasons to hate a language, certainly not one that is as ubiquitous as PHP. There's no argument you could make for why someone hates a programming language.

load more comments (1 replies)
[–] [email protected] 1 points 1 year ago (1 children)
[–] [email protected] 1 points 1 year ago (1 children)
[–] [email protected] 2 points 1 year ago* (last edited 1 year ago)

If you think PHP is weird, go look up ZZT-OOP, the scripting language from Tim Sweeney's first game.

(No, a scripting language for game characters doesn't need integers. If you need to count, you can do that by moving blocks around on the game board. It's halfway between LOGO and Minecraft.)

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

Finally got it...

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

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

Now do CGI.

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

load more comments
view more: next ›