| When working in company, where more than a couple of people share the same code base, should we enforce a code style? Is it fair to ask someone to fix a style/comprehensibility issue like: change a variable name; prohibit lines longer than N chars, ... or should you just focus on the feature/behavior the code should implement/fix? What are you doing in your current job: - Do you have a well defined code style? Is it public? Where is it? - How do you enforce it? Comment on commits/ pull requests? - Are you automating style reviews? How? Are you using tools like JSCS, Scalastyle etc? Are you using services like Codacy? - How do you think a well defined code style is helping your code/work? |
Prohibit lines longer than N chars, again absolutely, many languages have standards like Pythons PEP8, I find 80 chars constricting sometimes but I stick to the standard because it is the standard (de-facto or not).
--
I stick to standards where they exist, for PHP thats the relevant PSR's, for Python, PEP8.
I enforce it by using the IDE to flag non-conformance and auto format either on the fly or on save, since I'm the only dev I don't need to enforce it on commits/pull requests.
Style Reviews are not applicable since there is just me (see above).
I think coding against the languages 'default' styles whether de-facto or imposed (I wish all languages had gone the gofmt route so we could obviate this problem nearly completely) helps, it certainly requires less context shifting when jumping from code I wrote to third party libraries in the same language.
In the past when I've worked with teams I've found having a defined standard helps hugely since it settles the inevitable bikeshedding arguments that crop up when programmer A wants to do foo and B do bar, often there is no clear winner so just picking one and adding it to the standard kills the argument dead the next time.
Personally I've always preferred :-
to but since PSR2 says not to do that I stopped (or more correctly I let the IDE handle it till it became habit to do it PSR style).