Live data from Hacker News

Unpythonic Python

skien.cc

141–150 of 156 posts

Re: Unpythonic Python

#143

Earlier quoted context omitted.

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.

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.

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.

Re: Unpythonic Python

#144
Since we are talking about crazy python fizzbuzz, allow me to share a creating I have had sitting around for a while:

    def fbg(s,r):print("\n".join(map(lambda x:str(x[1])if x[0]==''else x[0],zip(("".join(a for a,b in s if n%b==0)for n in range(1,r+1)),range(1,r+1)))))
    fbg((('Fizz',3),('Buzz',5)),100)
Cause, you know, fizzbuzz one-liners need to work for the generic case.

Re: Unpythonic Python

#145
post #135

#include #include #include #include #include #include static char c[9]; int p(int i) { putchar(c[i++]); putchar(c[i++]); putchar(c[i+(7-i)]); putchar(c[i+(8-i)]); return 0; } int f(int i, int x) { i -= x; if(!i) { return p(x); } if(i

This'd be more fun if it didn't segfault printf(n%15 ? n%3 ? n%5 ? "%d\n" : "Buzz\n" : "Fizz\n" : "FizzBuzz\n", n);

Probably segfaults with the shitty ELF hackery :(

Re: Unpythonic Python

#146
post #24
post #14

Earlier quoted context omitted.

I generally don't particularly like giving punctuation meaning that, well, isn't punctuating. The bottleneck when writing code is almost never keypresses. I think CoffeeScript gets it probably the most right of languages I've worked with, in that the choice of punctuation makes intuitive sense... "Hey! It's an Arrow. It goes from here to here". FWIW, I don't like the word "lambda" either... Naming things with one let…

I cannot agree enough. Someone give me a call when a Haskell-like language with readable syntax appears. I really like the ideas behind Haskell, but the syntax is so unfriendly that I cannot be bothered to really start using it. Less special characters, please.

I have very limited familiarity with Haskell, but I find the syntax pretty clean and readable - I spend most of my time getting my head around functional/lazy/etc semantics, which make my head hurt (in a good way) - that presumably implies that the syntax is successfully exposing those semantics to my poor OO/duck-typing coddled brain.

I suppose these things are a matter of taste as much as anything else. But when people talk about a Haskell program being 'elegant', I never think to myself "what, that mess?"

Re: Unpythonic Python

#149
post #129
post #40

When you write too much Haskell, your Python code starts to look like this: print('\n'.join( 'FizzBuzz' if x%5==0 and x%3==0 else 'Fizz' if x%3==0 else 'Buzz' if x%5==0 else str(x) for x in range(1, 101))) I would really like to have a "let" expression in Python to avoid having to write a new function with a def statement when you could get away with a simple lambda or generator expression.

Julia: print([(x%3==0) && (x%5==0) ? "FizzBuzz" : (x%3==0) ? "Fizz" : (x%5==0) ? "Buzz" : x for x in 1:100])

Cool!

Re: Unpythonic Python

#150
post #79

There's something minor that's always bothered me about the usual description of FizzBuzz: > If the number is divisible by 3, print Fizz instead of the number. If it’s divisible by 5, print Buzz. If it’s divisible by both 3 and 5, print FizzBuzz. In a strict interpretation, the first two sentences could be seen as incorrect. If a number is divisible by 3, you cannot just print 'Fizz' and move on. You also have to che…

This is why the description is good. Sure, it tests whether you can write a set of statements a computer can understand. But it also tests whether you can understand the intent behind a set of statements a human would make, without going on a diatribe about how the definition is not good enough. After all, if English was a formal strict language where only one right way existed to express something, we wouldn't need…

I think you could have made this point without subtly referring to my post as a "diatribe." I'm more than aware of what the intended interpretation is. Posting what I felt was a very minor and amusing observation hardly constitutes a "diatribe."

> After all, if English was a formal strict language where only one right way existed to express something, we wouldn't need programmers, would we?

This is very off-topic, but I'm not sure I agree with it. You're assuming that it would be easy to find the one unique way to express a given computation such that anybody could write it down. Even if English had this uniqueness property, I don't think that would be true at all.

Post reply on HN