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

in LeoFinance3 months ago (edited)

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.


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.




Posted Using LeoFinance


I recently found I had my PhD C++ code on my laptop (I hadn't thought I still had this). It was written on a Silicon Graphics machine in the late 90's. That code formed part of my PhD thesis and even though I was a Physicist working in a Physics department, because I used C++ instead of Fortran my boss had me defend my thesis in front of a full on Computer Science Prof. My code was OK but not cutting edge... I scrapped through that bit but thank heavens my code was well commented!

Finding lost/old works is amazing. It is like a treasure you never valued before. I didn't know you were a physicist. That is awesome. I think physicists are among the smartest people we have.

Once I tried to read the C++ book, I gave up in couple of days. That's why I like python. Much simpler than any other programming languages and can get simple tasks done.


It's pretty cool that you got paid to hang out on a social network while you learned all this

Ugly code? I didn't think it was too bad.... until I got to col_letter 😂

Thank you. Actually, things started not working right after col_letter. I just kept changing until it started working. :)

I have skillz.

Congratulations on 3 years!

Thank you @enjar! Friends like you made this journey fun. You are awesome!

What can I say, your journey has been amazing so far, I mean you were huge on the chain then with curie and I think I remember vividly then as well. What can I say but congratulations my friends it's been a splendid 3 years on the chain for you.

Thank You @josedicuss!

You're welcome, looking forward to your 4th year

Happy Hive Birthday @geekgirl (sorry being a bit late)

Thank You.

You start with a dirty code and once is working you do the optimizations. Functionality before the performance I think is a natural way of doing things.

Coding is a tough job. But in my opinion if one can write ugly code he can write efficient code. All the thing required is passion and little efforts. Thanka for sharing your experience with codes.
Your post has been curated with @gitplait community account because this is the kind of publications we like to see in our community.

Join our Community on Hive and Chat with us on Discord.

I am not much of a coder, but I found your article very interesting. Keep at it and you will get better! Try something new every day and don't be afraid to make mistakes! That is how we learn.


Good luck in your journey to becoming a Python Expert. This skills do not die but it keeps evolving overtime because it is open source indeed. Best of luck to you my friend, see you on Twitter Hustling! 🤗❤💯

Thank You.

Ugly code is fine as long as no other person will be tasked to maintain or upgrade the code. I make sure I comment a lot on my code because that "other person" could be future me lol.