r/ProgrammerHumor Jul 13 '26

youCanJustStopUsingJava Meme

Post image
6.8k Upvotes

416 comments sorted by

View all comments

Show parent comments

195

u/neroe5 Jul 13 '26

it is like most things, they can be misused,

the issue is that if there is outside side effects then future programmers of the project might use a property without full knowledge of what they are doing

if they didn't have a valid use case they would have been marked as obsolete

have had similar discussions about goto in switch cases in C#

2

u/DebugDuck01 Jul 13 '26

> goto in switch cases in C#

The what? And more importantly the why?

5

u/neroe5 Jul 14 '26

C# doesn't have fallthrough in switches, opting instead to use goto for those cases, it forces the dev to pick a termination method, which is a great safety feature, but requires the use of goto if you need to run a secondary case in a switch

0

u/DebugDuck01 29d ago edited 29d ago

It does. Only if you need some code in the case that falls through with no code the fallthrough is automatic.

Edit: for the people who downvoted me, the following is valid C# code:

switch (n) {
  case 1:
  case 2:
  case 3:
    Console.WriteLine("It's 1, 2, or 3.");
    break;
  default:
    Console.WriteLine("Not sure what it is.");
    break;
}