On Fri, May 29, 2015 at 8:53 PM, Tim Chase <python.l...@tim.thechases.com> wrote: > On 2015-05-29 13:48, Chris Angelico wrote: >> That said, though, using 0 for False and 1 for True is easily >> the most common convention in use today, and the next most likely >> case is that comparing booleans would give a simple and immediate >> error. So it's most likely to be safe to do. > > There are popular exceptions though. coughshellscriptingcough
Yes, so you'd have to be careful if you port your complex script to bash [1]. I'm also not sure how you'd even implement the comparison. But shell scripting is still dwarfed by languages in which false is 0 and true is (usually) 1. Using Redmonk rankings: 1 JavaScript 2 Java 3 PHP 4 Python 5 C# 5 C++ 5 Ruby 8 CSS 9 C 10 Objective-C 11 Perl 11 Shell I'm not sure about Ruby, and I don't think CSS has a concept of boolean arithmetic, but ten languages outrank shell scripting (Perl is tied) and of them eight (maybe nine) use 0/1. Using langpop.com stats, shell scripting comse up rather higher, but it's still beaten out - and by considerable margins - by C, Java, PHP, JavaScript, C++, and Python, all of which use 0/1. The Tiobe index seems to split up several shells, which penalizes them severely (Bourne shell and bash both come up in the 51-100 range), but even if they were merged, they're unlikely to be able to nudge out the top five of Java, C, C++, Objective-C, and C#. So while it's clearly false to state that 0/1 is the _only_ convention in use today, it's fairly justifiably the _most common_. And of course, there are plenty of historical systems that were different, as have been mentioned. But most programmers aren't going to come across those... I hope! ChrisA [1] You'd also have to be insane. A bash script should not, in my opinion, exceed about a page or two of code. I'm not sure how large a bash script has to be before it collapses under its own gravity and forms a black hole out of which no comprehension or sanity can escape, but I'm taking no chances. -- https://mail.python.org/mailman/listinfo/python-list