Consider warning on using True/False instead of true/false

111 views
Skip to first unread message

miwee

unread,
Aug 13, 2016, 9:52:54 AM8/13/16
to elixir-lang-core
I recently got bitten by this. I used True/False, thinking them as boolean values true/false. Got no warning, but code failed. Partly reason is that I was recently alternating between python and Elixir code base. Python uses True/False. May be a gentle reminder from elixir compiler, on usage of True/False could have saved me from this.

thanks
miwee

José Valim

unread,
Aug 13, 2016, 2:58:56 PM8/13/16
to elixir-l...@googlegroups.com
I am at first positive on this change. There is at least two mainstream languages that use True and False: Haskell and Python. Although I am not sure the warning will be really helpful at large, I don't think we would lose anything as it is quite unlikely someone has a module named True (or False). So it seems like a net benefit.

What are other people thoughts?
--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/df1d6c68-6303-41f3-83d8-1dc4b1ed2121%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Andrea Leopardi

unread,
Aug 13, 2016, 5:26:15 PM8/13/16
to elixir-l...@googlegroups.com
As I mentioned in IRC, I think this is a slippery slope. We never mention True/False in the docs and Erlang does not have them; if the warning would be specifically for Haskell and Python programmers, than we should ask ourselves, should we try to warn on everything in Elixir that looks like something in another language? For example, when I go back and forth between Elixir and Ruby, I put the do in def in Ruby, and I imagine many people coming from Ruby will forget the do in def when using Elixir: should we warn on such cases? This may not be the best example given that the warning on True/False is quite straightforward and non-intrusive to implement while warning on missing do would require changes to the parser and so on, but I hope it conveys the idea.



Andrea Leopardi

Parker Selbert

unread,
Aug 13, 2016, 6:54:27 PM8/13/16
to elixir-l...@googlegroups.com
To me it seems like the Python shell inconvenience of "did you mean quit" when you type exit (or the other way around, I can't recall). Clearly they mean `true` regardless. Beyond True, False, and Nil I don't see what else this could apply to–the slope isn't that slippery. If it is an easy win and it makes transitioning easier, why not. 
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/CAM9Rf%2BLG4zqPDChND9YKSvOZUVpkfmhm-vVbZ-w6xouYnqDOUg%40mail.gmail.com.

Bruce Tate

unread,
Aug 19, 2016, 9:48:35 AM8/19/16
to elixir-l...@googlegroups.com
+1 from me. 

-bt

--
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+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Bruce Tate
President, RapidRed, LLC
Phone: 512.772.4312
Fax: 512 857-0415

Author of Seven Languages in Seven Weeks, Deploying Rails Applications, From Java to Ruby, Rails: Up and Running, Beyond Java, 6 others.

Pedro Medeiros

unread,
Aug 21, 2016, 10:02:46 PM8/21/16
to elixir-l...@googlegroups.com
Well is -1 for me. I have a project in which I have a module that is named False and True (actually the name is Machine.False Machine.True). it should be a pain for me to see a warning every time I call True or False, even because those modules names are valid once they are all atoms.


For more options, visit https://groups.google.com/d/optout.



--
Pedro Henrique de Souza Medeiros
----------------------------------
Cel: +55 (61) 9197-0993
Email: pedr...@gmail.com

Beautiful is better than ugly,
Explicit is better than implicit,
Simple is better than complex,
Complex is better than complicated.

The Zen of Python, by Tim Peters

Peter Hamilton

unread,
Aug 21, 2016, 10:19:50 PM8/21/16
to elixir-l...@googlegroups.com

I think warnings are good, but we need a way to say "Don't warn here" first.


On Sun, Aug 21, 2016, 7:02 PM Pedro Medeiros <pedr...@gmail.com> wrote:
Well is -1 for me. I have a project in which I have a module that is named False and True (actually the name is Machine.False Machine.True). it should be a pain for me to see a warning every time I call True or False, even because those modules names are valid once they are all atoms.
On Fri, Aug 19, 2016 at 10:48 AM, Bruce Tate <br...@rapidred.com> wrote:
+1 from me. 

-bt

On Sat, Aug 13, 2016 at 5:54 PM, Parker Selbert <par...@sorentwo.com> wrote:
To me it seems like the Python shell inconvenience of "did you mean quit" when you type exit (or the other way around, I can't recall). Clearly they mean `true` regardless. Beyond True, False, and Nil I don't see what else this could apply to–the slope isn't that slippery. If it is an easy win and it makes transitioning easier, why not. 

On Aug 13, 2016, at 4:25 PM, Andrea Leopardi <an.le...@gmail.com> wrote:

As I mentioned in IRC, I think this is a slippery slope. We never mention True/False in the docs and Erlang does not have them; if the warning would be specifically for Haskell and Python programmers, than we should ask ourselves, should we try to warn on everything in Elixir that looks like something in another language? For example, when I go back and forth between Elixir and Ruby, I put the do in def in Ruby, and I imagine many people coming from Ruby will forget the do in def when using Elixir: should we warn on such cases? This may not be the best example given that the warning on True/False is quite straightforward and non-intrusive to implement while warning on missing do would require changes to the parser and so on, but I hope it conveys the idea.



Andrea Leopardi

On Sat, Aug 13, 2016 at 8:58 PM, José Valim <jose....@plataformatec.com.br> wrote:
I am at first positive on this change. There is at least two mainstream languages that use True and False: Haskell and Python. Although I am not sure the warning will be really helpful at large, I don't think we would lose anything as it is quite unlikely someone has a module named True (or False). So it seems like a net benefit.

What are other people thoughts?


On Saturday, August 13, 2016, miwee <me.m...@gmail.com> wrote:
I recently got bitten by this. I used True/False, thinking them as boolean values true/false. Got no warning, but code failed. Partly reason is that I was recently alternating between python and Elixir code base. Python uses True/False. May be a gentle reminder from elixir compiler, on usage of True/False could have saved me from this.

thanks
miwee

--
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-co...@googlegroups.com.

--
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-co...@googlegroups.com.

--
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-co...@googlegroups.com.

--
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-co...@googlegroups.com.
--
Bruce Tate
President, RapidRed, LLC
Phone: 512.772.4312
Fax: 512 857-0415

Author of Seven Languages in Seven Weeks, Deploying Rails Applications, From Java to Ruby, Rails: Up and Running, Beyond Java, 6 others.

--
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-co...@googlegroups.com.
--
Pedro Henrique de Souza Medeiros
----------------------------------
Cel: +55 (61) 9197-0993
Email: pedr...@gmail.com

Beautiful is better than ugly,
Explicit is better than implicit,
Simple is better than complex,
Complex is better than complicated.

The Zen of Python, by Tim Peters

--
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-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/CAJbPmJOdM_JstrFkn358zKymvYX8E6d-kv4wbNoG585aryj1AA%40mail.gmail.com.

Chris McCord

unread,
Aug 21, 2016, 11:28:37 PM8/21/16
to elixir-l...@googlegroups.com
I am -1 on this warning since this is the first time this issue has been raised. I propose waiting for more feedback on this thread by people who have run into this issue, so we can get a larger sample size. I agree having this warning would affect very few negatively, but we've already seen someone that has code in the wild which will be punished. 

Saša Jurić

unread,
Aug 22, 2016, 4:03:36 PM8/22/16
to elixir-lang-core
This sounds like something which could be discovered with dialyzer. Maybe a rule in a linter (e.g. Credo) could also be helpful.

Wiebe-Marten Wijnja

unread,
Aug 29, 2016, 12:43:54 PM8/29/16
to elixir-lang-core
I agree with @Saša Jurić's approach. This (valid but possibly hazardous code), is exactly what linters are built for.
Reply all
Reply to author
Forward
0 new messages