What if your code is ugly but it works? Amateur python programmers journey.

For simplicity I will refer to Hive as rebranding of Steem and when I say Hive I mean its entire history even before HF23. Yesterday I received a comment from @hivebuzz by @arcange that reminded me I have been on Hive for 3 years. I have been on the blockchain for 3 years. Time flies indeed.

happybirthday.png

Hive has many features that attract people like myself. Among them is learning new skills. If you have been following my posts recently, you would know that I like writing codes in python to automate things. But you may not know that I have become familiar with Python and started learning how to code is here on Hive.

My early days on Hive were heavily involved with Curie and curation. As soon as I discovered Curie, I was more interested in curating than blogging. Not everybody have blogging skills. But luckily Hive is not only about blogging. I have made many friends among curators who would spends hours on daily basis to find talents and makes sure they get rewarded handsomely.

One of the curators, @locikll introduced me to python. Initially I wanted to learn more python to make curating more efficient. Curating the entire blockchain involves a lot of repetitive moves. Combining automation to discover brilliant posts makes the process more efficient. Later, I was introduced to HiveSQL by @carlgnash and @markangeltrueman. Back then HiveSQL was affordable for an average curator. It might be a bit more expensive these days. It has always been a joy to use HiveSQL combined with python.

Let me explain just to give an idea how one of my codes would help with curating. I have python code that would utilize HiveSQL. I would run it on a daily basis. It would filter out the posts that are most likely to be quality posts. But still return about 400-500 posts. Then it would open up 50 tabs at a time with all the posts. I would go through every single tab manually, read, evaluate, and keep the ones I would consider for suggesting for Curie. Utilizing shot-cut keys to close the tabs and move to the next one would also speed up the process. In no time I would be able to go through about 500 posts. Submit the ones I chose to Curie and move on the next day of curation. Later, I even purchased a special mouse, that I used for curating. It is a ring mouse with some keys that can be assigned to certain function.

As I was exploring python and learning more, I wrote some bot codes for Steem.chat and later for discord. None of those projects were completed. But they worked for a certain time period as intended. The problem I constantly keep facing is the ugly code. Even if the codes work well at the time they are needed, over some period of time they become unusable, because I don't know what their functions were and they were not written in a fashion to be reused.

The reason is simple. When I start writing a code, initially I try to plan to make it reusable in future codes, organize it a little bit. But once codes starts getting longer, more complicated, I find myself rushing to finish and keep getting various errors. Whenever errors occur, there is always a simpler approach to take, that is simpler, sort of a patch, but ends up making code hard to read when revisited at a later time.

If you have been following my automating Stock Prices Traders Diary blog posts recently, you would know that I was working on automating record keeping of watched stock prices. Today I was able to finish the project. But end result ended up being an ugly code. But it works.

What do I mean with an ugly code? It is a code that if someone else read it probably would be confused and decides that it is more efficient to rewrite it from the scratch. Not only that, it is a code that I myself probably would have hard time understand what I was trying to do when I read it a month from now.

I was able to finish the project and get the code to work as intended. For that to happen though I had to compromise, make patches to fix errors, and not organizing it well so it can be reused in the future. I do see a lot of potential in the skills I learnt though, and I believe they will help me develop more based on them. Maybe I will revisit this code and improve to make it more readable and reusable in the future. For now, I will keep it, as it fulfills the functions I need.

I will attach the screenshots of the code below. You be the judge how ugly it is.

uglycode1.png

uglycase2.png

unglycase3.png

H2
H3
H4
3 columns
2 columns
1 column
Join the conversation now
Logo
Center