Live data from Hacker News

Unpythonic Python

skien.cc

81–90 of 156 posts

Re: Unpythonic Python

#81
post #62

Earlier quoted context omitted.

Mmm I suppose it's really just preference. I love that syntax. But I guess there's no arguing about taste.

Well, it's typing-friendly but not (re)learning-friendly. I guess it depends how you weigh those concerns.

It's also very reading friendly.

I normally forgive languages being hard to learn if the bring enough utility.

Re: Unpythonic Python

#82

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?

Yes, it's a joke. I know it's against the guidelines of this site, but it's quite a nice joke.

Re: Unpythonic Python

#83
Here's one in Hy (a homoiconic frontend to Python... it really is just Python™):

   (require hy.contrib.anaphoric)
  
   (ap-each (range 1 101)
    (print (cond [(= (% it 15) 0) "Fizzbuzz"]
                 [(= (% it 5) 0) "Buzz"]
                 [(= (% it 3) 0) "Fizz"]
                 [True it])))
Reads pretty good too, doesn't it?

http://docs.hylang.org/en/latest/

Re: Unpythonic Python

#84
post #7

This was what one of our Java coworkers wrote a while back: https://gist.github.com/1337/8155054

It won't work on py3 because map is a generator. Tell him to use list comprehensions:

  [setattr(self, x, kwargs[x]) for x in kwargs.keys()]
Though of course that is a bit too slow and he should do

  self.__dict__.update(**kwargs)
or for maximum correctness

  import os; os.remove(__file__)

Re: Unpythonic Python

#85
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 programmers, would we?

Re: Unpythonic Python

#86

Earlier quoted context omitted.

You realise the equivilent Objective-C syntax is ^{} right? And access modifiers are + and - rather than static and nonstatic. Objective-C definitely isn't above using lightweight syntax. Where it favours verbosity is APIs.

I realize it, right. But I hoped you'd see beyond the direct comparison of lambdas with Objective C's blocks. I'm saying that short code doesn't automatically translate to more readable or better code, Objective C's message syntax is the proof (if I have to be painfully specific about it). I write a lot of JS and typing out "function" or "return" was never on the list of things I found a problem, despite I also work…

The parent wasn't saying code should be short, they were saying the syntax for lambdas should be short.

Yes, short code doesn't automatically translate to readible code. But neither does long code.

You can't wheel out objective-c's fondness for long self-documenting message names as self-evident proof that the syntax for lambdas must be verbose.

Long message names are good because they let you clearly describe what is otherwise a big black box of unknown behaviour.

The syntax for a lambda will always be a lambda, so it doesn't need to be spelt out explicitly each time. Shorter syntaxes such as used by Haskell are easier to visually pattern match on and so can actually aid comprehension.

It's not as simple as longer is always better and anyone who disagrees is obviously foolish and lazy.

Re: Unpythonic Python

#87
post #34
post #7

This was what one of our Java coworkers wrote a while back: https://gist.github.com/1337/8155054

I don't think you need to even explicity say he's used to Java. Wow... I've never felt the need to the use the factory technique.

I use factories a lot when using Django... But, of course, in Python they are functions that return a class, not classes.

Interfaces instead are completely unpythonic. Or, maybe I should call them antipythonic?

Re: Unpythonic Python

#88

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?

While I wrote this with tongue in cheek, I also aimed to illuminate the power of Python's flexibility along with the inherent danger therein. I do admit the Javacious example was over the top though ;)

Re: Unpythonic Python

#89
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.

I like this one. I don't know enough Haskell to have come up with it on my own (but I should!)

Re: Unpythonic Python

#90

Neat! I'd be interested in seeing pythonic solutions written in other languages (to the extent that those languages may allow 'Pythonic' style), too. I find it fascinating to see how certain languages will, for one reason or another, trend towards certain design patterns and styles.

I'm trying very hard to write Python in VB.Net at my job. But I've not been very successful, Python is very flexible.
Post reply on HN