Live data from Hacker News

Reasons Python Sucks

hackerfactor.com

31–40 of 554 posts

Re: Reasons Python Sucks

#31

the self argument for methods/method calls is stressful (having to define self for methods and having to call a method via self); also the fact that you need to check if dictionary key exists, else you get an exception when trying to get the keys value. Also ':' at the end of each line. I always forget at least one of these. You didn't have any of these goodies in good old perl (sob, sob) (wow, this one got flagged p…

you need to check if dictionary key exists, else you get an exception when trying to get the keys value.

What should be the correct behavior when accessing a key that doesn't exists? If you want a specific default value when a key doesn't exist you can use the get() method.

Also ':' at the end of each line.

What do you mean? You don't need ':' at the end of each line, only at the start of a block (basically anywhere you'd use a '{' in other languages).

Re: Reasons Python Sucks

#32

I too have tried it many times mainly because of all the great ML libs for python but each time I dreaded using it for Reason #3 (Syntax). Using indents for blocks just seemed unintuitive and error prone to me. But I dismissed it because all the programming languages I've worked with have had curly braces so maybe the reason for my discomfort was that it was unfamiliar.

Only in Python can I commit a whitespace-only change that results in a 10x speed improvement.

Re: Reasons Python Sucks

#33

A number of these points seem like reasonable opinions to have. But two which had me questioning the breadth of the author's experience were "Most programming languages pass function parameters by value." and "In every other language, arrays are called 'arrays'. In Python, they are called 'lists'." To the author: 1. Java, JavaScript and C# all have types which are passed by reference. (They also have types which are…

In C#, all variables ( reference or value types ) are passed by value. Yes, even reference types are passed by value. If you want to pass variables by reference, you need to use special modifiers ( out or ref ).

Re: Reasons Python Sucks

#34
post #6

