Re: [ansible-project] Ternary filter vs conditional expressions

2018-04-13 Thread Rastislav Barlik
Thanks Brian,

If people find the filter useful then that's fair enough. Everybody has a
difference preference. I probably suffer from Python's "There should be one
-- and preferably only one -- obvious way to do it."


On Thu, Apr 12, 2018 at 9:25 PM, Brian Coca  wrote:

> Other people found it confusing and wanted something they could easily
> lookup up, like a filter.
>
> Once I added it, I stopped hearing complaints, so not sure how much
> that is worth other than anecdotal evidence.
>
> Use whichever way suits you best.
>
>
>
>
>
> --
> --
> Brian Coca
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Ansible Project" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/
> topic/ansible-project/mi8zuVlRR3g/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> ansible-project+unsubscr...@googlegroups.com.
> To post to this group, send email to ansible-project@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/ansible-project/CACVha7cA6WoFgc7jOBcvwzr6nhpyA
> _uhBO3GoVfw%3Df0ys9%2BvGw%40mail.gmail.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAPA8sOJ7d9Fg1bDzT3kZLB-Dg%2B4GdU1gpTC%3DngLUT9bOu8uuog%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] Ternary filter vs conditional expressions

2018-04-12 Thread Brian Coca
Other people found it confusing and wanted something they could easily
lookup up, like a filter.

Once I added it, I stopped hearing complaints, so not sure how much
that is worth other than anecdotal evidence.

Use whichever way suits you best.





-- 
--
Brian Coca

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CACVha7cA6WoFgc7jOBcvwzr6nhpyA_uhBO3GoVfw%3Df0ys9%2BvGw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] Ternary filter vs conditional expressions

2018-04-12 Thread rbarlik


On Wednesday, April 11, 2018 at 3:10:34 PM UTC+1, Brian Coca wrote:
>
>
> The `ternary` filter is easier for people that are not familiar with 
> Python, but non programmers and those used to ternary structures in 
> other languages. 
>
>
I'm used to the different ternary structures from different programming 
languages and I find it hard to believe that the ternary filter is easier 
for non programmers. Is there any evidence of it being the case?

The python style syntax reads more like English and you can immediately see 
the control flow.

On the other hand, the first time I've seen the ternary filter I had to 
look up how it works. Is the first argument for the false or for the true 
condition.
You don't have this problem with the other syntax.


-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/0d31cef3-a3a7-4c31-8018-6cc5f0c3d7c4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] Ternary filter vs conditional expressions

2018-04-11 Thread Brian Coca
Even though Ansible is written in Python, Python devs are not the main
target of the tool, so being 'pythonic' is not really an aim of it.

The `ternary` filter is easier for people that are not familiar with
Python, but non programmers and those used to ternary structures in
other languages.

-- 
--
Brian Coca

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CACVha7e7zDsPgtm8xrwKwZ9GQj808gqLMbx6kRo0b_o1DMG1gQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] Ternary filter vs conditional expressions

2018-04-11 Thread rbarlik


I've been recently wondering about the ternary filter in Ansible. I've seen 
it used in a couple of places and it's also mentioned in the documentation. 
As you probably know, it's not a standard Jinja filter but one created in 
Ansible code.


I would like to understand why was the ternary filter created and why is it 
preferred (Ansible docs doesn't even mention the alternative syntax) over 
the more pythonic way of using python style conditional expressions 
supported by the Jinja library.


# python style conditional expressions
- debug: msg="{{ variable if variable is defined else omit }}"
- debug: msg="{{ 'yes' if variable == 'inline' else 'no' }}"
 

# Using ternary filter
 - debug: msg="{{ variable | ternary(variable, omit) }}"
 - debug: msg="{{ (variable == 'inline') | ternary('yes', 'no') }}"


To me, the first example seems more readable and uses a syntax familiar to 
python developers.

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/1a6b745e-c97b-47f0-a284-92052f4ac3bb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.