-
Notifications
You must be signed in to change notification settings - Fork 149
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
base: master
Are you sure you want to change the base?
Use SWT constant and make the code more readable. #1755
Conversation
03b22e9
to
c23fb47
Compare
@merks @HeikoKlare : can you review this please? |
There was a problem hiding this 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, likeSWT.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.
c23fb47
to
eb5bcfd
Compare
eb5bcfd
to
a57288a
Compare
I don't think this makes the code more readable. It makes the code more verbose and hence even arguably less readable. |
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?
Ofcourse this is a cosmetic change and nothing else should change except the readability for a developer post this pr. |
I am open to take this pr in any direction, thats individual perception in my opinion. But thanks for your opinion on this. |
There was a problem hiding this 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.
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.