DEV Community

CS50 Week 1 - Learning C

Emilie Ma on July 09, 2020

This post is edited from my original blog post. Find it, and other posts by me on kewbish.github.io/blog. Introduction Well, it's been ...
Collapse
 
bradwellsb profile image
Bradley Wells

C has its place, and it's super fast for those things it should be used for, like numerical analysis (estimating the solution for a partial differential equation, for example). I wouldn't want to attempt that using a higher-level language!

Collapse
 
kewbish profile image
Emilie Ma

Definitely true!

Collapse
 
paramsiddharth profile image
Param Siddharth • Edited

I did the course a few weeks ago. It was one of the best ones I ever did, and I miss it now that it is finished. :) It was a great learning opportunity, but sadly, I don't have a PC, so I did it all on my Android phone using Termux and Acode.

I just love the idea of C! I perhaps have a long way to learn more of it, but the very realization that beautiful languages like Python and Java were written in C intrigues me. C is very powerful.

P. S. It is known that the creator of Python, Guido van Rossum, didn't add pointers in Python because he found them quite difficult to handle and believed that they made coding difficult for the programmer.

Collapse
 
kewbish profile image
Emilie Ma

That's crazy that you managed to do it all on a phone - props!
I definitely agree about the wonder that Python is written in C, looking further into C has made me appreciate Python a lot more.

Collapse
 
pentacular profile image
pentacular

C is all about fixed length arrays accessed by indexes called pointers.

// Variables are effectively stored in arrays of length one.
int i = 1;

// Let's get a pointer to the array element that i is stored in.
int *a = &i;

// Now we can modify i through the pointer into the array it is stored in.
a[0] = 2;

// Just like with an explicit array.
int q[4];
// But the array evaluates to a pointer to its first element.
int *r = q;
// But the elements are modified in the same way.
r[0] = 1;
// Since the array evaluates to a pointer to its first element we can skip using r.
q[0] = 2;
Enter fullscreen mode Exit fullscreen mode

C is reasonably simple once you understand that it is:

  1. All about arrays.
  2. A primitive language designed to make mediocre compilers easy to implement.

Point 2 is why C is so wide-spread -- writing a shoddy C compiler is very easy, so there are shoddy C compilers for pretty much everything.

Writing a good optimizing C compiler is quite difficult, so it took considerable time for C implementations to become competitive with assembly.

Collapse
 
darkwiiplayer profile image
𒎏Wii 🏳️‍⚧️ • Edited

Writing a good optimizing C compiler is quite difficult

Still infinitely easier than for something like C++ though, which means there's not only more bad compilers but also better good compilers.

Also, to expand a bit on the array thing: that's actually a huge benefit when comparing to other languages, since arrays (unpartitioned, sequential bytes in memory) play very nice with caching, which has led to arrays performing better than other data structures even where it's counter-intuitive, like deleting elements faster than linked lists.

Collapse
 
kewbish profile image
Emilie Ma

Thank you for the in-depth comment - I'll be sure to keep this in mind in the coming weeks 😄

Collapse
 
pmpn8ez profile image
pmpn8ez

I blew through this course myself recently, very well done. I agree with you on the IDE was easy and handy for submitting/checking but not as keyboard friendly as visual studio/vscode.
Decent examples, not too boring (unless you do the web path....) made it a great use of time. I took about 2ish weeks to do the whole course including the android/ios and game tracks. Currently working on the follow up game design course

Collapse
 
kewbish profile image
Emilie Ma

I was planning on doing the web path actually - what did you find boring?

Collapse
 
pmpn8ez profile image
pmpn8ez

I found the whole make a "homepage" a little outdated and had little interest in writing a stock market app. I liked the instructor the least as well out of the 3. I watched and followed along with the lessons but did not do the assignments.

Thread Thread
 
kewbish profile image
Emilie Ma

Ah, I'll keep that in mind!

Collapse
 
monicamakes profile image
Monica

This course is so fun (and challenging!), enjoy the ride.

Collapse
 
kewbish profile image
Emilie Ma

Definitely will!

Collapse
 
natyekennedy profile image
Kennedy Tariah

Hello there, thanks for this piece.
How did you get C to run in VScode?

Collapse
 
kewbish profile image
Emilie Ma

There's a C/C++ extension that I installed for linting and some useful snippets. Aside from that, I just set up a bash function with WSL to run clang and ran my binaries from WSL as well.