You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As of Java 24, there are 5 kinds of switches namely, "Classic" integer selector switches, enum switches, string switches, type switches with patterns and primitive switches.
Code generation for each of these involves some abstractable steps such as (a) Prologue (all preparatory steps including and upto the case selection) (b) Code generation for the switch block (c) generation of injected default case - where applicable (d) epilogue - any and all actions to wrap up.
ATM, there is no clear design that is worth speaking of - there is some faint half/quarter hearted attempt at differentiating prologues, but this is inconsistently followed through, resulting in two big "blobs" of code - one for switching on strings and one for all other switches.
There is no attempt at code reuse - see the duplication between org.eclipse.jdt.internal.compiler.ast.SwitchStatement.generateCodeForStringSwitch(BlockScope, CodeStream) and org.eclipse.jdt.internal.compiler.ast.SwitchStatement.generateCode(BlockScope, CodeStream) - bottom half of each could be extracted as common code.
There is also no clear separation of concerns - resulting in spaghetti style intertwining of disparate concerns.
We can certainly do better by retrofitting some design that would promote readability, code organization and reuse.
The text was updated successfully, but these errors were encountered:
As of Java 24, there are 5 kinds of switches namely, "Classic" integer selector switches, enum switches, string switches, type switches with patterns and primitive switches.
Code generation for each of these involves some abstractable steps such as (a) Prologue (all preparatory steps including and upto the case selection) (b) Code generation for the switch block (c) generation of injected default case - where applicable (d) epilogue - any and all actions to wrap up.
ATM, there is no clear design that is worth speaking of - there is some faint half/quarter hearted attempt at differentiating prologues, but this is inconsistently followed through, resulting in two big "blobs" of code - one for switching on strings and one for all other switches.
There is no attempt at code reuse - see the duplication between
org.eclipse.jdt.internal.compiler.ast.SwitchStatement.generateCodeForStringSwitch(BlockScope, CodeStream)
andorg.eclipse.jdt.internal.compiler.ast.SwitchStatement.generateCode(BlockScope, CodeStream)
- bottom half of each could be extracted as common code.There is also no clear separation of concerns - resulting in spaghetti style intertwining of disparate concerns.
We can certainly do better by retrofitting some design that would promote readability, code organization and reuse.
The text was updated successfully, but these errors were encountered: