My Second Month At The Alx Software Engineering Programme

My Second Month At The Alx Software Engineering Programme

INTRODUCTION

Hello everyone, I am George Nduka and you are welcome to the third instalment of my blog.

The workload for the second month of the ALX Software Engineering Programme was at least three times what it was in the first. In fact, when I look back at all the work I did, a part of me still finds it hard to believe how far I have come. A couple of months ago, I would never have imagined that I would be writing successful code and enjoying the process.

And it is not just software engineering, it is the friends I have made along the way from the most unlikely places, the network I have built, the discovery of my love for writing, the discipline I have been able to instil in myself, my new Twitter following and the ideas that are constantly bouncing around in my head, begging to be let out. I am certain even ALX students who transition into non-tech careers along the way will take something from this experience.

C PROGRAMMING

The second month was completely focused on C programming. Like a vast majority of ALX students, I constantly wondered why we were learning C. I did not know anyone who called themselves a C programmer and I had hoped that we would start with languages like JavaScript and Python. After asking the ALX mentors, I learned that C is useful for building a solid foundation for software engineering and gaining a comprehensive understanding of how programs operate. Since many languages are derived from C, it was essential for us to start our education from the source.

DATA TYPES AND VARIABLES

I became familiar with C by learning the fundamental topics that make up the language, beginning with data types and variables. A data type is essentially how data items are categorised. Humans are able to recognize “1” as a number and “A” as a letter and in this context, “number” and “letter” are types of data. Computers do not have this ability and they require information on what types of data we have included in our code.

The basic data types in C are:

  • int, for whole numbers e.g. 1, 35, 900.
  • char, for any letter, single digit number, space, punctuation mark, or symbol e.g. a, P, &, p, 2.
  • float, for numbers with up to 7 decimal digits of precision, and
  • double, for numbers with up to 15 decimal digits of precision.

Integers, characters, floats and doubles have to be stored in computer memory before they can be used. A variable is a container for storing data items at a particular memory location. It is a way to represent the location of data items so that they can be easily identified, much as how names are used to identify people.

To store data items, we need to specify its type and assign a variable to it:

int age;
// variable declaration
// 'age' is the variable
age = 5;
// variable initialization
char Grade = ‘B’;
// variable declaration and initialization
float average_score = 275.123489;
// variable declaration and initialization

FUNCTIONS

After figuring out data types and variables, I moved on to functions. I like to think of functions as formulae, a way of representing data with placeholders (parameters) until you are ready to switch them out. A function is a set of statements within curly brackets that takes inputs, computes them, produces output and can be used repeatedly.

The syntax for a function is:

return_type function_name(parameters)
{
    code to be executed;
}

The function below finds the sum of two integers:

int sum(int x, int y)
{
        int z = x + y;
        return (z);
        // the semicolon is used to end statements in C.
}

Every C program must have a main function. In the main function, our previously defined functions are invoked and parameters are switched out with real values (arguments).

int main()
{
        int first_sum = sum(2, 6);
        // The result of the above statement is 8 and is now the value of “first_sum”.

        int second_sum = sum(9, 4);
        // Result is 13.
}

STANDARD LIBRARY FUNCTIONS

Programmers in the past discovered that some functions were commonly used by everybody. Having to write the statements of these functions over and over was time consuming and programs usually contained many lines of code. Eventually, everybody’s favourite functions were collected into "header files". You did not have to write your own statements for these functions every time because they were already in the standard library.

For example, "stdio.h" is a header file that contains numerous functions, including "printf()" and "putchar()". printf() prints a string (a group of characters) while putchar() prints a single character. I simply have to include the stdio.h header file to use the functions in my program.

#include <stdio.h>

int main()
{
        printf("The truth will set you free");
        putchar('!'); 

        return (0);
}

Using printf() or putchar() without including the stdio.h header file will result in an error.

For someone like me who does not like stress, standard libraries are the answers to my prayers. So you can imagine how I felt when I learned that ALX denied us access to them 95 percent of the time. We had to create our own functions instead. I felt it was unnecessary having to forsake the blood, sweat and tears of programmers who had tried to make things easier for us and I complained to anyone who would listen.

However, my attitude changed when Phil, a friend of mine, offered his view on how we were learning the intricate workings of C, which we could apply to developing our own programming languages. That idea captured my attention because it followed the same logic as the reason for studying C. I began to see the benefit of taking the longer route.

CONDITIONAL STATEMENTS

I got a job as an architectural intern the same week I started at ALX. After my first day on the job, I realised that the internship and the ALX programme were both time intensive and I had to pick one over the other. I made my decision based on which career path I was more passionate about.

My decision can be represented by the following statements:

If I am more passionate about architecture, I will pick the internship.

Else, I will pick Software engineering.

Just like I was able to make that decision, we can allow a program to replicate human behaviour by instructing it to carry out certain actions, provided that certain conditions are met.

The function below prints out a certain string depending on whether the given number is positive or negative.

#include <stdio.h>

