-
Notifications
You must be signed in to change notification settings - Fork 769
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
Philosophy of generated code #177
Comments
I agree with the approach you propose here. Until now the generated code only followed principles like:
But nothing on readability or clarity, I feel it's nice to follow your proposal. One question/concern I have is that this will result in not using the R.swift.Library methods, but "plain" Swift code instead. This makes the library methods harder to discover (minor issue) and will mean that fixing an issue in the library, like this one fixing incorrect use of What do you think? |
Yes, writing "plain Swift" is a bit more cumbersome than using the functions from R.swift.Library. This is of course the whole reason why these convenience initializers were created! 😄 However, I think the benefit of readability for the hundreds (tens? thousands?) of users reading the code, outweighs the (slight) cost of writing the code for maintainers of R.swift. In my opinion the price is worth it. |
Also, whatever the final result of chosen principles is: These should be written down in a document somewhere, so that future R.swift contributors can refer to these. |
Agreed, let's from here on go for clarity. I think we should create a |
I think these are very interesting points. There is one thing that I am unclear about regarding how the first proposed principle would be carried out in practice. Would you say that "Don't generate as short code as possible." is equivalent to something like "Use native calls where ever possible." or "Don't have deeply nested layers of function calls for something that could be written in a single function clearly."? My concern is that there is an unclear line between brevity and clarity and if your are doing something complex over and over again, it might be more clear to throw that logic in a well names (well commented) function rather than repeat the logic in all places it's needed. Unfortunately, this line is obviously not well defined, so in order to enforce a rule like this, we might just have to draw a hard line somewhere, whether that be something like I mentioned above or something new. After thinking about it, for the Localizable.strings implementation, I was originally planning on putting the
|
Perhaps another way to describe this would be: few (or zero?) indirections Your example is great! To quote Spock: |
I'm all for this new style. At the moment having multiple items in auto complete, one with |
This is a discussion, rather than a bug or feature request.
I think we should try to generate "readable" code (defined later on).
In principle, users shouldn't have to look at the generated code.
R.*
can be used through autocomplete.However, in my opion there are two types of people who do read the generated code:
R.image.someImage
. A user might want to look "under the hood".For these two use cases, readability of code is very important. So as not to scare someone off.
In particular, I think the following should be non-goals:
For example, instead of generating this code:
This more straightforward code should be generated instead:
The first piece of code, using the
UINib(resource:)
initializer uses 2 or 3 indirections.When trying to figure out how R.swift works, or what code is actually run, the second piece of code is simpler.
The text was updated successfully, but these errors were encountered: