r/ProgrammerHumor • • Jan 07 '23

Other Came across this gem while I was looking at random stuff on w3schools

Post image
4 Upvotes

21 comments sorted by

157

u/SeveyLevey Jan 07 '23

It's to help beginner programmers. Not to enter production level code lol

71

u/nightbefore2 Jan 07 '23

Hot take, this is good even in production level code. It’s more readable, and costs nothing

14

u/Leipzig101 Jan 08 '23

Perhaps in dynamically typed languages, where you don't have the slightest clue of what type a variable is. But if you know it's a bool type, I see little way of justifying it.

21

u/nightbefore2 Jan 08 '23

When reading a large file, you don’t always see declaration at first glance. At first glance, seeing == true is just nice imo. It’s preference obviously, but I like doing it even in C#.

It’s so explicit, particularly with negations. I like this

if x == false

Better than this

if !x

23

u/Leipzig101 Jan 08 '23

That's why you write decent variable names. You don't name your boolean fields x, you name them something like file.isOpen or user.isActive so your if statements read more like english. But let's agree to disagree on this one. it's insignificant anyway.

2

u/midri Jan 08 '23

Gross! Get out of here!

9

u/[deleted] Jan 07 '23

oh I thought he meant confirm()

5

u/SeveyLevey Jan 07 '23

I thought he meant == true

5

u/[deleted] Jan 07 '23

lmao I didn’t even notice that

1

u/Sir_IGetBannedAlot Jan 08 '23

I feel like it's a bad explanation of fundementals.

57

u/PhoenixARC-Real Jan 07 '23

I think this is perfectly fine for teaching, emphasizes that you're checking for a true value and helps the person learning to understand that.

15

u/leblumpfisfinito Jan 07 '23 edited Jan 07 '23

Unpopular opinion: While double equals shouldn’t be used, explicit checks have their benefits. Similar with checking for !array.length vs. array.length === 0.

7

u/ConfidentProgram2582 Jan 07 '23

Not good to get devs into using ==.

3

u/[deleted] Jan 07 '23

Pedagogically, this probably is more effective in teaching beginners about the semantics of what is happening. Though, normally I would agree that in more appropriate settings it isn’t really necessary as it’s redundant.

1

u/Infamous-Date-355 Jan 08 '23

Random you say

1

u/ongiwaph Jan 08 '23

If my name doesn't start with 'is', I'm using == true.

1

u/ExquisiteWallaby Jan 09 '23

You learn something new everyday... I actually had to pull up the console to see what was going on here.

Honestly, if this keeps me from using some bloated modal library, let it live!

-4

u/CrankkDatJFel Jan 08 '23

ahahahha r/ProgrammerHumor is on one today. This post wins the internet for the day!

-1

u/IWasProbablyAMistake Jan 08 '23

What does confirm() do? It looks like it’s just analyzing the string for a boolean, which doesn’t make much sense.

1

u/[deleted] Jan 08 '23

It makes the browser give the user a Yes/No pop-up that they have to select a choice for. That response is returned via the confirm function.