News for hackers. Stuff that matters.
Re:Unpythonic Python by MichaelDickens on Wednesday April 09, 2014 @07:45PM (#7563298)
I think this code is easier to read than the more verbose 12-line version given in the article. It takes longer to read per line, but less time total.
Re:Unpythonic Python by Shish2k on Wednesday April 09, 2014 @07:59PM (#7563365)
It's not just more complexity per line, it's also a higher level of complexity, using language-specific features that people who aren't fluent in python wouldn't be familiar with (multiplying a string by a boolean)
Re:Unpythonic Python by arethuza on Thursday April 10, 2014 @04:57AM (#7564921)
I'm fairly new to Python, though not to software development, and one of the nice things I find about Python is that when I see something I haven't seen before (in this case multiplying a string by a boolean) I can usually guess correctly what it will do and spend a few seconds with the REPL to confirm.

Of course, this is true to a certain extent of all programming languages, but I do find Python particularly easy in this respect.

Re:Unpythonic Python by groovy2shoes on Thursday April 10, 2014 @12:44AM (#7564251)
By that logic, no one should write anything in idiomatic French because anyone who isn't fluent in French wouldn't be able to read it.
Re:Unpythonic Python by jfoster on Thursday April 10, 2014 @01:27AM (#7564344)
Well, that example is a bit different. You're ignoring who the audience is. When writing code, the audience is usually at least people on the same team, if not the person writing in the first place.

If writing in French for people who are not fluent, I think it would be a good idea to avoid idiomatic language.

Re:Unpythonic Python by groovy2shoes on Thursday April 10, 2014 @02:56PM (#7568849)
It's not different. The audience in this case is people who are fluent in Python. Saying that code sample is bad is like saying Baudelaire is bad because only people fluent in French can read it.
Re:Unpythonic Python by icambron on Thursday April 10, 2014 @01:26AM (#7564341)
I was curious about that. Is multiplying a string by a boolean idiomatic Python? I don't write nearly enough Python to know, but it strikes me that this might be more like writing French using lots of obscure words.
Re:Unpythonic Python by softbuilder on Thursday April 10, 2014 @05:10AM (#7564944)
This starts to get into "what is idiomatic python?" which changes as the language evolves. For example, before Python had an official ternary form, this was a common idiom:

    account.status = ["paid", "unpaid"][amount_due > 0]
This does the same thing as the FizzBuzz example, coercing a bool to int. Here the int is used as an index into the list of the two strings.

Personally, I found this handy and liked it a lot. Others didn't and now there is this, which isn't bad:

   account.status = "unpaid" if amount_due > 0 else "paid"

Maybe it's less like using obscure French and more like speaking in a slightly different dialect, or in a different region with different cultural references.
Re:Unpythonic Python by yen223 on Thursday April 10, 2014 @06:19AM (#7565086)
Multiplying a string by an integer is fine.

Treating a boolean as an integer is iffy

Multiplying a string by a boolean frankly should be a no-no.