&(&1) ...  sigh. In the project where I work I generally argue against 
these constructs because it really reduces readability. There's a limit of 
special character the brain can process correctly in a row. (My personal 
opinion, though.)

In general, two constructs are more common in our code:

if ... do .. else .. end # inline in any other expression
... && .. || ... # the favorite of some of my colleagues

I still limit the use of the latter one simply because it quickly gets out 
of hand, but for filling a field in a struct with simple values it can be 
really useful.

Best regards,
Oliver

On Saturday, January 27, 2024 at 7:08:20 PM UTC+1 gva...@gmail.com wrote:

> On Jan 26, 2024, at 10:52 PM, Robert Viragh <rvi...@gmail.com> wrote:
> > 
> > As a user of Elixir, it seems to me that I can write ternary expressions 
> in Elixir by treating the if statement as an expression and it remains 
> highly readable.
>
> You are so close to being correct here. You're not "treating" a statement 
> as an expression. Elixir has no if statement. It only has an if expression. 
> This is by design and is common among functional languages.
>
> It just so happens that Elixir is the first language where you have 
> encountered it. It's great to see you have a "lightbulb moment" when a new 
> concept fits together in your mind. Google for terms such as "expression 
> based language" for more details.
>
> That being said, yes, this insight offers you a deeper way of looking at 
> conditional logic in Elixir. However, a ternary operator is distinct, as 
> José pointed out, because it is an operator.
>
> -Greg Vaughn

-- 
You received this message because you are subscribed to the Google Groups 
"elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elixir-lang-core+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elixir-lang-core/23fb0cef-6de6-4116-93c9-88835035d2d2n%40googlegroups.com.

Reply via email to