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

Wrap code at 120 characters #3

Open
cbeams opened this issue Mar 16, 2018 · 3 comments
Open

Wrap code at 120 characters #3

cbeams opened this issue Mar 16, 2018 · 3 comments

Comments

@cbeams
Copy link
Member

cbeams commented Mar 16, 2018

It is conventional to wrap lines of (Java) code at 120 characters. This is IDEA's default wrap margin, and (most importantly) it is the number of characters that can be displayed in GitHub's web UI without requiring horizontal scrolling.

Keeping lines of code to 120 characters or less therefore improves readability and reviewability. More generally, though, it is a code smell for lines of code to longer than this. It usually indicates that there is too much going on in a single statement and that things need to be broken up. Refactor code as necessary to eliminate the need to exceed 120 chars, or at the very least add line breaks to the code that help the reader parse and understand it more efficiently.

cbeams added a commit to bisq-network/bisq-core that referenced this issue Mar 16, 2018
cbeams added a commit to bisq-network/bisq-monitor-deprecated that referenced this issue Mar 16, 2018
Problem: bisq-network/style#3 indicates code should be wrapped at 120
characters, but it is likely that people will forget and that this habit
will only change slowly.

Solution: Configure IDEA to wrap lines automatically when typing past
120 characters, forcing the reminder to happen in real time. If this
becomes a nuisance, we can remove it later.

Note that this change also explicitly sets the RIGHT_MARGIN value to
120, even though this is already IDEA's default value. This is simply
to be explicit and self-documenting.
cbeams added a commit to bisq-network/bisq-common that referenced this issue Mar 16, 2018
Problem: bisq-network/style#3 indicates code should be wrapped at 120
characters, but it is likely that people will forget and that this habit
will only change slowly.

Solution: Configure IDEA to wrap lines automatically when typing past
120 characters, forcing the reminder to happen in real time. If this
becomes a nuisance, we can remove it later.

Note that this change also explicitly sets the RIGHT_MARGIN value to
120, even though this is already IDEA's default value. This is simply
to be explicit and self-documenting.
cbeams added a commit to bisq-network/bisq-statsnode that referenced this issue Mar 16, 2018
Problem: bisq-network/style#3 indicates code should be wrapped at 120
characters, but it is likely that people will forget and that this habit
will only change slowly.

Solution: Configure IDEA to wrap lines automatically when typing past
120 characters, forcing the reminder to happen in real time. If this
becomes a nuisance, we can remove it later.

Note that this change also explicitly sets the RIGHT_MARGIN value to
120, even though this is already IDEA's default value. This is simply
to be explicit and self-documenting.
cbeams added a commit to bisq-network/bisq-seednode that referenced this issue Mar 16, 2018
Problem: bisq-network/style#3 indicates code should be wrapped at 120
characters, but it is likely that people will forget and that this habit
will only change slowly.

Solution: Configure IDEA to wrap lines automatically when typing past
120 characters, forcing the reminder to happen in real time. If this
becomes a nuisance, we can remove it later.

Note that this change also explicitly sets the RIGHT_MARGIN value to
120, even though this is already IDEA's default value. This is simply
to be explicit and self-documenting.
cbeams added a commit to bisq-network/bisq-p2p that referenced this issue Mar 16, 2018
Problem: bisq-network/style#3 indicates code should be wrapped at 120
characters, but it is likely that people will forget and that this habit
will only change slowly.

Solution: Configure IDEA to wrap lines automatically when typing past
120 characters, forcing the reminder to happen in real time. If this
becomes a nuisance, we can remove it later.

Note that this change also explicitly sets the RIGHT_MARGIN value to
120, even though this is already IDEA's default value. This is simply
to be explicit and self-documenting.
cbeams added a commit to cbeams/bisq-pricenode that referenced this issue Mar 16, 2018
Problem: bisq-network/style#3 indicates code should be wrapped at 120
characters, but it is likely that people will forget and that this habit
will only change slowly.

Solution: Configure IDEA to wrap lines automatically when typing past
120 characters, forcing the reminder to happen in real time. If this
becomes a nuisance, we can remove it later.

Note that this change also explicitly sets the RIGHT_MARGIN value to
120, even though this is already IDEA's default value. This is simply
to be explicit and self-documenting.
cbeams added a commit to bisq-network/dao that referenced this issue Mar 16, 2018
Problem: bisq-network/style#3 indicates code should be wrapped at 120
characters, but it is likely that people will forget and that this habit
will only change slowly.

