[Info-vax] BASIC (and Horizon)
Lawrence D'Oliveiro
ldo at nz.invalid
Mon Feb 5 18:25:26 EST 2024
On Fri, 2 Feb 2024 07:56:33 -0500, Arne Vajhøj wrote:
> On 2/1/2024 11:51 PM, Lawrence D'Oliveiro wrote:
>> On Thu, 1 Feb 2024 22:44:56 -0500, Arne Vajhøj wrote:
>>> To quote from Linux kernel coding style doc:
>>>
>>> <quote>
>>> Now, some people will claim that having 8-character indentations makes
>>> the code move too far to the right, and makes it hard to read on a
>>> 80-character terminal screen. The answer to that is that if you need
>>> more than 3 levels of indentation, you’re screwed anyway, and should
>>> fix your program.
>>
>> I think this is a load of nonsense.
>
> Apparently Linus doesn't think so.
I know he doesn’t.
> And while few may have worded is this blunt, then it is generally
> accepted that deep nesting is a code smell and should be refactored and
> code moved out to functions/methods.
I do deep nesting all the time. This one goes 8 levels deep.
(defun prev_less_indent (count)
"moves to the last prior line with a lesser indentation level."
(interactive "p")
(loop break
(back-to-indentation)
(let
(
(indent_end (point))
indent_amt
line_start
)
(beginning-of-line)
(cond
((> indent_end (point))
(setq indent_amt (- indent_end (point) 1))
(unless
(loop done
(when (= (point) (point-min))
(ding)
(done nil)
) ; when
(previous-logical-line)
(beginning-of-line)
(setq line_start (point))
(end-of-line)
(when (/= line_start (point)) ; skip over empty lines
(back-to-indentation)
(setq indent_end (point))
(beginning-of-line)
(when (< (- indent_end (point)) indent_amt)
(done t)
) ; when
) ; when
) ; loop
(break)
) ; unless
)
(t ; on line with no leading whitespace
(ding)
(break)
)
) ; cond
) ; let
(setq count (- count 1))
(when (<= count 0)
(break)
) ; when
) ; loop
(back-to-indentation)
) ; prev_less_indent
Feel free to show us how it should be “refactored and code moved out
to functions/methods”.
More information about the Info-vax
mailing list