💾 Archived View for sud0nim.smol.pub › python-sucks-too-bad-its-great captured on 2023-09-28 at 15:54:22. Gemini links have been rewritten to link to archived content
⬅️ Previous capture (2023-01-29)
-=-=-=-=-=-=-
I had an assignment this week where we needed to generate mazes for an algorithm to solve. It was a demonstration on time complexity; with more possible spaces to move the execution time and work done increased exponentially.
In the video lecture, recorded two years ago, he said the maze needed to be 100x100. I didn't want to create a 100x100 2D array of 0s and 1s, building the maze, manually. I thought it'd be easier to write a script to convert a black and white image into the maze so I could draw it in gimp. I saw a video by "Films by Kris" that showed off the "convert" command from ImageMagick which allows you to convert an image to text. This is easier to parse since my graphics knowledge is limited.
Since python's dynamic types allows you to pretty easily parse text through converting it to a list, I decided to go with python for the script, though the maze solver is in C so I needed to format the output like a C array. Initially I wanted to create a 2d array (or list in this case since python), but then remembered that you can't easily declare an array of a fixed size in python like in c(++). I tried doing it with the line:
arr = [[]*100]*100
like how every guide online said to. Well when I printed out the list it was all 1s, not the maze.Then I remembered I ran into this problem a year ago when making a tic-tac-toe game for a homework assignment, Unless you manually make each separate "[]" it doesn't recognize these as separate list. This was easy to do for a 3x3 grid but 100x100 was way too much to type or paste out. I'm sure there is a way to make the [[]*x}*x method work but I had already put too much time into what was supposed to be a time-saving script. So I decided to just append a "1," or a "0," to an output string. This was really fast and easy to do, I should have just done this in the first place.
Turns out that the assignment only called for 10 10x10 mazes because the 100x100 maze takes forever to run unless you optimized his algorithm. 10 10x10 mazes are easy to make in a text editor, so the hour I put into the script could have been done in 10 minutes by hand *sigh*. At least I have a graphical representation of the maze I guess.
But this is an example of what I hate about python. Declaring variables before you use them allow you to easily allocate needed space. It makes a clear distinction between initializing and the reassigning the value. The .append() method is great when you don't know how many elements are going to be in the list, but for multidimensional arrays it is simply frustrating.
Then when I tried to modify the output string using the subscript notation (ie string[n]) it blocked it because strings are immutable! Why are strings immutable! this is a basic data type which is essentially an array of chars with a number of methods! The actual way they want you to modify specific chars is through concatenation of slices of the string! ridiculous!
Why does python feel like it needs to do everything different from every other programming language? code blocks being identified with curly braces works great, why does whitespace dictate code blocks? Indentation aids the readability without interfering with the actual code. Pasting code around doesn't become a headache, trying to match up the indentation level.
what was wrong with && and || for 'and' and 'or'? I prefer the former since variables clearly stick out as the only "words" in the line of code.
Python has great libraries and a low amount of boiler plate code. These are the only positives.
It's not a good 'first language' since then you have to unlearn all the pythonic ways of doing things for every other language. If it's not your first language then you end up trying to do things unpythonicly and get frustrated by the silly abstractions. The idea that the "normal" way of doing things is unintuitive for new programmers is a joke. Python was my first language and I tried doing things in the "normal" way and only later realized the frustrations I was having was because python wanted me to do it in the python way.
But damn it is easy to write. No need to keep track of pointers or care about return types. Runtime-errors are clearly articulated and easy to diagnose. Some of the abstractions are really useful and make tasks so much easier. The in operator is great.
So yeah I hate python, but it's the primary language I use. I also am a computer science major who hates technology so I guess it's only fitting.