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

Prefer if expression #87

Closed
pjljvandelaar opened this issue Feb 9, 2023 · 2 comments
Closed

Prefer if expression #87

pjljvandelaar opened this issue Feb 9, 2023 · 2 comments
Assignees
Projects
Milestone

Comments

@pjljvandelaar
Copy link

Dear Developers,

There are many places where if expressions could be used.
I don't know whether you consider that an improvement in readability.
But I think that in orka/src/gl/implementation/gl-objects-textures.adb the following change

-      if Object.Compressed then
-         return Object.Create_View
-          (Kind      => Kind,
-           Format    => Object.Compressed_Format,
-           Min_Level => Object.Lowest_Mipmap_Level,
-           Levels    => Object.Mipmap_Levels,
-           Min_Layer => Layer,
-           Layers    => Get_Layers (Kind));
-      else
-         return Object.Create_View
-          (Kind      => Kind,
-           Format    => Object.Internal_Format,
-           Min_Level => Object.Lowest_Mipmap_Level,
-           Levels    => Object.Mipmap_Levels,
-           Min_Layer => Layer,
-           Layers    => Get_Layers (Kind));
-      end if;
+         return Object.Create_View
+          (Kind      => Kind,
+           Format    => (if Object.Compressed then Object.Compressed_Format else Object.Internal_Format),
+           Min_Level => Object.Lowest_Mipmap_Level,
+           Levels    => Object.Mipmap_Levels,
+           Min_Layer => Layer,
+           Layers    => Get_Layers (Kind));

improves readability.

See patch file for more inspiration of places where code might be simplified.
If_Expression.zip

Greetings,
Pierre

@onox onox self-assigned this Feb 11, 2023
@onox onox added this to To do in 1.0 via automation Feb 11, 2023
@onox onox added this to the 0.3 milestone Feb 11, 2023
@onox onox closed this as completed in ed9bd2a Feb 11, 2023
1.0 automation moved this from To do to Done Feb 11, 2023
@pjljvandelaar
Copy link
Author

I am missing the change in orka/src/gl/implementation/gl-objects-textures.adb as shown above.
Why don't you think it is an improvement?

@onox
Copy link
Owner

onox commented Feb 14, 2023

Because there are 2 definitions of Create_View, each specifying a different type (compressed or uncompressed). I find it (having 2 types) a bit ugly. Perhaps it would be better to use a subtype for the compressed textures, so that only 1 definition of Create_View is needed.

I agree that it's an improvement, but it doesn't compile unfortunately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
1.0
  
Done
Status: Done
Development

No branches or pull requests

2 participants