Sunday, March 19, 2017

Python: Airing of Grievances

Although this list focuses on the negative aspects of Python, I am publishing it so I can use it as a reference in an upcoming essay about my positive experiences with Python 3.6. Update: This is referenced by my post, "JavaScript vs. Python in 2017."

I am excited by many of the recent improvements in Python, but here are some of my outstanding issues with Python (particularly when compared to JavaScript):

PEP-8

What do you get when you combine 79-column lines, four space indents, and snake case? Incessant line-wrapping, that's what! I prefer 100 cols and 2-space indents for my personal Python projects, but every time a personal project becomes a group project and  true Pythonista joins the team, they inevitably turn on PEP-8 linting with its defaults and reformat everything.

Having to declare self as the first argument of a method

As someone who is not a maintainer of Python, there is not much I could do to fix this, but I did the next best thing: I complained about it on Facebook. In this case, it worked! That is, I provoked Ćukasz Langa to add a check for this (it now exists as B902 in flake8-bugbear), so at least when I inevitably forget to declare self, Nuclide warns me inline as I'm authoring the code.

.pyc files

These things are turds. I get why they are important for production, but I'm tired of seeing them appear in my filetree, adding *.pyc to .gitignore every time I create a new project, etc.

Lack of a standard docblock

Historically, Python has not had a formal type system, so I was eager to document my parameter and return types consistently. If you look at the top-voted answer to “What is the standard Python docstring format?” on StackOverflow, the lack of consensus extremely dissatisfying. Although Javadoc has its flaws, Java's documentation story is orders of magnitude better than that of Python's.

Lack of a Good, free graphical debugger

Under duress, I use pdb. I frequently edit Python on a remote machine, so most of the free tools do not work for me. I have not had the energy to try to set up remote debugging in PyCharm, though admittedly that appears to be the best commercial solution. Instead, I tried to lay the groundwork for a Python debugger in Nuclide, which would support remote development by default. I need to find someone who wants to continue that effort.

Whitespace-delimited

I'm still not 100% sold on this. In practice, this begets all sorts of subtle annoyances. Code snippets that you copy/paste from the Web or an email have to be reformatted before you can run them. Tools that generate Python code incur additional complexity because they have to keep track of the indent level. Editors frequently guess the wrong place to put your cursor when you introduce a new line whereas typing } gives it the signal it needs to un-indent without further interaction. Expressions that span a line frequently have to be wrapped in parentheses in order to parse. The list goes on and on.

Bungled rollout of Python 3

Honestly, this is one of the primary reasons I didn't look at Python seriously for awhile. When Python 3 came out, the rhetoric I remember was: “Nothing substantially new here. Python 2.7 works great for me and the 2to3 migration tool is reportedly buggy. No thanks.” It's rare to see such a large community move forward with such a poorly executed backwards-compatibility story. (Presumably this has contributed to the lack of a default Python 3 installation on OS X, which is another reason that some software shops stick with Python 2.) Angular 2 is the only other similar rage-inducing upgrade in recent history that comes to mind.

I don't understand how imports are resolved

Arguably, this is a personal failure rather than a failure of Python. That said, compared to Java or Node, whatever Python is doing seems incredibly complicated. Do I need an __init__.py file? Do I need to put something in it? If I do have to put something in it, does it have to define __all__? For a language whose mantra is “There's only one way to do it,” it is frustrating that the answer to all of these questions is “it depends.”

Busted Scoping Rules

For a language with built-in map() and filter() functions that underscore the support for first-order functions, I am perplexed with how bad the support for closures is in Python. Apparently your options are (1) lambda (which is extremely limited), or (2) a bastardized closure. Borrowing an example from an article that explains the new nonlocal keyword in Python 3, consider the following code in JavaScript:
function outside() {
  let msg = 'Outside!';
  console.log(msg);
  let inside = () => {
    msg = 'Inside!';
    console.log(msg);
  };
  inside();
  console.log(msg);
}
If you ran outside(), you would get the following output (which you would expect from a lexically scoped language like JavaScript):
Outside!
Inside!
Inside!
Whereas if you wrote this Python code:
def outside():
    msg = 'Outside!'
    print(msg)
    def inside():
        msg = 'Inside!'
        print(msg)
    inside()
    print(msg)
and ran outside(), you would get the following:
Outside!
Inside!
Outside!
In Python 2, the only way to emulate the JavaScript behavior is to use a mutable container type (which is gross):
def outside():
    msg_holder = ['Outside!']
    print(msg_holder[0])
    def inside():
        msg_holder[0] = 'Inside!'
        print(msg_holder[0])
    inside()
    print(msg_holder[0])
Though apparently Python 3 has a new nonlocal keyword that makes this less distasteful:
def outside():
    msg = 'Outside!'
    print(msg)
    def inside():
        nonlocal msg
        msg = 'Inside!'
        print(msg)
    inside()
    print(msg)
I realize that JavaScript generally forces you to type more with its var, let and const qualifiers, but I find this to be a small price to pay in exchange for unambiguous variable scopes.

