There have been multiple accounts created with the sole purpose of posting advertisement posts or replies containing unsolicited advertising.

Accounts which solely post advertisements, or persistently post them may be terminated.

lemmy.world

Lemmypy , to programmerhumor in and people wonder why we say PHP is a meme

Finally got it…

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

nihilomaster ,

because “two” is a truthy value?

Worthstream ,

Yep, any non empty string is truthy.

xedrak , to programmerhumor in and people wonder why we say PHP is a meme
@xedrak@kbin.social avatar

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.

Frools ,

That’s why JS gets hates on just as much as PHP, if not more so these days as JS is fuckin everywhere!

cupcakezealot ,
@cupcakezealot@lemmy.blahaj.zone avatar

JS is just popular because Google invests so much money into it to use it to make the web worse off.

CanadaPlus ,

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

This is not the flex you think it is.

xedrak ,
@xedrak@kbin.social avatar

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.

Funwayguy ,
@Funwayguy@lemmy.world avatar

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.

CanadaPlus ,

A high level language should make coding easier. If it doesn’t why not just code in assembly, or even build an ASIC? And no, allowing you to fuck yourself by accident isn’t making your life easier even if it seems simpler at the time you write the code.

CanadaPlus , (edited )

Why not just use a good language though? Most of them are decent. It sounds like typescript is getting used a lot, at least - although it then gets turned into JavaScript for the browser.

zalgotext ,

Why not just use a good language though?

You don’t really have a choice when it comes to front end web dev, JS is almost the only option for programming languages that run in the browser.

CanadaPlus ,

Yes, there’s a lot of lock-in with JavaScript. The first step would be designing a Python-based browser or whatever and getting people to use it. I know less about PHP.

That was more of a “why if you had the option”. I’ve use JavaScript too for exactly this reason.

Xariphon , to aww in "i love to snuggle with you :3!"

Even when the size of a horse, cat wants snuggles.

kibiz0r , to programmerhumor in and people wonder why we say PHP is a meme

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

Serdan ,

Why?

It’s perfectly readable.

lowleveldata ,

It is sort of readable. A switch is “perfectly” readable for switching.

Serdan ,

Ternary expressions aren’t switches though

Kryomaani ,

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

Serdan ,

In the given example I’d probably use a switch / match expression, but ternaries are usually more flexible than switches and I don’t think it’s an issue to write a nested ternary instead of if else statements.

lowleveldata ,

ternaries are usually more flexible than switches

Which is bad for readability because the reader need to manually compute it to see whether it’s doing simple switching or not. Also it adds the question of “Why did the author use a nested ternary instead of a switch? Was it meant to do more but get left out unintentionally?”

Serdan ,

Yes, you need to read code to understand it. If else statements can also do the job of a switch, so the exact same argument applies.

lowleveldata ,

The point is I don’t need to read a switch statement to know that it is a switch

rikudou ,

Match is even better, short and sweet.

deaf_fish ,

There is usually a safer and more readable way to do what you want to do by chaining ternaries in most languages.

Serdan ,

How is it unsafe?

deaf_fish ,

Well, if you assume ternary operations work the same in PHP as in c and attempted to write the code demoed by this meme. You would end up with unexpected behavior. Maybe I should have said unexpected behavior instead of unsafe behavior.

Serdan ,

PHP is the only language in existence with a left associative ternary operator. Ignoring PHP, the operator has worked exactly the same way for decades. And even PHP has now fixed the operator.

I don’t think it’s reasonable to avoid a very commonly supported pattern just because a single badly designed language implemented it wrong.

deaf_fish ,

Okay, even if I give you the unexpected behavior point. The readability problem remains. Switch statements or tables will work just fine and are easier to read.

To be clear, I am fine with single ternary operations. I think nested ternary operations are harder to read and follow.

Serdan ,

I agree you should use a switch where applicable, but ternaries are the expression equivalent of if-else statements. If I have two conditions and a default, and each branch simply evaluates to a value of the same type, I’ll probably just use a ternary.

baascus , to programmerhumor in and people wonder why we say PHP is a meme
@baascus@lemmy.world avatar

Ever wondered about the array_fill function? It can be baffling. Try filling an array with a negative index:

array_fill(-5, 4, ‘test’);

Many languages would throw an error, but PHP? It’s perfectly fine with this and you get an array starting at index -5. It’s like PHP is the Wild West of array indexing!

marcos ,

Well, many languages are perfectly ok with negative array indexes.

But all of those languages are either statically typed ones where you declare the boundings with the array, or php.

baascus ,
@baascus@lemmy.world avatar

Absolutely, many languages do allow negative indices. The intriguing part about PHP, though, is that its ‘arrays’ are actually ordered maps (or hash tables) under the hood. This structure allows for a broader range of keys, like our negative integers or even strings. It’s a unique design choice that sets PHP apart and allows for some really interesting usage patterns. Not your everyday array, right?

Funwayguy ,
@Funwayguy@lemmy.world avatar

I’ve been working with PHP for two years now (not by choice) but I still sometimes forget the weird behaviours these not-arrays cause. Recently I was pushing/popping entries in a queue and it fucked the indexing. I had programmed it like I would any other sane language and it wasn’t until I was stepping through the bug I realised I had forgotten about this.

I hate PHP for so many more reasons. It baffles me why anyone would think it was a good idea to design it this way. Thankfully my current job involves actively burning it down and preparing for its replacement.

Windex007 ,

You think that’s bad, just wait until you hear what C does

mosiacmango ,

“Shot myself in the foot? No, no. I took out the whole leg.”

exu ,

That’s C++ you’re thinking off.

rikudou ,

Yeah, because casting everything to void* is so safe.

