Lrrr
Lrrr

Reputation: 4807

Is label in java make spaghetti code?

I've just read about spaghetti code ( wiki link) that "goto" statement creates, I wonder if label in java makes spaghetti code?

I just interested in this because one of my old question about break and label in java that I asked here

Upvotes: 0

Views: 304

Answers (2)

Peter Lawrey
Peter Lawrey

Reputation: 533530

The main problem with labels is that they are rarely used which means they are surprising and possibly confusing for a reader. e.g

http://stackoverflow.com/
System.out.println("Hello SO");

At first glance, that doesn't even look like valid Java code, but it is.

Because labels tend to be used only when the are really needed, and sometime not used when they should have been used IMHO, they don't lead to spaghetti code in Java in reality.

Upvotes: 2

Kayaman
Kayaman

Reputation: 73558

Labels are so rarely needed/used that no, not really. Also you can't jump to a label, you need to break to it, so you can't get the similar kind of confusion as with filling the code with goto whereever statements.

Upvotes: 3

Related Questions