Skip to content

Instantly share code, notes, and snippets.

@LordMZTE
Created September 13, 2020 15:09
Show Gist options
  • Save LordMZTE/9032dd7d98f709852455d82ac5e54994 to your computer and use it in GitHub Desktop.
Save LordMZTE/9032dd7d98f709852455d82ac5e54994 to your computer and use it in GitHub Desktop.
Python

python is a pretty bad language because


  • weird syntax
    • I find it hard to read because its missing semicolons and braces
    • doc comments
      • they use triple quotes which doesn't make sense for a comment
      • they go under the item they are documenting which just looks ugly
    • lambdas are a poorly implemented afterthought
    • the def keyword is named inconsistently since "def" does in no way says that a function is being defined
    • indentation as a syntactical element is just silly. it takes freedom from the programmer and makes it harder to see where a block ends
    • weird names for special functions like constructors or operators
      • when I see a function like __init__ it just looks like this is an internal function not meant to be used in any way.
      • this just also looks like an afterthought. instead, special syntax should be used like java using the class name for declaring constructors or kotlin using the operator keyword for operator functions
    • unusual symbols and naming
      • comments use # instead of the more conventional //
      • exceptions use the unusual keywords raise and except instead of the usual throw and catch
      • elif instead of easier to remember else if. elif really just seems like a useless keyword
    • not, and and or instead of the cleaner looking and easier to write !, && and ||
    • because indentation is used to determine scopes, it looks really unclean to write a block or just multiple statements on one line which may be wanted.
    • normal if/else blocks are not expressions. if they were the additional ternary operator syntax would be redundant
    • there is no switch statement or something similar, leading to huge elif blocks
    • the syntax for inheritance makes the classes to inherit from look like types for constructor parameters
    • declaring a block that does nothing requires the pass keyword and for some reason, it is not possible to just leave out the :
    • the recently added assignment expression has new syntax (:=) instead of just making the normal assignment an expression
  • dynamic typing
    • dynamic typing leads to runtime errors which could normally be detected at compile time
    • passing an incorrect type into a function may cause unpredicted behaviour
    • it may not be immediately clear what type a function is expecting, which may lead to trouble when trying to call it since it is unknown what it wants
    • a function may return anything, thus making it hard to predict what it will return and to work with the result
    • type hints may solve some of the issues above, but they are still just a suggestion and do not have to be used
    • that variables don't need to be declared means that typos may be harder to find. i may want to assign a value to foo but then accidentally mistype it as fo. if this happens, it will be hard to debug if foo was used before, because foo may have an unexpected value later in the program
    • a variable's type can be changed after it has been assigned, which can lead to confusion about what type it has
  • interpreted
    • poor performance
    • some errors are only detected once the code that they are in gets executed, this means a part of the program that may not have been tested could have an error that remains undetected
    • distribution. python, as an interpreted language is hard to package as it is not compiled into a binary or archive unless third party tools are used, which also don't work really well
  • classes
    • self parameter is passed into the function which is unnecessary boilerplate. this should happen seamlessly because python has no advantage in specifying it. instead an approach like java should be taken that some keyword should be added to make the function static. however, a self parameter is not always a bad idea, but it is in python. in languages like rust, it makes sense because self could be a pointer, or mutable which needs to be stated however in python self only ever has one variation making the parameter unnecessarily complicated
    • fields do not need to be declared and can just be assigned. this leads to a lot of issues
      • a function may expect a class to have a field but it cannot be guaranteed that it has
      • it is hard to know what a class will store thus making it harder to work with
      • I know it is recommended to declare fields but it is not enforced
    • enums are an afterthought and values in them cannot even be declared without assigning them some value. enums don't even really exist and are just classes with named fields
  • docs are for some reason available at runtime and can be viewed with help(element). this is really strange. docs should not be able to affect the program in any way. this allows to use them as data, which should not be possible
  • strings can be evaluated as code, encouraging spaghetti
  • the command line interpreter literally trolls you when you wanna exit instead of just exiting. when you type exit you get Use exit() or Ctrl-Z plus Return to exit

my conclusion is that python is usable for small scripts but completely unsuited for bigger projects

however, there is still often a better alternative

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment