Month 4, Battling with Tests and OOP

Month 4, Battling with Tests and OOP

A focus on test-driven development, writing object-oriented code, learning how to build sorting algorithms in C. The fifth month of ALX was extensive!

📅
Jan 2nd – Jan 29th

This month was a month of diverse learnings. Started out with learning how to write unit tests for Python scripts, to working on tasks that helped me understand objects and Object-Oriented Programming better. Delved into file handling in a Python script before moving on to understanding sorting algorithms; built simple sorting algorithms using C (also got introduced to the Big O notation!) The month ended with getting better at writing bash scripts through loops, conditions and signal handling.

TL;DR: Learnt about the importance of testing in programming, how to write test cases, and the different types of tests. Got a better understanding of objects and how inheritance in objects work. Worked on File Input/Output, learning how to create, read and write to a file through a Python script. Used C to build simple sorting algorithms (insertion sort, selection sort, bubble sort and others). Improved on my bash scripting knowledge by learning about loops, conditions and signal handling in bash.

Overview for the month

Month 4 started with a lot of focus on testing and how to test the Python scripts we write for our assessment tasks. Learnt on how to use the doctest and unittest Python modules to create test cases for Python scripts.

We then built on last month's knowledge of Object-Oriented Programming by learning more about Inheritance among objects and classes, and how to use that to share attributes among different object instances. Worked on using Python decorators to create static methods and extend the scope of functions without changing existing code.

After working with the new OOP concepts, we transitioned into interacting with files through Python scripts. This involved creating files, reading files and writing/appending content to files. Learnt on how to handle clean-up operations after working with a file, and the importance of providing encoding information for each file you want to work on.

The next topics required us to use the Big-O notation for calculating the time complexity of algorithms, and on learning the importance of sorting data that is being used in a software application. Learnt different types of sorting algorithms, their characteristics and time-space complexities, alongside situations where one will be preferred over the other. Built some simple sorting algorithms for unsorted arrays and lists with C.

The month ended with bash scripting, where we had to learn how to use loops and conditional statements (e.g. if-else statements) to improve the scripts we write for the Linux Bash. We also worked on handling signals, and using them to manage processes running on a Linux environment.

Key Concepts Learnt

Test-Driven Development

  • Importance of testing, different types of tests and how they can build on one another.

  • How to write test cases in Python. Using doctests for quick testing in Python scripts. How to write unit tests for a Python script using unittest, and common strategies towards handling testing for an application.

More Object-Oriented Programming in Python

  • Using static methods, and how they differ from class methods. Got introduced to using class decorators in Python.

  • Working on using magic methods like __str__ and __repr__.

  • Getting a better understanding of how inheritance works in objects (superclasses, parentclasses and baseclasses).

File Input/Output in Python

  • Encoding standards in files, and how important they are to computers understanding how to interpret a file.

  • Reading a file, writing or appending content to the file, handling clean-up actions after file operations are over.

  • Serializing data into JSON, and deserializing from JSON back to normal data.

Sorting Algorithms and the Big O Notation

  • The Big-O Notation and how it is used to calculate the time complexity of an algorithm. Also got to know about the Omega Notation, which is used to calculate the best case time complexity (Big-O Notation is for worst case.)

  • The importance of sorting data in an application, especially for searching operations or data retrieval. Different types of sorting algorithms, their time complexities, and if they are stable algorithms or not.

  • How to select the best sorting algorithm for a given input.

  • Learnt how to build four (4) simple sorting algorithms; bubble sort, insertion sort, selection sort and quick sort.

Advanced Bash Scripting

  • Improving portability of bash scripts across different environments and operating systems.

  • Learning about looping in bash scripts. while, until, and for loops, and how to use them in the scripts.

  • Adding conditionals in your scripts, using if-else and case statements.

  • Using file and comparison operators, using them for checks in conditional statements.

  • Using the cut command to parse text data in bash scripts.

  • Learnt about Linux processes, how to kill a running process, and using Linux signals (both signal handling, and using it to managing processes).

Summary

Month 4 was a LOT. From Python to C, to Bash Scripts, it was an all-rounder month. Learning how to calculate the time complexity of algorithms and working with sorting algorithms (though simple ones) was a big part of this month that I am so happy about, and I hope to be able to improve on my knowledge of using sorting algorithms as time goes. Next month is going to be our introduction to SQL, and I am super hyped to see how that will go.


Anyway, that marks an end to this month's review. Thank you so much for going through it, and I hope this one was (slightly?) better than the previous review for December. Your thoughts and feedback are always appreciated; share them in the comments.

So yea; sayōnara, ciao, [insert goodbye in your native language here], byee🫶🏾

🙃
"The more I C, the less I see" 🥲🥲🥲