3 ms·
> 2) When you copy-paste Perl (or C, or Java, etc) code, do you not reformat that code anyways? Yes, with Perl::Tidy and one keyboard shortcut bound to it. Wit
by pronik 13y ago
> 2) When you copy-paste Perl (or C, or Java, etc) code, do you not reformat that code anyways?
Yes, with Perl::Tidy and one keyboard shortcut bound to it. With Python I have to manually and very carefully block-indent the pasted fragment and then figure out how it fits into existing code. Even if there were a proper Python code formatter (hint: there isn't anything even close in functionality to Perl::Tidy) it wouldn't be able to figure out the code, since whitespace is significant. No such thing in Perl -- paste, tidy, rinse and repeat.
- collyw 13y agoYes, you have to think a bit more when reformatting Python, but it is worth it as you never get the missing brace problem that you can get when moving Perl blocks around. Its enough of a benefit for me.
- pronik 13y agoThe point is: I don't have to think at all. Reformatting code with Perl is a matter of a save hook in the editor or a pre-commit hook in your VCS. No thinking necessary, it just works.
- ptx 13y ago> Yes, with Perl::Tidy and one keyboard shortcut bound to it. With Python I have to manually and very carefully block-indent the pasted fragment and then figure out how it fits into existing code. No need to do it carefully or manually. The indentation within the fragment will be internally consistent, as will the indentation in the existing code you're pasting it into. So you just have to figure out the difference in indentation level between the two and use whatever keyboard command your editor has (e.g. C-c < and C-c > in Emacs) to shift the whole fragment. > Even if there were a proper Python code formatter (hint: there isn't anything even close in functionality to Perl::Tidy) it wouldn't be able to figure out the code, since whitespace is significant. No such thing in Perl -- paste, tidy, rinse and repeat. Right, but in Python there is no such thing as reformatting. The information about the structure is already encoded in the indentation, so it's neither possible nor necessary to reconstruct it from other formatting characters. In other words, whereas in Perl and C-like languages you would 1) edit the braces so that they're correct and then 2) automatically reconstruct the indentation to match the braces, in Python you simply 1) edit the indentation so that it's correct.