Live data from Hacker News

How To Let People Know You're A Bad Python Programmer

artificialcode.blogspot.com

21–30 of 40 posts

Re: How To Let People Know You're A Bad Python Programmer

#21
post #14

Call Perl from Python This is an oldie but a goodie, but a lot of bad programmers don't realize they can make their Python code even worse, if they embed a bunch of untested, legacy, Perl code in it. There is a Perl/Python module that makes this a snap. Yes, throw in a Perl slight for good measure. A surer way of endearing yourself to your fellow Pythonistas , I know of not. This is not unlike what happens on reddit.…

Perl, that miserable little unwanted orphan of a language, has real anonymous, first-class functions complete with closures. Python, sadly, does not Which Python are you talking about? The language I use has had closures and first-class functions for years.

They don't seem to work very well:

  >>> def foo():
  ...   blah = 42
  ...   def wibble():
  ...     print "blah is " + blah
  ...   wibble()
  ... 
  >>> foo()
  blah is 42
Great! Looks like we have real closures!

  >>> def foo():
  ...   blah = 42
  ...   def wibble():
  ...     blah += 1 
  ...   wibble()
  ...   print "blah is " + blah
  ... 
  >>> foo()
  Traceback (most recent call last):
    File "", line 1, in 
    File "", line 5, in foo
    File "", line 4, in wibble
  UnboundLocalError: local variable 'blah' referenced before assignment
Oh. Maybe not.

Re: How To Let People Know You're A Bad Python Programmer

#22
post #14

Call Perl from Python This is an oldie but a goodie, but a lot of bad programmers don't realize they can make their Python code even worse, if they embed a bunch of untested, legacy, Perl code in it. There is a Perl/Python module that makes this a snap. Yes, throw in a Perl slight for good measure. A surer way of endearing yourself to your fellow Pythonistas , I know of not. This is not unlike what happens on reddit.…

Perl, that miserable little unwanted orphan of a language, has real anonymous, first-class functions complete with closures. Python, sadly, does not Which Python are you talking about? The language I use has had closures and first-class functions for years.

Only since Python 3000, with the addition of the "nonlocal" declaration, can python claim to have closures. And yes, Python does also have "first-class functions"--in the same way that C has first-class functions. It's the "anonymous" part that it has difficulty with.

Re: How To Let People Know You're A Bad Python Programmer

#23

> Add comments in the doc string or anywhere, that say, this is "magic", or "bad" and needs to be rewritten. These are XXX comments and they're pretty common even with the best developers. They're so common that pretty much every editor has a syntax highlighting regex to detect them.

Yup, they're common, and I agree with cturner - they're a very good thing. Comments that point out bad sections of code that need rewriting are invaluable.

Re: How To Let People Know You're A Bad Python Programmer

#24
post #16
post #14

Call Perl from Python This is an oldie but a goodie, but a lot of bad programmers don't realize they can make their Python code even worse, if they embed a bunch of untested, legacy, Perl code in it. There is a Perl/Python module that makes this a snap. Yes, throw in a Perl slight for good measure. A surer way of endearing yourself to your fellow Pythonistas , I know of not. This is not unlike what happens on reddit.…

I agree wholeheartedly with the first half of your comment, but the second half is the same uninformed dogma you rail against in the first! Python is not really a functional programming language -- it has statements and suites, neither of which are first-class. lambda is implemented as an inline (suite-less) value-returning statement (like the ternary statement) because dealing with indentation would be a bitch. Sinc…

> first-class.

I'm not sure I follow. This looks first-class to me.

  def name_printer(name):
      def printer():
          print(name)
      return printer

  erlanger_printer = name_printer('erlanger')
Python doesn't support creating anonymous functions, but functions are first-class. Sorry if you already knew this; it seems like you know Python pretty well so I'm sure you do.

Re: How To Let People Know You're A Bad Python Programmer

#26

Earlier quoted context omitted.

Perl, that miserable little unwanted orphan of a language, has real anonymous, first-class functions complete with closures. Python, sadly, does not Which Python are you talking about? The language I use has had closures and first-class functions for years.

They don't seem to work very well: >>> def foo(): ... blah = 42 ... def wibble(): ... print "blah is " + blah ... wibble() ... >>> foo() blah is 42 Great! Looks like we have real closures! >>> def foo(): ... blah = 42 ... def wibble(): ... blah += 1 ... wibble() ... print "blah is " + blah ... >>> foo() Traceback (most recent call last): File " ", line 1, in File " ", line 5, in foo File " ", line 4, in wibble Unboun…

That's a scoping problem, not a closure problem. The issue in this example is that python doesn't have true lexical scope. It has three scopes: function level, class level, file level. If you wrote "global blah", it would look at file level, not the next function level.

I agree it's broken, but it's a different flaw than the closure problem.

Re: How To Let People Know You're A Bad Python Programmer

#27
post #12

a few of these are the same as those mentioned in http://news.ycombinator.com/item?id=746873 i too think the distinction between camel case and lowercase underscore as one being somehow more readable or better than the other is a little silly.

I'm shifting to prefer lowercase underscore, but I actually wasn't aware of that detail of PEP 8, either. Not that I can claim to have built anything sizable in Python, just lots of little to moderate-sized scripts.

Re: How To Let People Know You're A Bad Python Programmer

#28
post #22

Earlier quoted context omitted.

Perl, that miserable little unwanted orphan of a language, has real anonymous, first-class functions complete with closures. Python, sadly, does not Which Python are you talking about? The language I use has had closures and first-class functions for years.

Only since Python 3000, with the addition of the "nonlocal" declaration, can python claim to have closures. And yes, Python does also have "first-class functions"--in the same way that C has first-class functions. It's the "anonymous" part that it has difficulty with.

Glad to know I can add you to my list of people who believe that Haskell does not (and by definition cannot) have closures.

Re: How To Let People Know You're A Bad Python Programmer

#29
post #18

> Brag that you called Perl from Python because it was "quicker" to experienced Python programmers. A coworker found that calling out to grep can be faster than using Python's regular expressions for large amounts of text processing. My first reaction was to cringe, but it was indeed much faster for this particular problem; I think I was the bad programmer for reflexively cringing instead of saying "nice performance…

There are times and cases where a Perl script is faster than grep. It's ridiculously heavily optimized for that particular task.

Re: How To Let People Know You're A Bad Python Programmer

#30
post #18

> Brag that you called Perl from Python because it was "quicker" to experienced Python programmers. A coworker found that calling out to grep can be faster than using Python's regular expressions for large amounts of text processing. My first reaction was to cringe, but it was indeed much faster for this particular problem; I think I was the bad programmer for reflexively cringing instead of saying "nice performance…

There are times and cases where a Perl script is faster than grep. It's ridiculously heavily optimized for that particular task.

[deleted]
Post reply on HN