Re^5: How would you indent this?
by GrandFather (Saint) on Mar 18, 2021 at 20:24 UTC
|
Problem in this thread is that the OP is effectively asking multiple questions:
- how should this be best written
- how should my editor do it
- what's the bug in my editor
- They way I write it of course!
- The way I would write it if I were taking appropriate care
- Is it that it is emacs?
The are many very bad indentation and white space usage styles in use. Aside from a desire for consistency and style informed by "that is the way we always do it", I don't think many people think very much about their code writing style. My own style decisions, which I have thought about, are driven by laziness. I use white space, to the extent reasonably possible, consistently with the conventional usage in (English) written prose. That way I already have a parsing tool (my brain) that knows how to break stuff up without needing different settings packages for prose and code.
Other style decisions are made based on intelligibility, such as keeping lines short with the important stuff toward the front, minimizing nesting, keeping functions reasonably short, and so on. Look at pretty much any of my code on PerlMonks to see how that looks. Note though that my block delimiting brace usage for Perl is K&R which I avoid in other languages (I prefer Whitesmiths).
Optimising for fewest key strokes only makes sense transmitting to Pluto or beyond
| [reply] |
|
|
> Is it that it is emacs?
The OP is using a function which is not standard indenting, hitting TAB is.°
This function offers plenty of interactive real-time benefits, without needing to wait 2 sec till a Perl::Tidy background process returned.
Komodo has nothing like this to offer.
And contrary to you I know both editors pretty well.
So please cut the FUD out.
> The way I would write it if I were taking appropriate care
That's BS, no software can decide what the best choice is, it can only assist at best.
See AnoMonks demo here: Re: How would you indent this? Which identation style do you prefer?
The editor shouldn't interfere automatically in the formatting after the author has chosen a representation.
°) or activating auto-indent, which seems to be default now.
| [reply] |
|
|
> Is it that it is emacs?
The OP is using a function which is not standard indenting, hitting TAB is.°
That's an oversimplification.
- <TAB> is equivalent to M-x cperl-indent-line if (as per default) tab-always-indent is set to a true value. It indents the current line.
- M-x cperl-indent-exp indents the current expression and reformats if (as per default) cperl-indent-region-fix-constructs is set to 1.
- M-x cperl-indent-region indents the current region and reformats if (as per default) cperl-indent-region-fix-constructs is set to 1.
- <RET> is, per default, equivalent to M-x newline which, also per default, indents the current and the new (empty) line.
None of these functions are more standard than the others, and with the current settings there's rarely the need to use <TAB> at all.
°) or activating auto-indent, which seems to be default now.
That's electric-indent-mode, which isn't actually overdocumented right now. One of the consequences of this mode is that the PBP recommendation to remap <RET> to M-x newline-and-indent is outdated and should no longer be used. Also, in Python buffers, where indentation can't be inferred from braces and such, Electric Indent mode is switched off.
| [reply] |
|
|
|
|
|
|
I agree that the "editor shouldn't interfere automatically". One of the worst editors I ever worked with was the UCSD Pascal system which forced its own idea of indentation live while editing, including disallowing multi-line comments. I run perltidy occasionally to clean up after things like a big code refactor, and I pretty much always use it to clean up code from PerlMonks questions.
The impressive thing about perltidy is that I have tuned it to produce almost exactly what I write most of the time. Some of the modern C++ pretty printer type tools are pretty good too. Modern Visual Studio can do a pretty good job and the C++ Code Style Formatter provided by Eclipse is very configurable aside from some weird omissions (why does it insist on a space before a : in a constructor declerator list?). So yes, pretty printing tools can get extremely close to making the same code style decisions I do, partly because I have thought hard about my style choices and understand what I want to achieve, so results are consistent and fairly easy to codify.
I apologize for the perceived attack on emacs. Never fear, I treat vi equally. :-D
Optimising for fewest key strokes only makes sense transmitting to Pluto or beyond
| [reply] |
|
|
|
|
|
|
|
Quoth Rolf:
The OP is using a function which is not standard indenting, hitting TAB is.°
I quite categorically am using the standard indenting of cperl-mode. Copy the original example into a file called, say "test.pl", then edit with emacs -Q test.pl, and take the following sequence of instructions:
M-X cperl-mode
C-SPC
M->
M-C-\
gives me (copy-pasting from Emacs window):
my @headings = (
{
key => 'k', name => 'Kanji', class => 'kanji'},
{
key => 'skip', name => 'SKIP', class => 'skip-code'},
{
key => 'co', name => 'Suggestion', class => 'skip-code'},
{
key => 'disc', name => 'Discussion'},
);
The version of Emacs I am using is as follows:
GNU Emacs 27.1 (build 1, i386-portbld-freebsd12.1, GTK+ Version 3.24.2
+4, cairo version 1.16.0)
Copyright (C) 2020 Free Software Foundation, Inc.
The cperl-mode is the default supplied with the above.
| [reply] [d/l] [select] |
|
|
|
|
|
|
|
|
Re^5: How would you indent this?
by ikegami (Patriarch) on Mar 19, 2021 at 13:32 UTC
|
Everything else needs intelligent heuristics to determine if the data has a repeated structure requiring another presentation
Well, yeah. In case you missed the implication, some styles are better than others in certain situations, and you should use the appropriate style to the situation.
Style is about readability, not slavishly following some preset rules.
Seeking work! You can reach me at ikegami@adaelis.com
| [reply] |
|
|
> Style is about readability,
I agree with you about the best representation of this particular set of data.
> not slavishly following some preset rules.
And I said more than once that the editor shouldn't change the authors decision but assist when wanted.
I'm just skeptical there is a Perl tool yet, which auto-detects tabular structure with empty cells and represents it accordingly.
I could think of ways to implement this, and would be thankful to hear about tools which do it already.
All discussed tools so far are either not changing key order or sorting alphabetically.
| [reply] |
|
|
| [reply] |