News for hackers. Stuff that matters.
Re:Building an Inclusive Code Review Culture by aequitas on Monday July 30, 2018 @11:55AM (#17645363)
"If someone has committed many crimes against the style guide in a PR, the reviewer should point them to the style guide..."

Everything a computer can do trivially should not be done by humans. There are plenty of tools available to validate code to all the standards you can dream up. And most languages allow you to even automatically fix style errors or even enforce it for compilation (thank you Go).

So instead of codifying it in a style guide document, codify it in config files for linting and autoformat tools instead. The defaults of those tools are often fine for what you need and exceptions can as easily be documented in them as well.

Re:Building an Inclusive Code Review Culture by aequitas on Monday July 30, 2018 @02:18PM (#17646672)
Btw, an added bonus of having a automation friendly standard for your codebase is that is can be easily converted in something you prefer reading. Prefer brackets below the condition instead of at the end? With one standard to convert to/from you can write a simple script to do that using a Git filter so every time you commit/checkout the transformation is automatically applied (https://git-scm.com/book/en/v2/Customizing-Git-Git-Attribute...).

Also one example on how to codify almost any style is using something like Sonarqube SSLR (https://docs.sonarqube.org/display/DEV/SSLR) where the code is converted into an abstract representation where comprehensible rule can be written for (instead of for example a bunch of regexes). But you really have to be deep into wanting to enforce every aspect of a style to dive into this one.

Re:Building an Inclusive Code Review Culture by ISL on Monday July 30, 2018 @12:05PM (#17645462)
> Everything a computer can do trivially should not be done by humans.

Agreed, to a point. In many contexts, it is important for humans to do things themselves occasionally in order to learn how, even if a computer is generally used to do those things far more quickly.

Re:Building an Inclusive Code Review Culture by jelambs on Monday July 30, 2018 @12:17PM (#17645577)
Agreed, computers are generally way better than humans at catching many style issues. We utilize linters extensively, those enforce many of our style guide rules. However, there are some, such as the example pictured in the article, that aren’t always detectable with a linter. In these cases, we use the style guide as the source of truth to reduce the amount of personal preference that comes into code reviews.
Re:Building an Inclusive Code Review Culture by aequitas on Monday July 30, 2018 @12:43PM (#17645787)
Agree, for everything that doesn't go automatically or would be to much effort to automate a single source of truth must be maintained.
Re:Building an Inclusive Code Review Culture by aequitas on Monday July 30, 2018 @12:41PM (#17645777)
I agree with that if you would be learning a language. But even then, being bothered by indenting, alignment, spacing etc gets tiresome and the small amounts of time lost accumulate over the day.
Re:Building an Inclusive Code Review Culture by Coding_Cat on Monday July 30, 2018 @12:23PM (#17645625)
Not all languages have good linting/autoformatting support (although luckilt they're rarer these days). For example: R.
Re:Building an Inclusive Code Review Culture by zeckalpha on Monday July 30, 2018 @06:25PM (#17648711)
Re:Building an Inclusive Code Review Culture by Coding_Cat on Monday July 30, 2018 @07:11PM (#17649036)
We looked at it for our project, but it didn't work for us. Too little configuration & it made sections of code completely unreadable.

I miss clang-format...

Re:Building an Inclusive Code Review Culture by galkk on Tuesday July 31, 2018 @12:53AM (#17650630)
Google's internal Java formatter doesn't (didn't) have _any_ configuration. And, as I start to believe, it's good
Re:Building an Inclusive Code Review Culture by bluntfang on Monday July 30, 2018 @01:45PM (#17646395)
This is a discussion to be had before coding starts on a project. Do you care about style? If yes, choose a language that cares about style.
Re:Building an Inclusive Code Review Culture by com2kid on Monday July 30, 2018 @02:31PM (#17646776)
Not always possible if the requirements of the project dictate the language.
Re:Building an Inclusive Code Review Culture by wereHamster on Monday July 30, 2018 @04:56PM (#17647942)
Build that tool yourself if one doesn't exist yet. The whole community will thank you for it.
Re:Building an Inclusive Code Review Culture by ghostbrainalpha on Monday July 30, 2018 @01:06PM (#17646020)
Noobie question.....

Do you think there is any value in writing the code with the correct style before it is fixed in the compiler?

Like is it easier to help out and spot a problem quicker, if everyone is thinking in the exact same patterns when they write code?

Re:Building an Inclusive Code Review Culture by aequitas on Monday July 30, 2018 @02:05PM (#17646577)
Depends on the kind of style 'subject' I think. If it is trivial indentation, bracket placement and other preference kind of things it probably wouldn't. But if the style things lean more towards design patterns, then often there is a proper reason behind choosing that style over another and it would help because you would notice doing it the 'wrong' way and you stop to evaluate and maybe spot a bug or design issue. I think that would fall in the category of code smells like when you use a framework in a convoluted way you're probably not using the framework right or over stretching it.
Re:Building an Inclusive Code Review Culture by Jach on Monday July 30, 2018 @02:39PM (#17646847)
I'd second this. Depending on the style in question, there could be a mismatch in thinking, but probably not for most styles. If you're used to writing very dense C code for example, transforming it at the end to meet typical Enterprise Java standards might introduce subtle logic issues (or point out existing ones) or make it harder for you to understand in the future depending on how the transformation is done, but this is really just another instance of the general refactor caution to lean on tools, incremental changes that preserve key features like function signatures, and tests to make certain you don't change behavior.

Styles like forbidding single-statement if conditions that don't have curly braces helps protect you from bugs like goto-fail[0] meanwhile styles like which line your opening curly goes on, use of spacing, dare I say tabs vs spaces (outside of languages with significant whitespace anyway), and even abbrev names vs BigLongNames[1] don't really matter apart from personal preference and it being aesthetically pleasing to have local consistency.

[0] https://www.imperialviolet.org/2014/02/22/applebug.html

[1] https://www.hillelwayne.com/post/the-best-se-paper/

Re:Building an Inclusive Code Review Culture by btbuildem on Monday July 30, 2018 @01:33PM (#17646289)
If everyone is thinking in the exact same pattern, you will have terrible monoculture, and a total inability to get past certain kinds of problem.

An effective team is comprised of people with a variety of backgrounds and approaches.

Re:Building an Inclusive Code Review Culture by akerl_ on Monday July 30, 2018 @01:39PM (#17646332)
This is a very uncharitable interpretation of the parent comment.

The parent comment appears to be referring to having people keep the shared style guide in mind when writing code, vs just letting the linter fix it. Extrapolating this to suggesting they don't want a team "with a variety of backgrounds and approaches" drags the conversation pretty far afield of that question.

Re:Building an Inclusive Code Review Culture by arvinsim on Monday July 30, 2018 @10:24PM (#17650070)
All of my formatting issues disappeared when I adopted prettier for my Javascript projects.

I don't have to worry about bikeshedding/yak shaving anymore and now can focus on more important problems.

Re:Building an Inclusive Code Review Culture by mnarayan01 on Monday July 30, 2018 @12:50PM (#17645855)

  if a = foo()
versus:

  if (a = foo())
Sometimes idiomatic patterns vary based on things which are not amiable to mechanical correction.
Re:Building an Inclusive Code Review Culture by quxbar on Monday July 30, 2018 @12:58PM (#17645945)
The trick is to ban even the correct but (to a human) ambiguous patterns. In this case, I wouldn't let you do assignment on the same line as the conditional.
Re:Building an Inclusive Code Review Culture by squiggleblaz on Monday July 30, 2018 @09:34PM (#17649857)
With an `if` it's probably superfluous and therefore bannable without cost, but sometimes it can make a `while` loop so much more concise - since the alternative would be to write the same code before the loop and at the bottom of the loop. It is the cost of inexpressive languages.
Re:Building an Inclusive Code Review Culture by fipple on Monday July 30, 2018 @02:08PM (#17646596)
In what language do those produce different results?
Re:Building an Inclusive Code Review Culture by mattnewton on Monday July 30, 2018 @04:42PM (#17647839)
In many people’s head-parser, the first one looks like an equality check (but is in fact assignment). The parens try to clue people into “this is an assignment expression!” I think, but personally I wouldn’t allow an assignment expression in an if statement even with parens.
Re:Building an Inclusive Code Review Culture by munchbunny on Monday July 30, 2018 @12:54PM (#17645892)
While you have a point, I don't think the exception should disprove the rule. Even if a few specific style patterns can't be automated, the bulk can be and it's probably better to have them enforced at the pre-compile stage.