There's no honest attempt to explain the philosophy behind every language with real-world examples in Python. It's just childish jokes. It's the equivalent of saying "Ze fish in le river" is "Frenchish English". Ha ha, stupid French people, right? It's easy to make fun of programming languages like this, but what does that teach us? Aside from to mock what is different than what we use right now?
Unpythonic Python
151–156 of 156 posts
Re: Unpythonic Python
#152When 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.
And when you write C carefully, the C code looks like this (thanks seanjensengrey and rhth54656 for ideas): int i; static char* a[] = { "%d\n", "Fizz\n", "Buzz\n", "FizzBuzz\n" }; for ( i = 1; i The loosely similar Python: for i in range( 1, 101 ): print( [ i,'Fizz','Buzz','FizzBuzz' ][ (i%5==0)*2 + (i%3==0) ] )
const char *fb[][2] = {{"%d\n", "Fizz\n"}, {"Buzz\n", "FizzBuzz\n"}};
int i;
for (i = 1; i
(It's a pity we have to specify the second dimension manually . . .)Re: Unpythonic Python
#153Earlier 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.
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
#154This reminds me of a similar effort called "evolution of a python programmer" and published in this gist:
https://gist.github.com/ghoseb/25049
something like 30 different implementations of factorial; my favorites are the 'expert programmer' and the "web designer"
Re: Unpythonic Python
#155Earlier quoted context omitted.
The particular form of the description at issue can be interpreted (arguably, is most naturally interpreted ) to direct a different outcome than is usually expected from FizzBuzz, to wit, it directs that on numbers divisible by 15 "Fizz", "Buzz", and "FizzBuzz" all should be printed, rather than just the last.
The description is underspecified, no surprise there, but that's different from claiming it's incorrect . As far as its purpose as an interview question goes noticing this interpretation would probably be seen as a good sign.
Natural language can be used with precision, and this is an important skill for engineers. Being able to identify ambiguity and inconsistency is an important part of that skill so yes, noticing it within a question should count in favor of the candidate. Dismissing it as being pedantic is the wrong response, because if you are working on something critical (secure communications software, for example) you need to handle ideas with precision.
Re: Unpythonic Python
#156One of the solutions in the comments I found quite pythonic and concise. Somehow people have it in their heads that "Pythonic" means long-winded. And yes, you have to read the code and think for a second to understand it, but that's no crime. [(not x % 3) * 'Fizz' + (not x % 5) * 'Buzz' or x for x in range(1, 101)]
let f = (replicate . fromEnum . (==0)) .: mod in [concat $ f x 3 "Fizz" ++ f x 5 "Buzz" | x <- [1..101]]