Why Python Sucks

The Good, the bad & the ugly

- Yash Mehrotra

About Me

The Ugly

Error Handling

try:
    logging.info('Trying to open the file')
    filePointer = open('appFile','r')
    try:
        logging.info('Trying to read the file content')
        content = filePointer.readline()
    finally:
        filePointer.close()
except IOError as e:
    logging.error('Error occurred ' + str(e))

- There is a lot of blanket code when trying to handle errors

Its not just limited to Python, lots of languages use this way

Error Handling

Even though this is my personal opinion, it has been formed after working with lots people from different technical backgrounds.

 

According to me, this leads to bad practices where people just wrap their whole functions in try/except blocks

No constants

- Python has no concept of immutable constants

 

- There are many cases where one would want to declare something which would go unchanged throughout the execution of my program

 

- Additionally, an error should on raised on  changing the said constant

Pass by what ... ?

- Python has a mixture of pass by value and pass by reference

 

- Strings, integers, floats and tuples are passed by value where as lists and dictionaries are passed by reference

 

- In python, EVERYTHING IS AN OBJECT

 

- This leads to some bugs/unexpected output which you learn the hard way.

list_a = [1, 2, 3, 4]

list_b = list_a

list_b.append(5)

print list_a
>> [1, 2, 3, 4, 5]

print list_b
>> [1, 2, 3, 4, 5]
list_b = list_a[:]

Even assignment is not safe

 

We do this a lot, but in most of the use cases, this is not our intended behaviour

What we should do in this case

The Bad

2 vs 3 Split

  • There are still a lot of people who use python2
  • A pain for library maintainers
  • Developers are not migrating due to supposedly lack of libraries
  • Some famous libraries like Django are trying to push the community forward (Django 2.0 will not support Python 2)

Switch Statement

- Switch statement is one of the most common constructs of programming.


- It has lots of use-cases.


- It is missing in Python.

a = "Hello"

switch a:
    case "Hi":
        say_hi()
    case "Hello":
        say_hello()
    case "Bye":
        say_bye()
    default:
        say_idk()
a = "Hello"

if a == "Hi":
    say_hi()
elif a == "Hello"
    say_hello()
elif a == "Bye"
    say_bye()
else:
    say_idk()
a = "Hello"
mappings = {
    "Hi": say_hi
    "Hello": say_hello,
    "Bye": say_bye
}

mappings.get(a, say_idk)()

Or

Switch Statement

vs

Some minor annoyances

  • No multiline lambda functions
  • The way threading is handled

The Good

Flexibility

Readability

Third Party Libraries

Community

Thank You

Why Python Sucks

By Yash Mehrotra

Why Python Sucks

  • 305
Loading comments...

More from Yash Mehrotra