pySearch Dev Log: Acting as a Maintainer for the First Time
When I first started programming one of the very first lessons I learned was “get familiar with the command line it’ll be your best friend” and while I didn’t believe it at first this statement has definitely proven true on multiple occasions and this is especially true when I’m using OSX or Linux considering these OS are built on top of Unix which was designed with the command line interface in mind. When I started programming I didn’t why people appreciate the command line interface until I was forced to develop using mostly CLI for a month and for someone who previously tried to avoid CLI like the plague it was definitely an interesting experience. That said, I think my biggest takeaway from the entire experience was how much time I lost switching between every time I moved my hand off the keyboard to navigate with my mouse and vice versa. I would type something, take my hand off the keyboard to use my mouse and go back to the keyboard to type a command. This was especially evident when I started using Git as every time I didn’t know the user of a command or forgot a command I would pull up my browser, google the command and then test in the Terminal.
I started learning Python around the time I started learning Git as I wanted to contribute to an open source project. I was following the Python documentation which introduces you to a lot of initial concepts through examples that you can run through the Python interpreter’s interactive mode. Long story short, my initial Python and Git experience was a lot of learning while doing and a LOT of back and forth between my Command Prompt, Git Bash and my web browser for Google, Stackoverflow and Python documentation.
During the development process of my contribution I kept thinking “wouldn’t it be nice if I could just do a Google search in my command line?” because every time I did a search I would take my hand off the keyboard to use the mouse twice, once to open the browser and then again when I’m selecting my search result. But if I could initialize a search though CLI I would only need to take my hand off the keyboard when I’m selecting my result. Thus the idea for pySearch was born.
The initial iteration of pySearch was 60 lines of Python code which simply used command line arguments to build a query URL which is opened in the system’s default browser.
pySearch sat dormant for roughly a year. There wasn’t a lot of movement after the initial proof of concept was created. This changed after I pitched pySearch as an open source project that could be used for Seneca’s Topics for Open Source Development course. As the creator of the project I took the maintainer role and started filing issues.
Tests are Important
The first pull request for pySearch that came in was a PR that added support to open multiple searches at once. This functionality was simple enough to test and considering pySearch is a simple script which just takes the user’s query with the option to define the search engine and search engine’s domain used to create the query URL there shouldn’t be much to test. What could go wrong?
Famous last words. I tested pySearch and the changes made in the PR seemed to work. Nothing breaks when I try performing multiple searches and even when I tried edge cases which could break the code if the arguments weren’t handled correctly but none of that occurred. So I thought it was safe to merge the PR. Needless to say mistakes were made.
The changed where the Search object was initiated and the ordering actually meant the command line arguments which handled the search engine and the domain were actually ignored. This was an easy mistake that could have been easily avoided with tests but pySearch was made when I first started learning Python and never in my wildest dreams would I have imagined that such a simple utility could use tests to verify it’s functionality.