Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change do {} while(true) to while(true) {} #167

Closed
GraxCode opened this issue May 13, 2020 · 11 comments
Closed

Change do {} while(true) to while(true) {} #167

GraxCode opened this issue May 13, 2020 · 11 comments

Comments

@GraxCode
Copy link
Contributor

These loops in CFR output

do {
...
} while(true);

should be changed to

while(true) {
...
} 

A do while loop insists that the condition is at the end and when I encounter a loop the first thing I want to know is what the condition is. Thus, I am forced to look for the end of the code block of the loop just to find out it is an infinite loop. In conclusion, changing those loops to while loops will improve readability.

@leibnitz27
Copy link
Owner

leibnitz27 commented May 15, 2020

You know, I was going to die on this hill ;) (especially because it's subjective)

Alas, I put this to a straw poll of 1000 java devs ( closed audience ) and lost 14:1 (with one person demanding for(;;) )

So, fair enough.

But out of sheer (1/schadenfreude) I'll close #17 . Because THAT HILL IS MINE TO DIE ON. ;)

@Lanchon
Copy link

Lanchon commented May 15, 2020

lol noooo, THAT guy is right, for (;;) is the idiomatic way!

(seriously, i do that; it's less verbose and there is no condition to look at.)

@Lanchon
Copy link

Lanchon commented May 15, 2020

but i do agree on do {} while (true) being the least desirable form.

@GraxCode
Copy link
Contributor Author

hehe - I mean you could still make an interface that lets somebody use their own formatting standards (please don't)

@GraxCode
Copy link
Contributor Author

lol noooo, THAT guy is right, for (;;) is the idiomatic way!

(seriously, i do that; it's less verbose and there is no condition to look at.)

Oh hell no, it doesn't look aesthetic and an amateur wouldn't understand it imo

@Col-E
Copy link
Contributor

Col-E commented May 16, 2020

lol noooo, THAT guy is right, for (;;) is the idiomatic way!

I got a better one 😉

label-begin: {
    // code here
    goto label-begin
}

@GraxCode
Copy link
Contributor Author

lol noooo, THAT guy is right, for (;;) is the idiomatic way!

I got a better one

label-begin: {
    // code here
    goto label-begin
}

Looks like krakatau

@Lanchon
Copy link

Lanchon commented May 16, 2020

its inevitable, CFR will have to be hostile-forked now

@leibnitz27
Copy link
Owner

I got a better one 😉

label-begin: {
    // code here
    goto label-begin
}

FWIW this is why I prefer the while(true) ;) - it's clearly a goto at the end of the block.

@GraxCode
Copy link
Contributor Author

I got a better one wink

label-begin: {
    // code here
    goto label-begin
}

FWIW this is why I prefer the while(true) ;) - it's clearly a goto at the end of the block.

If you'd make a statistic of what is used most, while(true) {} will probably win by far. Also oracle docs specify while(true) {} as infinite loop: https://docs.oracle.com/javase/tutorial/java/nutsandbolts/while.html

@leibnitz27
Copy link
Owner

hehe - I mean you could still make an interface that lets somebody use their own formatting standards (please don't)

FWIW - I already mentioned this in #17 - If someone wants to bolt a code-style plugin on afterwards, feel free, but that's definitely not a reasonable thing to incorporate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants