Understanding the basics of the programming world!

Wellington Martins dos Santos
5 min readJul 3, 2020

--

Computer Science course — Harvard CS50 (STILL WORKING ON IT)

Just to make it clear, this course has a part in C, and another in Python.

1 Advice for programmers — Make your code clear providing the main functions at the beginning of it.

2 Computers read the codes from top to bottom, left to the right. They are dump, therefore, you need to tell them what to do and how to do.

3 Each character, the number is a sequence of 0 and 1s, which have meaning for the computer. This is stored as bits, megabytes, etc.

4 When assignment something in a variable x for example, is common see something like x= 3. In cases of determining the equality between conditions like x is equal to y it is necessary to differentiate from the first example using double equal sign like this: x ==y.

5Understanding function is required for a programmer. To make it clear, when declaring a function, it is possible to set the wanted output and input. In this example, void test1(void) assigning the void into the function means that there is no input in this case.

void test1(void)

{

printf(“NO INPUT — CALL ME ONLY WHEN NECESSARY\n”)

}

In the function test1, the output will be an integer as defined; The inpute inside the function is not required.

int test1(void);

6 Boolean is a way to answer something which represents duality. For example, Yes or not, there is, there is not, x > y and so forth.

7 Loop provides the possibility to repeat an event. In an easier way to understand. Using Scratch.

A loop expression in Scratch.

while (true)

{

printf(“hello, world\n”)

}

You also can define the number of times which will be repeated.

int i = 0;

while (i<50)

{

printf(“hello, wolrd\n”);

i = i+1; #In here, you are addmin in the variable plus 1 to the variable i

}

8For loop provides the same output as shown in the last example, however, it has some different inputs in its functions — to be more precisely 3 inputs.

for (1st; 2nd; 3rd)

1th — Assign a variable or how it begins; 2nd — Boolean expression, what is the condition that will stop the loop; 3rd — Your update in the variable, when the condition is true, what will be changed?

for (int i = 0; i<50; i = i + 1)

{

printf(“hello, wolrd\n”);

}

Another example using for loop

for( int i = 0; i < 3; i = i+ 1)

{

printf(“cough\n”)

}

9 Tips to use if, else or else if. When you have two possible solutions. A program that defines if a number is even or odd there is a possibility to use if, else once your outcome has only two possibilities, this (if) or that (else).

if (n % 2 ==0)

{

printf(“even\n”);

}

else

{

printf(“odd\n”)

}

As else if it is a boolean expression, the following works, but it is not necessary.

if (n % 2 ==0)

{

printf(“even\n”);

}

else if

{

printf(“odd\n”)

}

In conclusion, programmers should be aware of their outcomes to avoid unnecessary code.

10 A double vertical bar ( || ) is a logical OR in programming languages like Python.

11 Check the following code — You will see that you have a function providing what the program is supposed to do and what function should be printed — cough(). Thus, as the function does not exist, it won’t work.

int main(void)

{

….for (int i= 0; i < 3; i = i + 1)

….{

….cough();

….}

}

To fix it, type down the function cough() before this code — this is not the best way to solve this problem — or include only part of it. The void will provide the program with a known function to run the code as shown down below.

void cough(void);

int main(void)

{

….for (int i= 0; i < 3; i = i + 1 )

….{

cough();

….}

}

{

printf(“cough\n”)

}

11 In the function below it is shown a better way to design code.

void cough(int n);

int main (void)

{

cough (3);

}

Check it out that the function wrote is calling cough() to provide an integer of how many times cough should be running. The idea here is that there is no necessity to know what is going on behind function cough(). This is a good design program — One line of code, it is descriptive — you know what will be done only by the name cough — , takes an input and what is down below is an implementation detail — You don’t need to see what is going on and re-invent the wheel again.

void cough(int n )

{

……for ( int i = 0; i< n; i++ | i = i + 1 )

# After | is another example of how to represent the i++

……{

……printf(“cough\n”);

……}

}

12.2 This is another example showed by the professor of good code.

int get _positive_int(void);

Int (Type of output), void (Type of input)

int main(void)

{

int i = get_positive_int();

printf(“%\n”,i)

}

int get_positive int(void)

{

# In this ca se, you have no input — int(void) — however, you need an output — int. So, you have a function with output but not an input.

…. int n; # This means,

“Computer give me a variable called n — I’m not sure what I’m gonna do yet”

…. do

….{

….….…. n = get_int(“Positive integer: ”);

….}

….while (n<1);

….return n;

#Do somenthing WHILE the boolean expression (n< 1) is true.

}

13 7–6–2020. Important note, I DO NEED to create each step to run a program, for instance, if printing a square, I do need to create a row and then a column to get the whole square.

while (n <1);

for (int i =0; i < n; i++)

{

…. for (int j =0; i < n; j++)

….{

….printf(“#”);

….}

….printf(“\n”); # Print a new line

}

14 Uou

>>Course dictionary<<

Correctness: The fact of being correct;

Funky: Mean fashionable, original, different in a good manner;

Thus far == So far;

Sake: Purpose of something — This is an example where for design’s sake.

Compelling: Adjective which gives strong evidence to believe — I got compelling evidence.

Constrains: To control or limit something you do — Eventually, you are going to run into some kind of constraints.

Nest: To fit one object inside the other— The column loop is nested in the row loop.

--

--

Wellington Martins dos Santos
Wellington Martins dos Santos

Written by Wellington Martins dos Santos

Sports Scientist, Physical Trainer so far but I still wanna be a Fitness Funcional Athlete and programmer — 27 years old

No responses yet