int main()
{
        int num = -5;

        if (num > 0)
        {
                printf("The number is positive");
        }
        else
        {
                printf("The number is negative");
        }

        return (0);
}

Since -5 is less than 0, the following result is printed out:

The number is negative

LOOPS

My music playlist is on a loop. Rather than having to press "play" anytime I want to listen to the next song, I can play one song and my music app goes through the playlist until the songs have been exhausted.

A loop is used to execute a block of code a number of times until a specific condition is fulfilled. The condition that ends the music playlist loop is "play the last song". In a sense, loops are shortcuts. They are an efficient way of compressing numerous lines of code into fewer lines.

For instance, I could use the following program to print all the digits from 1 to 9 on a single line:

#include <stdio.h>

int main() 
{
         putchar('1');
         putchar('2');
         putchar('3');
         putchar('4');
         putchar('5');
         putchar('6');
         putchar('7');
         putchar('8');
         putchar('9');

         return (0);
}

Evidently, I had to repeat the same line nine times, changing just the digits. Therefore, I will have to repeat the line a thousand times if I want to print from 1 to 1000. This is where loops come in.

The types of loops in C are:

  • While loop.

  • For loop.

  • Do while loop.

The syntax for a while loop is:

variable declaration and initialization;

while (condition)
{
        statement;
        increment or decrement variable;
}

The program below uses a while loop to print out digits one to nine:

int main()
{
        char i = '1';

        while (i < '10')
        // The condition is satisfied and the loop is started because i is less than 10
        {
        putchar(i);    
        // i is printed i.e. 1 is printed
        i = i + 1;
        // i is incremented i.e. i is now equal to 2
        }

        return (0);
}
  • The condition of the loop is checked again i.e. while (i < 10).
  • i, which has been incremented to 2 is still less than 10.
  • i is printed i.e. 2 is printed.
  • i is incremented to 3.
  • The loop goes on and on until i is no longer less than 10, i.e. i = 10.
  • Consequently, the loop is ended because the condition is now false.

The result of the program is:

123456789

ARRAYS

An array is a collection of data items of the same type stored in consecutive memory locations. The exam scores of ten students in a classroom can be stored in an array instead of in ten variables. The scores would be stored directly after each other in memory and accessed through the index of the array.

The index of an array is the position of each element in the array. The index starts from 0 to (size of array - 1).

The size of an array is the number of elements in the array. If there are ten elements in the array, the index starts from 0 to 9.

arrays.png

The syntax for an array is:

data_type array_name[array_size] = {elements};

The program below represents the declaration and initialization of the array in the picture above:

int main()
{
        int scores[10] = {60, 45, 79, 84, 66, 44, 23, 91, 50, 63};

        // array_name[index] represents each element of the array.

        scores[0] = 60;
        scores[1] = 45;
        scores[2] = 79;
        scores[3] = 84;
        scores[4] = 66;
        scores[5] = 44;
        scores[6] = 23;
        scores[7] = 91;
        scores[8] = 50;
        scores[9] = 63;

        return (0);
}

POINTERS

I live in a home, my home has an address and visitors can come to my home to find me. In the same vein, every data item in C has a variable and every variable has an address. A variable is a memory location and its value can be accessed through its address.

The address of a variable is denoted by the ampersand (&) operator, followed by the variable’s name. For example, the address of variable var1 is "&var1".

A pointer is a variable whose value is the address of another variable. Pointers are used to optimise programs to run faster or use less memory than they normally would. A pointer is denoted by an asterisk (*) followed by the variable name.

Here is how we declare pointers:

data_type *var_name;
  • int *age is a pointer to an integer i.e it stores the address of an integer.
  • char *name is a pointer to a character.
  • float *average_sales is a pointer to a float.
  • double *constant_value is a pointer to a double.

The following program uses a pointer to access the value of a variable and its address.

#include <stdio.h>

int main ()
{
        int  age = 20;
        // Variable declaration and initialization
        int  *ap;
        // Pointer declaration

       ap = &age;
       // Pointer variable is used to store address of age variable

       printf("Address of age variable: %x\n", ap);
       // Address of age variable is accessed using pointer variable

       printf("Value of age variable: %d\n", *ap);
       // Value of age variable is accessed using pointer

       return 0;
}

The result of the program is:

Address of age variable: 87115aac
Value of age variable: 20

%x and %d are called format specifiers.

Pointers can seem very complicated and I am still on the journey of learning them. Each time I think I have mastered pointers, something new comes up. The use of pointers is required in some capacity in almost every ALX task on C programming, so I would advise anyone just getting started to pay a lot of attention to pointers.

COMPILATION

Compilation in C is the process of transforming code we have written into machine-readable (binary) format. It is basically how we get the computer to read our code and generate output. An executable file is generated at the end of the compilation process and we can run the file to get the desired output of our programs.

Below are steps to create a C file named hello.c and compile it with the gcc compiler:

  • I create the file with vi editor.
$ vi hello.c
  • I input a program that prints "Hello World" into the hello.c file.
#include <stdio.h>

int main()
{
         printf("Hello World")

         return (0);
}
  • I compile the file with the gcc compiler.
