Hello everyone, and welcome to Part 2 of The Harvard CS50x Adventures. These blog posts are my journey into the world of computer science via Harvard University’s CS50 course on edX. I go through what I learn, the challenges I face, and how I overcome them as a complete programming newbie.

Last week, we started with Scratch, a visual drag-and-drop programming language created by MIT. It was fun learning the concepts and working through programming algorithms in my head as I created a game to bounce balls around. Make sure you check out Part 1 of the Harvard CS50x Adventures here.

Today, things start for real. We started Week 1 (Scratch counted as Week 0) of the course and jumped into the programming language C right away. So how did it go?

C, Old And Complex

Years ago, I was reading blog posts and articles about learning programming. There were always questions hello world c program

about what programming language one should start with.

“Which programming language should I learn first?” and there was an abundance of different answers.

  • “It depends on what you’re doing, front-end web probably requires Javascript, Android app development requires Java, data science can be done in R, and etc.”
  • “Start with an easy programming language like Python, so you can make something faster.”
  • “Start with C, because it is a difficult language that will force good coding practices from you. Plus, many other languages are based on C anyways.”

After reading some of these answers, I always got the impression that C was like the grandfather of programming languages. It’s an old and hard programming language to learn. Still, if you learn it, it will tremendously speed up the learning curve of every other programming language.

Same Concepts, New Language

I was slightly mistaken.

When I jumped into Lecture 1 and watched Professor Malan create some of the things we can do in Scratch in C, I realized that learning a programming language wasn’t the hard part. It was the concepts and problem solving that was the most important.

Sure, perhaps C has all these curly braces and semi-colons that you have to figure out, but it didn’t take long for me, and it shouldn’t take that long for you either. You just have to stop thinking about it too much.

The entire lecture was reasonably straightforward. It was mostly tackling concepts that we previously learned in Week 0 and how to implement it in C. For example, to make a forever loop, we use:

while (true)
{
action
}

One new thing, however, was the introduction of variables and all their types and formats, as well as how we can manipulate those variables with various mathematical operators, prompt users for data, and more.

There was also a section of the course where Doug Lloyd explains some of the concepts more in-depth, but I got the gist of it from the lecture.

Break The Problem Down

After the lecture was finished, I started Problem Set 1. The difference between Problem Set 1 and Problem Set 0 was that this time, I had a definitive objective I had to complete at the end.

There were three assignments (five if you decided to do both the hard and easy tasks, which I did) that I had to submit.

The first assignment was reasonably straightforward. All you had to do was use C to print out “hello, your_name,” which was already shown in the lecture. The other assignments, however, were much more difficult.

When I started looking at the comfortable version of Mario, I was already feeling overwhelmed.

“Oh my gosh, I had to create something that takes in a user’s input, the input has to be a number between 1 and 8, and then the program has to print a bunch of hashtags in a half-pyramid!”

I was already tempted to go on Google and find a solution to this problem that I could reference. Luckily I held that temptation in and moved forward.

It was good that they had a walkthrough breaking down precisely what you had to do. It made things a billion times easier for every single problem.

When I took the problem apart and started working on each puzzle piece, one step at a time, things became much more manageable. For the first Mario problem, the steps looked like this:

  • Create a function that takes user input between 1 and 8
  • Print hashtags
  • Right-align hashtags

When I broke it down, suddenly it wasn’t that difficult anymore.

Just Start Writing Code And See What Happens

One of the lessons I learned was that you seldom get it right on your first try, so stop trying to get it right on your first try. Just get into the code editor and start writing code.

Instead of spending all my time thinking and planning exactly what I had to code, it was much easier for me to just start writing code. The theory behind this concept is that if you don’t already know exactly what you need to do, you’re wasting your time planning.

By letting myself jump straight into writing code, I could experiment and see what happens. I spent about 30 minutes playing around with random loops and functions until the ideas really started coming to me. And that’s when I knew how to implement the solution to the problem in code.

Patience Is Key

patience quote

Additionally, patience is the key to your success. Going along with the idea that you’ll probably never get it right on your first try, you probably won’t get it right on your second, third, fourth, or even fifth try.

I remember playing around with the easy version of the Mario problem for quite a bit until I thought I came across the solution. When I typed in 4 and 8, it did exactly what I needed it to do.

Hooray! I did my little mini dance, and two victory laps around the house. Then I came back to my computer and used the check50 function to see if I satisfied all the requirements…

  • “Input of 1 did not get the expected output.”
  • “Input of 2 did not get the expected output.”

My eyes opened up in disbelief, and I looked at the problem set. What did inputs of 1 and 2 output?

Then I realized I had added spaces when I wasn’t supposed to. It wasn’t me forgetting a semi-colon or adding one too many spaces somewhere, it was a fundamental problem with my algorithms.

I was frustrated and again, tempted to look at solutions.

But I forced myself to stick it through. I was going to succeed this time. No more cheating.

So I sat down and looked at my code. Then I looked at the problem I was trying to solve, and I looked back at my code and started changing up various things. It took me about an hour of changing and testing until I finally did it. I coded something that satisfied all the requirements.

Combining all the problems together, I spent an entire 6 hours to code everything. But I did it. I solved all of the issues without looking at any solutions, and that’s a huge accomplishment for me.

What To Do If You’re Really Stuck (Without Cheating)

The Credit problem was the most challenging. I watched the walkthrough multiple times over, looked at the problem, read over the notes, and even watched some of the shorts. I just couldn’t figure it out!

So I began using the tools that I was allowed to use, like the CS50 Discord group chat. I went into the conversation reading what other people had to say about the problem.

Other people had trouble coding this problem as well, and they were sharing their thoughts and ideas about how to go about solving the problem.

Many of these people were talking about creating new variables within a loop, putting them in an array, and so on. That was how I was thinking as well, except the issue was, I had no idea how to implement this idea into code.

It’s when other more experienced members started giving feedback when I realized what was really wrong.

In reply to some of these complex ideas, other members said, “Yes, you could do this, or alternatively, do it with modulus functions.” And I realized something essential.

Excellent courses will never present a problem to you without teaching the skills needed to solve the problem. An excellent course will also give problems that required you to combine what you learned and use it in an intricate way to solve problems.

I had to limit the way I was thinking. I could only use code that I learned from the course. What I needed to do was combine what I already knew to solve this complex problem.

I looked at the stuff I already learned and started writing code. After around an hour or so of testing random bits of code, I found out that I didn’t need to make the code complex at all. No automation of creating new variables or storing them in arrays, all I needed was a formula and then loop the program to run for a certain amount of time.

And in the end, I solved it!

When you get stuck, don’t Google your issue or ask for feedback contrary to many people’s advice, look at what your course has taught you so far and think about how you can put simple concepts together to solve complex solutions.

If you Google your issue or ask for feedback, you might just get a bunch of even more complex answers using functions and code that you have never seen in your life.

Moving Forward!

Despite spending 6 hours coding, Week 1 of CS50x was honestly refreshing. Programming has become fun to me, and I’m excited about what I’ll be learning in the future!

I’ll see you soon for Week 2 and Part 3 of the CS50x Adventures.

If you haven’t read Part 1 of the CS50x Adventures, I highly recommend you do so. Additionally, if you have any questions or comments, don’t hesitate to leave them down below. I will make sure to respond!