36 comments:

  1. Engage with our agents and Book a Flight With Turkish Airlines, get best deals and offers. We provide best suggestion on baggage, tickets.

    ReplyDelete
  2. We care the best for our customers for Delta Airlines Flights. Get a flight of safety with prompt Delta Airlines Flights Status with Coronavirus updates.

    ReplyDelete
  3. Looking for your insurance plan information and need some help? Reach Progressive Insurance provider and get the best help and available round the clock.

    ReplyDelete
  4. If you want to make changes in your ticket type and not able to access your British Airways Manage Booking then contact us. We are available 24/7.

    ReplyDelete
  5. If you are searching for someone for your Printer Setup, then we assure you that we are always available for you. You can reach us at any time.

    ReplyDelete
  6. If you are facing issues with available Wi-Fi networks while setting Canon Wireless Printer Setup. Contact us at our toll-free number and get instant help.

    ReplyDelete
  7. Call at Auto Locksmith Near Me and one of our professional automotive locksmiths will be there to manage your lock-related requirements. Call now!!

    ReplyDelete
  8. If you are looking for the best help for Brother Printer Setup. We are always available for you to get the best services. We have experts in our team. Call Now!!

    ReplyDelete
  9. Require technical help for Epson Printer Setup at your home or office? Connect with our professional team of technicians. They are available 24/7. Call Now!!

    ReplyDelete
  10. "Nice Blog!!
    Norton login is one of the easiest platform that allows you to manage products download Norton antivirus and protect your device from online threats.
    Norton Account
    Norton Setup"

    ReplyDelete
  11. Good Post!!
    AOL Mail serve all the emails in your account, with aol email will get all updates on your mails promptly by creating aol account.
    AOL Account
    AOL Gold Download

    ReplyDelete
  12. Thanks for the informative blog. But, pests nowadays are a big problem. People suffer a lot of pests at home and office. We can get you the best price and quotes with Cooks Pest Control. If you want to contact them, call at our toll free number for immediate help.

    ReplyDelete
  13. This comment has been removed by the author.

    ReplyDelete
  14. Tired of dealing with pests? Reach out to Moxie Pest Control, the experts available will instantly assist you and will help in resolving the issue. If you want to contact them, call at our toll free number for immediate help.

    ReplyDelete
  15. Edge pest control is one of the leading bug control service providers in the area. It is in process since a long time now and it is the first choice for every bug or pest relate issue any resident of the area has. The company works on some specific grounds to make their services more accurate and qualified. Edge pest control follows these factors that actually determine the quality of your experience of our bug control services with Edge pest control company.

    ReplyDelete
  16. Our team present at helpdesk for Rodent Control, Cook’s Pest Control team will help you to remove rodents from your place instantly with long term guarantee, so you don’t need to get worried over it. If you are stuck with pests for a long time and unable to reach the experts, then take a breath and feel relaxed because we are there for you.

    ReplyDelete
  17. In order to get rid of pests issues, the team of Hawx Pest Control will provide you significant services throughout the areas you require according to your convenience. The team of Hawx Pest Control will inspect your home from the top to bottom and from every corner to check the presence of the pests. The team of Hawx Pest Control always provide you the detailed view about the service and their activities.

    ReplyDelete
  18. If you are facing trouble related to pests and bugs, then you are at the right place. Aptive Pest Control innovative approach and safe advanced technology will help you to get away pests and bugs from your house. Pests can enter your stead through many ways like they can enter through windows, rooftop holes, rotten food in dustbin, standing water around buildings etc.

    ReplyDelete
  19. Tired of dealing with pests? Reach out to Moxie Pest Control, the experts available will instantly assist you and will help in resolving the issue. If you want to contact them, call at our toll free number for immediate help.

    ReplyDelete
  20. Terminix Pest Control is the best and leading pest control companies in the industry and includes some of the nation’s top specialists and professionals with all the graduate and PhD-level entomologists and certified members of the Entomological Society of United State of America.

    ReplyDelete
  21. When it comes to your career prospects and bright future, Assignment Help takes the onus on itself to promote your growth in the right direction. So, that way you wouldn’t have to think twice before trusting us with your academic papers. Place an order with us now and reap the rewards of brilliantly written academic papers today. Assignment help, one of the leading academic solution providers in Australia, understands the challenges and extends a helping hand to the aspiring engineers who are willing to land a job in Australia.
    Sydney Assignment Help

    ReplyDelete
  22. Nowadays students from the school, college and universities look for Essay Help UK and Essay Helper UK services from the experts who can help them in solving their assignment in a manner that is required in college and universities.

    ReplyDelete
  23. Terminix Pest Control is the best and leading pest control companies in the industry and includes some of the nation’s top specialists and professionals with all the graduate and PhD-level entomologists and certified members of the Entomological Society of United State of America.

    ReplyDelete
  24. Assignment help in Saudi Arabia allows students to finish their papers on time without having any mistakes. If you want to submit error-free papers in your universities, you must think about Online Assignment help in Saudi Arabia.

    ReplyDelete
  25. Nowadays students from the school, college and universities look for My Assignment Help Singapore and MyAssignmentHelp Singapore services from the experts who can help them in solving their assignment in a manner that is required in college and universities.

    ReplyDelete