Re: New EEP draft: Pinning operator ^ in patterns

Attila Rajmund Nohl <[email protected]>
Newsgroups gmane.comp.lang.erlang.general
Message-ID <CAFkcMa9zeL_XAq0oXoNuodPFYXeRJthfPhDWA8Ht1axZCsZWEg@mail.gmail.com>
Kostis Sagonas <[email protected]> ezt írta (időpont: 2021. jan. 21., Cs, 1:10):
[...]
>    Should this warning pass be introduced?
>
> My view is YES.  This pass can certainly be useful to many developers
> and I also bet it will detect real bugs in existing code bases.  So YES
> with all capital.

Just today I almost wrote some code that could have triggered a
warning like this. During writing code, code is moved around (need to
extract some code into a function or just used as a template, etc.) -
if a value is represented by a certain variable name, I tend to use
the same variable name in other functions in the same module to ease
reasoning about. If code is moved around in the editor, there's a
chance that it ends up in a place where that variable is already
assigned. Actually I noticed that even before I saved the source file
as the function was small, but sometimes I do miss stuff like this. So
I'd really like this warning.

> But IMO, we do not need strange hieroglyphics (with ad hoc design, as I
> explained above) to shut off these warnings.  Plain `when` clauses with
> =:= tests suffice for this -- perhaps with the exception of pattern
> matching with variables used as lengths of bitstring segments where the
> compiler warning pass can simply be silenced / not check.

I also do agree with this. I understand that a "when Value =:= V"
might be too verbose, but it's explicit.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.