fsniper ,

it was never an array to begin with!

Clocker108 , to mildlyinfuriating in Updated my Samsung phone and it installed unwanted apps

guess its carrier stuff?

x4740N ,
@x4740N@lemmy.world avatar

Yeah I have a Samsung phone and have never had this problem so I’m guessing it’s carrier stuff and op is unkowongly placing blame on the wrong company here

dan ,
@dan@upvote.au avatar

I wish manufacturers didn’t allow carriers to install junk on their phone.

On the other hand, this is how carriers can give you a good deal on a phone… They have to subsidise it by making deals with the companies that make apps like these.

GoosLife ,

If they have to trick you by installing unwanted apps on your phone, where you don’t even know it’s them doing it, then it sounds more like a scam than a great deal.

dan ,
@dan@upvote.au avatar

I agree. That’s unfortunately how it is today though - either you pay full price for an unlocked phone (which some people can’t afford), or you get junk apps on it. You can usually disable the junk apps at least.

Chonk , to mildlyinfuriating in Updated my Samsung phone and it installed unwanted apps

Happened to me too every time I update my Samsung J6

tallwookie , to mildlyinfuriating in This news site is 60% Amazon ads.
@tallwookie@lemmy.world avatar

only ever really see ads when I’m at work. all the things are blocked at home & on phone.

dot20 , to programmerhumor in and people wonder why we say PHP is a meme

Ah, I understand now. The expression is evaluated like this:

  • $a == 1 ? “one” : $a == 2 ? “two” : $a == 3 ? “three” : “other”
  • $a == 2 ? “two” : $a == 3 ? “three” : “other”
  • “two” ? “three” : “other”
  • “three”
lightsecond ,

Halp. I don’t understand how it went from step 2 to step 3.

sanguinet ,

It’s cause PHP associates the if-then-else pair only with its immediate “else” option, not with the entirety of the line.

Let’s go by parts.

$a == 1 ? “one” : $a == 2 ? “two” : $a == 3 ? “three” : “other”

Is $a equal to 1? If so, we’re “set” to the value on the left, which is “one”, if not then we’re set to the value on the right, which is $a == 2. $a is not equal to 1, so we’re set to the right value, $a == 2.

This replaces the relevant part, $a == 1 ? “one” : $a == 2, with $a == 2. So we’re left with:

$a == 2 ? “two” : $a == 3 ? “three” : “other”

Next, is $a equal to 2? If so, we’re set to “two”, if not we’re set to $a == 3. The comparison is true, so we’re set to the value on the left, “two”. The relevant part here is $a == 2 ? “two” : $a == 3 only, so it replaces it with “two” cause again, PHP is only associating with its immediate pair. So now we’re left with:

“two” ? “three” : “other”

Finally, is “two” truthy? If so, we’re set to “three”, if not we’re set to “other”. Since “two” is truthy we’re then left with “three”.

It’s super confusing for sure.

zarp86 ,

Thank you for the great explanation, and for teaching me the word “truthy.”

lightsecond ,

Thank you!

lugal ,

Thanks! I never worked with PHP but I understand your explanation. Making memes about languages is also about learning

Gnugit , to internetfuneral in Profiles you

Source please.

Judgy_McJudgerson ,

Following; I would like to know too.

Was it one of the Silent Hills?

very_well_lost ,
Judgy_McJudgerson ,

Thank you!

Gnugit ,

Thank you!

Judgy_McJudgerson ,

Hey; if you’re interested in this, I recommend Nevermind. It’s a game that gets harder when you get scared. It uses a heart rate monitor or your webcam. It’s supposed to teach you to make yourself calm down.

SaveComengs ,

that’s cool af

Gnugit ,

That sounds awesome, thank you!

Whirlybird , to mildlyinfuriating in Updated my Samsung phone and it installed unwanted apps

What model + what country + did you get your phone subsidized by a carrier? Literally never had this happen on any of my multiple samsung phones.

clearedtoland , to pics in A picture of the moon I took with my Nikon Coolpix P1000

I seriously have to buy that camera off eBay or something. For science!

Mookulator , to programmerhumor in and people wonder why we say PHP is a meme

Why

BorgDrone ,

To quote the guy who invented PHP:

“I don’t know how to stop it, there was never any intent to write a programming language […] I have absolutely no idea how to write a programming language, I just kept adding the next logical step on the way.”

larvyde ,

Yes, PHP was originally meant to be a template language, like handlebars or thymeleaf, but kept on accumulating features along the way…

ezchili ,

They didn’t think about which order ternaries should compute in when they coded the php interpreter

tal , to selfhosted in What's your uptime record?
@tal@kbin.social avatar

I remember this story from about twenty years back hitting the news:

https://www.theregister.com/2001/04/12/missing_novell_server_discovered_after/

Missing Novell server discovered after four years

In the kind of tale any aspiring BOFH would be able to dine out on for months, the University of North Carolina has finally located one of its most reliable servers - which nobody had seen for FOUR years.

One of the university's Novell servers had been doing the business for years and nobody stopped to wonder where it was - until some bright spark realised an audit of the campus network was well overdue.

According to a report by Techweb it was only then that those campus techies realised they couldn't find the server. Attempts to follow network cabling to find the missing box led to the discovery that maintenance workers had sealed the server behind a wall.

arke , to newcommunities in In 24hours, Meme about old memes pushes c/AntiqueMemesRoadShow to 7th largest community with "meme" in the title

Keep hearing the fediverse is full of mature, technical minded individuals. Glad to see memes are still the driving force of content.

  • All
  • Subscribed
  • Moderated
  • Favorites
  • random
  • lifeLocal
  • goranko
  • All magazines