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

Use SWT constant and make the code more readable. #1755

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

deepika-u
Copy link
Contributor

@deepika-u deepika-u commented Jan 23, 2025

This commit refactors the classes in swt by using swt provided constant and makes the code more readable. Instead, the SWT.SPACE static constant is now leveraged for representing a string containing single character which is space in these classes.

@deepika-u deepika-u marked this pull request as draft January 23, 2025 10:19
Copy link
Contributor

github-actions bot commented Jan 23, 2025

Test Results

   494 files  ±0     494 suites  ±0   8m 48s ⏱️ -50s
 4 333 tests ±0   4 320 ✅ ±0   13 💤 ±0  0 ❌ ±0 
16 574 runs  ±0  16 466 ✅ ±0  108 💤 ±0  0 ❌ ±0 

Results for commit a57288a. ± Comparison against base commit 4a201e2.

♻️ This comment has been updated with latest results.

@deepika-u deepika-u force-pushed the Reuse_SPACE_and_improve_readability branch from 03b22e9 to c23fb47 Compare January 23, 2025 11:42
@deepika-u deepika-u marked this pull request as ready for review January 23, 2025 12:04
@deepika-u
Copy link
Contributor Author

@merks @HeikoKlare : can you review this please?

Copy link
Contributor

@HeikoKlare HeikoKlare left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure about this change, as for me several questions arise:

  • Is there a specific reason for doing this with SWT.SPACE and not every other character constant in SWT, like SWT.TAB and the like?
  • Why replace exactly these usages of ' ' and not the others within the SWT bundles?
  • Why is that reasonable/necessary now? Is there a specific trigger or did you come across this by accident? I am asking because the constant has been there for more than 10 years now.

To me, it looks as if those SWT constants are rather used for expressing key codes and not as constants for general ASCII characters. If we really want to use them for that, I would expect that we do that for every appearance of ' ' or that we have a common notion of where we use it and where we don't.

@deepika-u deepika-u force-pushed the Reuse_SPACE_and_improve_readability branch from c23fb47 to eb5bcfd Compare February 3, 2025 10:05
@deepika-u deepika-u force-pushed the Reuse_SPACE_and_improve_readability branch from eb5bcfd to a57288a Compare February 3, 2025 10:06
@merks
Copy link
Contributor

merks commented Feb 3, 2025

I don't think this makes the code more readable. It makes the code more verbose and hence even arguably less readable.

@deepika-u
Copy link
Contributor Author

deepika-u commented Feb 3, 2025

To me, it looks as if those SWT constants are rather used for expressing key codes and not as constants for general ASCII characters. If we really want to use them for that, I would expect that we do that for every appearance of ' ' or that we have a common notion of where we use it and where we don't.

Actually i totally agree to your view point. While checking on another issue, i got to check on the contents of the SWT.java file indetail so landed into this pr actually. While updating the instances of SPACE occurences only i got see '\t', '\n' characters are also being used. By the way i didnt find any contant for an empty string like ZERO_LENGTH_STRING or EMPTY_STRING, do you think we should add one?

  • At first place, i have did only for windows(x86_64) platform for which i missed 1 instance, i have added it now. But now i updated in other OS specific files as well wherever needed.
  • I was not sure on the impact(in terms of performance) of replacing space character by this constant in os calls(Text.java, Menu.java, Combo.java kind of files) so i have left them untouched.
  • Ofcourse i didnt update in commented(Text.java) sections of code.
  • When individual characters are mentioned like occurrences in JSON.java, WebBrowser.java - i havent intentionally changed those so that it is more sensible that way itself.

Ofcourse this is a cosmetic change and nothing else should change except the readability for a developer post this pr.

@deepika-u
Copy link
Contributor Author

deepika-u commented Feb 3, 2025

I don't think this makes the code more readable. It makes the code more verbose and hence even arguably less readable.

I am open to take this pr in any direction, thats individual perception in my opinion. But thanks for your opinion on this.

Copy link
Contributor

@laeubi laeubi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is appropriate here.

If I look at the javadoc it says:

ASCII character convenience constant for the space character

and comparing this with other like ESC and how it is used in the current codebase it becomes quite clear that this is for using in key events when the user has pressed the space-bar an not a general purpose constant to be used in programming code.

Taking this further, one soon need to replace the : or ; as well and literally each and every single character. I also don't think it improves readability, if I see a space I can easily read it as a space (ignoring the fact that there are different space characters like non breakable space and alike for now), also there is no risk that a space changes to something else and we want it to be the case very where (like with a string constant).

If one really want to improve readability, I see some places where a loop is used and instead one maybe want to use " ".repeat(n) instead.

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

Successfully merging this pull request may close these issues.

4 participants