You are viewing a single thread.
View all comments
98 points

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

permalink
report
reply
36 points

But only if you don’t look

permalink
report
parent
reply
34 points
*

- if else

+ if and else

permalink
report
parent
reply
3 points

if or else

permalink
report
parent
reply
14 points

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

permalink
report
parent
reply
2 points
  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

permalink
report
parent
reply
1 point

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

permalink
report
parent
reply
9 points

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

permalink
report
parent
reply
2 points

doesn’t the CPU already do this?

permalink
report
parent
reply
0 points
*

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

permalink
report
parent
reply
5 points

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

permalink
report
parent
reply
-7 points
*

You’re writing extremely bad code if that’s the case and you need to refactor. The point of a function is to return a value. Anything else is just there to waste cycles and make the code less readable. You should also never use else statements for arithmetic due to their massive relative overhead. Your processor can do multiple arithmetic operations in the time it takes to process one if statement, and don’t get me started on people who demand you use nested if even though switch statements are way faster and leagues more readable.

permalink
report
parent
reply
3 points

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())

`

permalink
report
parent
reply

Programmer Humor

!programmer_humor@programming.dev

Create post

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

  • Keep content in english
  • No advertisements
  • Posts must be related to programming or programmer topics

Community stats

  • 3.4K

    Monthly active users

  • 1K

    Posts

  • 38K

    Comments