[erlang-questions] Best practices -- conditional statements
Ivan Uemlianin
ivan@REDACTED
Wed Feb 13 13:51:30 CET 2019
This might be cheating but I would avoid the branching altogether if
poss., eg:
PanPosition = CurrentPanPosition + notes_to_pad(Notes),
...
notes_to_pad(N) where N < 6 -> 8;
notes_to_pad(N) where N < 12 -> 4;
notes_to_pad(_) -> 2.
Also, I would avoid assignment inside a conditional, preferring eg:
PanPosition =
case Notes of
Few when Few < 6 -> CurrentPanPosition + 8;
...
Best wishes
Ivan
On 13/02/2019 12:40, Donald Steven wrote:
> The code excerpt below shows two alternate ways of branching. I'd be
> grateful for opinions on which represents best practices. Thanks.
>
>
> Don
>
>
> makePanPositionL(Notes, Mode, L),
>
> CurrentPanPosition = hd(L),
>
> case Mode of
>
> left2right ->
> if
> Notes < 6 -> PanPosition = CurrentPanPosition + 8;
> Notes < 12 -> PanPosition = CurrentPanPosition + 4;
> true -> PanPosition = CurrentPanPosition + 2
> end;
>
> left2right ->
> case Notes of
> Few when Few < 6 -> PanPosition = CurrentPanPosition
> + 8;
> More when More < 12 -> PanPosition =
> CurrentPanPosition + 4;
> _Lots -> PanPosition = CurrentPanPosition + 2
> end;
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
--
============================================================
Ivan A. Uemlianin PhD
Llaisdy
Ymchwil a Datblygu Technoleg Lleferydd
Speech Technology Research and Development
ivan@REDACTED
@llaisdy
llaisdy.wordpress.com
github.com/llaisdy
www.linkedin.com/in/ivanuemlianin
festina lente
============================================================
More information about the erlang-questions
mailing list