Many of the reasons authors states are quite silly. Personally I don’t like the huge perf hits everywhere you look. For example, a bool in Python takes whopping 24 bytes! Multi threading is a giant mess due to GIL that apparently no one can get rid of. Things like true static variables are missing. Import behavior differences for programs and modules is baffling. Lambda is intentionally kept under powered (ex. no gro…

Now this is a good list of things to hate about Python. I would add the fracturing of build methods for large applications is another frustrating thing about working with python. Although projects like Pipenv and Poetry seem to be bringing python up to modern standards in that arena.

Re: Reasons Python Sucks

#35
A better reason to hate Python: the internal model is way overcomplicated for what it's meant to be: a beginner-friendly scripting language. "Everything-is-an-object", duck typing, decorators, bizarre scoping rules, etc., all make it difficult for experienced programmers to understand, let along beginners. I've always thought there's a much simpler language struggling to get out of Python, and I wish it would and would become popular so I wouldn't have to recommend Python to beginners any more, and be on the hook for explaining e.g. why default values are mutable, or why nested generator comprehensions behave differently than nested list conprehensions. (Think Erlang levels of simplicity.)

The standard library is also haphazard and inconsistent (much like JavaScript's). Take lists: some operations are methods, some are functions, some mutate the list, some make a copy, some are global, some are in a module. There's no rhyme or reason that I can tell. Modern C++ has, in my opinion, a much more well-thought-out standard library. There are very few methods/functions which exist due to historical accident (iostreams aside), and the distinctions between methods/free functions and mutators/copiers is fairly uniform.

Re: Reasons Python Sucks

#36

A number of these points seem like reasonable opinions to have. But two which had me questioning the breadth of the author's experience were "Most programming languages pass function parameters by value." and "In every other language, arrays are called 'arrays'. In Python, they are called 'lists'." To the author: 1. Java, JavaScript and C# all have types which are passed by reference. (They also have types which are…

Python (and Java) do not pass anything by reference. They pass by pointer-value. (If they passed by reference, you could change to which value a caller's variable was bound, like you can in C++).

> (If they passed by reference, you could change to which value a caller's variable was bound, like you can in C++)

I might be misunderstanding you, but I don't think you can do this in C++. References can't be changed to point to a different object after initialization. If you have code like:

  void MyFunc(Foo& ref_param) {
    Foo new_foo;
    ref_param = new_foo;
  }
The assignment above isn't "changing the value to which a caller's variable is bound". Instead, it's running the '=' operator on the Foo object to copy the state from new_foo to ref_param. To demonstrate this, you could run the following to see that the addresses are the same:

  Foo original_object;
  Foo& object_ref = original_object;
  MyFunc(object_ref);
  // object_ref still points to the same address
  assert(&original_object == &object_ref);
Under the hood, C++ reference params are basically syntactic sugar for passing by pointer-value, so this behavior isn't surprising.

Re: Reasons Python Sucks

#38

the self argument for methods/method calls is stressful (having to define self for methods and having to call a method via self); also the fact that you need to check if dictionary key exists, else you get an exception when trying to get the keys value. Also ':' at the end of each line. I always forget at least one of these. You didn't have any of these goodies in good old perl (sob, sob) (wow, this one got flagged p…

Idk, maybe because your arguments are bit shallow?

I like 'self'. There's a lot to complain about magical 'this' of every other language - especially in Javascript. Specifying self makes it really clear if it's a member method or a standalone function.

Python really likes the idea of 'seek forgiveness, not permission', aka. abusing try/except. But it's kind of nice:

  # seek permission
  if 'key' in map:
      fn(map['key'])
  else:
      whatever()

  # seek forgiveness
  try:
      fn(map['key'])
  except KeyError:
      whatever()
Just pray that 'fn()' doesn't also throw a KeyError.

Re: Reasons Python Sucks

#39

the self argument for methods/method calls is stressful (having to define self for methods and having to call a method via self); also the fact that you need to check if dictionary key exists, else you get an exception when trying to get the keys value. Also ':' at the end of each line. I always forget at least one of these. You didn't have any of these goodies in good old perl (sob, sob) (wow, this one got flagged p…

It's been a while since I touched Python (thankfully), but there's also:

- The hideous __method__ and _private conventions

- A friend of mine was complaining about the implicit string concatenation: ["foo" "bar", "baz"] whoops forgot a comma and now there's a very hard to find bug

- pyc and pyo files littering the filesystem after running (yes, only a minor nuisance)

- import anywhere, the ugly __name__ = "main" hack

- GIL, reference counting GC, abysmal performance in general

- Dynamic typing, which is probably my most major complaint but I realize opinions differ

Re: Reasons Python Sucks

#40
* Versions and installation: Consider doing all dev work in a virtual env. It installs the correct python interpreter on your PATH, and installs pips in that isolated env.

$ python2.7 -m virtualenv .venv or $ python3.6 -m venv .venv

$ source .venv/bin/activate

// dev + test here

$ deactiveate

> This worked great until I started on a second project that needed Python 3.6. Two concurrent projects with two different versions of Python -- no, that wasn't confusing.

Note that Java also comes in various version of the compiler and jvm, and its common to have several versions on the same system. They are backward compatible but forward compatibility issues exist: your main server app runs on java7 but your batch process is running java9. you might not want to make java9 the default on the system without formally upgrading the server app.

* Syntax/spaces : you get used to it. Hey some people write code in perl :)

* Includes: In principle, this works somewhat similar in Java: You use imports and the imported package hierarchy can nest quite deep so you need to look.

> The import function also allows users to rename the imported code. They basically define a custom namespace..

This can be a good thing, it helps you prevent name clashes. C++ also lets you do this, its called Namespace aliases.

namespace fbz = foo::bar::baz; std::cout * Nomenclature:

> In every other language, arrays are called 'arrays'. In Python, they are called 'lists'.

Thats because it is a list. Nodes are dynamically allocated and appended to the list. You can expect similar algorithmic complexity for the operations.

Python also has arrays if you want the better efficiency: https://docs.python.org/3/library/array.html

* Pass By Object Reference: same as java

Post reply on HN