$ gcc hello.c
  • An executable file named a.out is generated and I run it.
$ ./a.out
  • The output is printed.
$ Hello World

These basic C concepts served as the basis for everything we learnt during the second month, which included recursion, dynamic memory allocation, creating structures, static libraries, function pointers and variadic functions.

CHALLENGES I FACED DURING THE SECOND MONTH

THE PACE OF THE CURRICULUM

The curriculum of the second month was very fast paced. A project with a twenty-four hour deadline was typically followed by a peer learning day and then, the next project. So we usually had forty-eight hours maximum to learn new concepts. It was not ideal so I did not always follow the schedule. Rushing was not good for my mental health, so I completed the tasks I could, made sure I understood and moved on to the next.

DEBUGGING

I got errors in my programs frequently. One type of errors was compilation errors. Some were easily fixed, such as the omission of the semicolon at the end of the statements. Others were not easily fixed because the compilation error messages were diabolically hard to interpret. Google was my go-to in those situations.

Incorrect output is the other type of errors. My programs did not always print the expected answers and it usually took a while to figure them out. When I was not able to fix them, I had my friends help check my code because they could see things from a different perspective. Sometimes I took long naps, woke up with rested eyes, and was able to come up with solutions.

BETTY

Betty is a coding style guide for ALX. Many organisations have a consistent way of writing code and documenting . Betty helps to enforce that at ALX. There are rules on indentation, commenting, where to place braces, naming variables, header files and so on.

It is usually amusing to get a Betty error after working hard to successfully complete a task. We have taken to referring to Betty with the pronouns "she" and "her" because of her name. While conducting research for this article, I discovered that Betty was named after Betty Holberton, one of the six original programmers of the first general-purpose electronic digital computer, ENIAC.

DISTRACTIONS

Early in the second month, I started to get distracted by social media and thoughts I just had to put into action right away. I would be studying and all of a sudden, I would get the urge to Google something or check updates on Twitter and an hour would flash by in an instant.

I realised how bad it was getting, so I began to write down my ideas and I allotted ten minutes of free time to do whatever I had written for every thirty minutes spent studying. My strategy worked and distractions became secondary.

MY LEARNING ENVIRONMENT

My younger sisters, who are pre-schoolers, went on holiday halfway through the second month. It was fun having them at home, but the noise levels in our home skyrocketed. For someone like me, who needs silence to study, the environment was not conducive.

I later realised that by devoting my entire time to software engineering, I was indirectly teaching them to be self-absorbed. So I began to spend more quality time with them, and most of the time, I received peace and quiet in return.

FORGETTING PREVIOUS TOPICS

I found that I occasionally forgot concepts I had previously learnt. Other times, generally due to anxiety, I struggled to communicate my understanding to my peers. When it became too regular, I knew that I had to refer back to Feynman’s technique.

So I got a teddy bear that served as my own rubber duck, and I constantly explained concepts and code to it. The process compelled me to understand concepts at a deeper level because I had to come up with simple words to use while I was explaining.

THINGS THAT HELPED ME GET THROUGH THE SECOND MONTH

WEEKLY DOSES OF ART

I took up the hobby of watching Art related videos on YouTube. I was watching videos ranging from how a particular cartoon was made to fashion competitions. Watching creative people work helped me relax when I took breaks from coding.

Some of my favourite videos are:

READING

I am now of the opinion that if you can read documentation, you can read anything. I started subscribing to tech publications and reading random articles online. I finally caught up on the Flutterwave scandal and I was just as shocked in July as the world was in April. Reading has even gotten tech journalism on my "possible careers list" and expanded my mind.

Here are links to some of my favourite articles:

TWITTER SPACES

Twitter spaces are a way to have live audio conversations on Twitter. They connect tech professionals from all over the world and I have found them very valuable. They have been a source of education for me as I have gotten various pieces of advice on how to navigate the tech industry and what the real tech world is like. Listening to other Africans who have just gotten into tech, talk about their journey has also been very inspiring.

Here are links to recorded spaces I found very valuable:

CONCLUSION

The highlight of the month came when I attended ALX’s Expert session with Kuda Mangwe. One of the topics discussed was the acquisition of Holberton’s Technology platform by African Leadership Group, a company by Africans and for Africans, changing the face of software engineering education globally. Holberton is an American company and acquisitions like this usually happen the other way around.

The fact that Africa is now being acknowledged for its talent and potential suggests to me that we, the upcoming generation of software engineers, have the power to amplify Africa's voice in the global IT sector. We are not only talented, we are being forged by the fire of government policies and systems that try to stop us in our tracks.

I am confident that we will eventually lead firms like Meta, Amazon, Google, and Apple and even launch our own international companies if we continue to persevere and apply grit. Nothing will be beyond our reach as long as we keep showing up every day and putting everything we have into achieving our goals.

Thank you so much for reading. I would love to connect with you on Twitter and on LinkedIn. I hope to see you in my next article. Please, have a great week.

I am not affiliated with or endorsed by ALX. The opinions and views I share are purely my own.