Friday, 16 October 2020

Lab 4 - More Python Nightmares

 


Hello my fellow programmers/coders/readers... ah w.e.

Just an update on my academic career, or mainly my open source endeavors.

Now I know I said this in my past blogs, You've been following right??, but I absolutely hate Python. I don't know what it is the Snek is just not compatible with me.

So WHY for the love of god did you choose to work on Python again, you ask? Well, the answer is quite simple because I am a loser work well with my friend @chris. Mainly because I like his coding style (similar to mine) and his bald head

Anyways, this week in my open source dev class we had to pick someone else's previous 0.1 release and implement a rather easy but tricky feature to their program. We had to implement a feature that reads a text file and scans links to be ignored from a file or URL.

Alright, Cool! I've worked on Chris' code before this should be a light summer breeze. Boy little did I know that Chris wanted me to do a lot more than just implement this feature...

My guy basically wanted me to restructure his whole program to look cleaner.
Yeah... good times. But, w.e. I told him I'd do it and I am a man of my word.
He had this gigantic code block that was an eye sore. 

This was the first thing I did. I made different functions that were called and outsourced a lot of the work for each type of link with a specific status code. In a sense it is not more modular (I should probably make my code as neat as his TBH! But... then again who really cares).

Once that was done, it was time to get back to the issue at hand. My initial step was to add a "-i" argument option for ignoring links from the file specified.
Super easy. I wish Java had something similar of how it handles arguments. I had to write the following to the "-i" argument option: "nargs=2, action='append' " nargs allows me to take in multiple arguments with a single option. Neat! Yet again Python proves to be superior than Java.

*Actual representation of me dying on the inside*
The other option I had to handle was "concatenating" the arguments into a single list/array. This is done by the " action='append' " pretty self explanatory.

The actual file checking of the links was not that hard to implement. A basic try and catch.
  • Try to open file
  • if file opens call regex function to search for links that do not start with a "#"
  • return array if it found any links

I actually contacted Chris and asked him how he would like me to handle the removing the links that were to be ignored. He told me he would like to continue using BeautifulSoup

In all honesty, that actually made my life much easier, as I did not have to use a separate function for checking links. I simply modeled the checker around his old function.
That's it. I didn't really have any issues with the implementation, more the cleanup... (Damn it Chris)

The second part of the lab was to Review and Test the the code via Remote. so I did just that
I reviewed the feature that Chris had worked on for me and I was thoroughly impressed.
lol O.o
I did not have any issues or remarks towards his code. I am actually thinking of refactoring all those nasty if conditions to match his style of logic (as mentioned earlier, "cleaner"). 
For real, Great job as per the ujee.

I merged the code and to my favor there was actually no merge issues. 
Sweet! 
I honestly learned more about Python from this lab than about git. It's a neat feature but I would find it easier to make a pull request via github than on bash/cmd. 

Till next time, 
XOXO,
Gossip Plamen

No comments:

Post a Comment

Release 0.4.3 - The End of Something Great

  Hello my wonderful followers! It is here... It is finally here. The end of this nightmarish semester is finally here. I have to say the pa...