This question is not so much technical than looking for advise to find the proper approach that will not hurt.
Assuming the following:
I thought about starting to format on subroutine level, but I do not find such feature in perltidy. There is another feature "Skipping Selected Sections of Code", but now I may want the opposite -- format only selected sections of code. The idea is that when a developer touches part of the code he/she will tidy only the modified part.
The best would be to find a way to format the whole project once without disrupting the development cycle and making sure we do not break any part of the code (during merging). We have unit tests, but some parts of the code may still be uncovered.
Let me also clarify that everybody in the team uses potentially different editor. For example I use Sublime Text 3 with SublimePerlTidy. Other people use Kate or Atom or VIM. A proper approach seem to be to format only pieces of code that we touch as pointed by @xxfelixxx (Thank you!)
- Define a coding standard and create a
.perltidyrc
to share with all of the developers.- Have tidying be one of the tasks that teams perform for their projects (along with testing and code review), so they tidy/test/review code they touch.
- Test the code very well. Tidying can introduce subtle bugs, so it is better in small manageable amounts (as opposed to just tidying the whole codebase, and wondering why things stopped working...)
- Tidy commits should be on their own, with no other changes, so that regressions can be tied to code changes or tidy changes respectively. git bisect is great for finding the offending commits.
As for my own perltidy usage, using emacs, I tend to tidy up small chunks of code at a time by highlighting a region ( creating a mark with C-space
, navigating to highlight a region, and then running M-p
which I have mapped to perltidy-region
. To get this to work, install perltidy
and add the following to your .emacs
file:
(defun perltidy-region ()
"Run perltidy on the current region."
(interactive)
(save-excursion
(shell-command-on-region (point) (mark) "perltidy -q" nil t)))
(defun perltidy-defun ()
"Run perltidy on the current defun."
(interactive)
(save-excursion (mark-defun)
(perltidy-region)))
(global-set-key "\M-p" 'perltidy-region)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With