Solution: Configure IDEA to wrap lines automatically when typing past
120 characters, forcing the reminder to happen in real time. If this
becomes a nuisance, we can remove it later.

Note that this change also explicitly sets the RIGHT_MARGIN value to
120, even though this is already IDEA's default value. This is simply
to be explicit and self-documenting.
cbeams added a commit to bisq-network/bisq-core that referenced this issue Mar 16, 2018
Problem: bisq-network/style#3 indicates code should be wrapped at 120
characters, but it is likely that people will forget and that this habit
will only change slowly.

Solution: Configure IDEA to wrap lines automatically when typing past
120 characters, forcing the reminder to happen in real time. If this
becomes a nuisance, we can remove it later.

Note that this change also explicitly sets the RIGHT_MARGIN value to
120, even though this is already IDEA's default value. This is simply
to be explicit and self-documenting.
cbeams added a commit to bisq-network/bisq that referenced this issue Mar 16, 2018
Problem: bisq-network/style#3 indicates code should be wrapped at 120
characters, but it is likely that people will forget and that this habit
will only change slowly.

Solution: Configure IDEA to wrap lines automatically when typing past
120 characters, forcing the reminder to happen in real time. If this
becomes a nuisance, we can remove it later.

Note that this change also explicitly sets the RIGHT_MARGIN value to
120, even though this is already IDEA's default value. This is simply
to be explicit and self-documenting.
cbeams added a commit to bisq-network/bisq-core that referenced this issue Mar 20, 2018
cbeams added a commit to bisq-network/bisq-core that referenced this issue Mar 20, 2018
* wqking-master:
  Wrap code at 120 characters (bisq-network/style#3)
  List InstaCash (ICH)
@cbeams
Copy link
Member Author

cbeams commented Mar 22, 2018

@ManfredKarrer wrote at https://bisq.slack.com/archives/C91AM9JKV/p1521605566000003:

@cbeams is the 120 char wrap that important for you? it often breaks code to less readible layout. The IDE has also auto wrap, so devs with small screens can use that to get it wrapped.

i would prefer to keep it “soft” and make line breaks around the 120 mark but not enforce it if it hurts readibility
i use rather long names which might be a reason why that often happens, but i prefer clear descriptive names instead of shortened

I do find this pretty important, @ManfredKarrer, not in any one particular instance, but for the overall health of a codebase. I'm not sure whether you saw the original description above or not, but do check it out, the main points of my rationale are there.

There are, without a doubt, exceptions to the 120 rule, and that's why I would never introduce a "hard enforcement" of the rule, e.g. an automatic formatter that forces line breaks, or a something like checkstyle that would break the build on a violation.

The middle ground is to configure IDEA to automatically wrap lines at the 120 char margin as a kind of friendly reminder, and that's what I've done in the commits above. If, as a developer you have a good reason to extend past 120, then you can ignore that hint from IDEA and re-join onto a single line. But the point of this style guideline is that doing that really should be the exception. And this is probably where we need to get aligned. Having long lines by default is just very bad for readability and comprehension (by anyone other than the original author at the time they are writing that line), essentially for the same reasons that it's hard to read very long lines of prose: it's too much for the eye to scan and for the brain to parse all at once. It's not a question of long variable names--I too prefer "clear, descriptive names" that are not artificially shortened. In my experience, it is almost always possible to use correct, idiomatic variable names, type names, and generics while keeping a line to 120 characters or less, given that one is mindful of making each line of code do just one thing, not two or three or more. Extract explanatory private methods wherever it improves comprehensibility and reduces complexity, break naturally long single-purpose statements up into multiple lines as necessary, etc, and begin to think of lines that are going past 120 characters as a signal that a line of code isn't just "too long" merely for aesthetic reasons, but that it is "doing too much" to be easily understood, reviewed and maintained over time.

I hope this helps, and I'm happy to have further conversation about it as necessary. That's why, by the way, these style guidelines are modeled first here as GitHub issues--so that we can have discussions about them. Once it's clear that we have a consensus, and that contributors are actually adhering to them, we can codify them a bit more into a README in the root of this repository that becomes something like an official Bisq style guide. See #1 for more details on that process.

@ManfredKarrer
Copy link
Member

Here are my comments from the Slack conversation:
https://bisq.slack.com/archives/C91AM9JKV/p1521764260000204
https://bisq.slack.com/archives/C91AM9JKV/p1521767693000039
"Yes I agree to the not-do-too-much argument. I just found the automatic breaks from the IDE often un-natural and I need then to fix it manually, often keeping the 120 limit just break it differently so it is better readible. I would prefer to keep that as not-strict guideline but not use the IDE to do it but do it manually.

Just saw an example what I meant with bad breaks:
IDEA breaks it automatically to:
CoinSelection coinSelection = bsqCoinSelector.select(fee, wallet. calculateAllSpendCandidates());
I break it manually to:
CoinSelection coinSelection = bsqCoinSelector.select(fee, wallet.calculateAllSpendCandidates());
Another one:
Automatic:
checkArgument(mutableState.getBlindVoteStakeOutput() != null, “mutableState.” + “getVoteStakeOutput() must not be null”);

    Versus manual:       
   `checkArgument(mutableState.getBlindVoteStakeOutput() != null,
           “mutableState.getVoteStakeOutput() must not be null”);`

specially those string separations are annoying. they happen with i18n string often as they tend to be longer due name spaces"

cbeams added a commit to bisq-network/bisq-multirepo that referenced this issue Mar 23, 2018
cbeams added a commit to bisq-network/bisq-common that referenced this issue Mar 23, 2018
cbeams added a commit to bisq-network/bisq-monitor-deprecated that referenced this issue Mar 23, 2018
cbeams added a commit to bisq-network/bisq-core that referenced this issue Mar 23, 2018
cbeams added a commit to bisq-network/bisq-statsnode that referenced this issue Mar 23, 2018
cbeams added a commit to bisq-network/bisq-p2p that referenced this issue Mar 23, 2018
cbeams added a commit to cbeams/bisq-pricenode that referenced this issue Mar 23, 2018
cbeams added a commit to bisq-network/bisq-seednode that referenced this issue Mar 23, 2018
cbeams added a commit to bisq-network/bisq that referenced this issue Mar 23, 2018
@cbeams
Copy link
Member Author

cbeams commented Mar 23, 2018

@ManfredKarrer and I agreed to disable IDEA's automatic 'wrap on typing' feature at the 120 character margin because it was causing slowdowns and frustrations on his side. Wrapping at 120 isn't generally the problem, but rather IDEA forcing the wrap and causing re-work. Manfred would rather choose when and where to break manually, and that's fine.

cbeams added a commit to blabno/bisq-core that referenced this issue Apr 3, 2018
mrosseel pushed a commit to mrosseel/pricenode that referenced this issue Jun 12, 2018
Problem: bisq-network/style#3 indicates code should be wrapped at 120
characters, but it is likely that people will forget and that this habit
will only change slowly.

Solution: Configure IDEA to wrap lines automatically when typing past
120 characters, forcing the reminder to happen in real time. If this
becomes a nuisance, we can remove it later.

Note that this change also explicitly sets the RIGHT_MARGIN value to
120, even though this is already IDEA's default value. This is simply
to be explicit and self-documenting.
mrosseel pushed a commit to mrosseel/pricenode that referenced this issue Jun 12, 2018
cbeams added a commit to cd2357/bisq that referenced this issue May 11, 2020
 - Wrap comments at 90 chars per bisq-network/style#5
 - Wrap code at 120 chars per bisq-network/style#3
 - Remove unused imports
 - Remove extra newlines
 - Format code where appropriate
 - Remove unused Javadoc tags, e.g. @return, @param
 - End Javadoc summary sentence with a period where missing
 - Remove HTML formatting in Javadoc, e.g. extra <br>s
cbeams added a commit to cd2357/bisq that referenced this issue May 11, 2020
 - Wrap comments at 90 chars per bisq-network/style#5
 - Wrap code at 120 chars per bisq-network/style#3
 - Remove unused imports
 - Remove extra newlines
 - Format code where appropriate
 - Remove unused Javadoc tags, e.g. @return, @param
 - End Javadoc summary sentence with a period where missing
 - Remove HTML formatting in Javadoc, e.g. extra <br>s
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

No branches or pull requests

2 participants