this post was submitted on 16 Jan 2024
547 points (98.8% liked)

Programmer Humor

19522 readers
289 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 1 year ago
MODERATORS
 
all 33 comments
sorted by: hot top controversial new old
[–] kubica@kbin.social 99 points 9 months ago (6 children)

Put it in an if-else and it executes both blocks.

[–] steersman2484@sh.itjust.works 36 points 9 months ago

But only if you don't look

[–] bananaw@sh.itjust.works 34 points 9 months ago* (last edited 9 months ago) (1 children)
[–] Klear@lemmy.world 3 points 9 months ago
[–] theneverfox@pawb.social 14 points 9 months ago (1 children)

Fun fact I learned today - you know how when there's a compound conditional, the interpreter stops once the result is known? (Eg, if the left side of an and is false, it's false so it doesn't bother checking the second condition)

Apparently, visual basic doesn't do this thing every other language I know of does... It might be a debug only thing for the convenience of the depreciated ide I'm forced to use, but I did a null check && called a function on it if it's not null, and it blew up

I pride myself on my ability to change to a new programming language and make progress on day one, but vb is truly the most disgusting POS language I've ever seen. From syntax to jarring inconsistencies in language design, it's just gross

[–] noli@programming.dev 2 points 9 months ago (1 children)
  1. That's behaviour that's just part of language design. If you rely on it you should probably check how the language you're using handles it.

  2. relying on that behaviour sounds a lot like "clever" (read unnecessarily unreadable) code

[–] theneverfox@pawb.social 1 points 9 months ago (1 children)

Are you serious? It's one of the most basic and common if statements that exist.

If( foo != null && foo.isBar() )

That's what we're talking about. Looking before you leap.

I take issue with the whole "too clever" argument fundamentally (for a number of reasons), but this isn't some fancy quality of life feature. This is as simple as it gets

[–] noli@programming.dev 1 points 9 months ago (1 children)
[–] theneverfox@pawb.social 1 points 9 months ago (1 children)

Scroll on down to the first common example there champ.

If you really think that's being "too clever" I don't know what to tell you... A big reason I think that argument is bullshit is because writing simple code isn't a goal (what does that even mean?) - readability is a big one, and breaking up every part of every conditional would just lead to unreadable spaghetti

Also, take a look at the languages being discussed. This is a long settled question - every language I've ever used has this.

Including VB, I found out it uses AndAlso...so gross

[–] noli@programming.dev 1 points 9 months ago* (last edited 9 months ago) (1 children)
  1. several languages that are still in use have eager evaluation.

  2. I'm a dumb programmer. The more I need to keep implicit behaviour in mind, the higher the probability I'm writing bugs. Short circuit evaluation is an optimization technique IMO and shouldn't be relied upon for control flow.

  3. The aggressive tone you're using is completely unnecessary and immature, so I'll refrain from responding any further. Have a nice day.

[–] theneverfox@pawb.social 1 points 9 months ago

You're the one who started this by criticizing my knowledge and my coding practices, in response to me sharing one very specific example of why I believe VB is a bad language

I held off because I thought you must've misread it and we'd laugh and maybe talk about language design... But no, you confirmed you just came at me with a bad take extremely dismissively

If you want respect, try showing it.

[–] madkarlsson@beehaw.org 9 points 9 months ago

Here is one of the programmers who is quantum ready as well

[–] datelmd5sum@lemmy.world 2 points 9 months ago

doesn't the CPU already do this?

[–] Omega_Haxors@lemmy.ml 0 points 9 months ago* (last edited 9 months ago) (2 children)

Screw else statements, people who use if-return have 180% more readable code.

[–] SpeakinTelnet@programming.dev 5 points 9 months ago (1 children)

Because everyone knows a function stops at the if-else. Nothing ever happens afterward.

[–] Octopus1348@lemy.lol 3 points 9 months ago

It's much more readable when you use else depending on the checks. You can still use return in an else block.

def Allowed()

  if name == "Octopus1348": return True

  elif name == "Bobert": return True

  else:
        return "You are not allowed to use this script."

print(Allowed())

`

[–] shotgun_crab@lemmy.world 45 points 9 months ago* (last edited 9 months ago) (1 children)
[–] mrkite@programming.dev 29 points 9 months ago (1 children)

Known to cause heisenbugs. They're bugs that disappear when you try to measure them with a debugger or a printf.

[–] jaybone@lemmy.world 16 points 9 months ago

So regular bugs then.

[–] docAvid@midwest.social 30 points 9 months ago (2 children)

Weird. Booleanish isn't a built-in, I'm pretty sure. I'd like to see the definition.

[–] madkarlsson@beehaw.org 16 points 9 months ago

This looks like javascript so let me guess the typescript definition

any|unknown

this is a joke, please chill

[–] Drama_durch_Lama@feddit.de 25 points 9 months ago (1 children)

That gave me an idea: A variable that is only defined when observed by a debugger, otherwise it's null.

[–] Flipper@feddit.de 9 points 9 months ago

How about an instruction that jumps only when a debugger is attached? Cause that exists.

[–] UnRelatedBurner@sh.itjust.works 4 points 9 months ago
[–] CanadaPlus@futurology.today 4 points 9 months ago

Call me when defining it a second time makes it guaranteed false again.