Code makes the world a better place

How I Became Interested in Computer Science

I am currently pursuing a graduate degree in computer science at NCTU. Deciding to go down the CS path was a long process for me. This story starts from the very beginning and describes how my interest in computer science gradually took shape. Everyone’s story is unique; I hope mine can offer some inspiration and lessons for others.

Continue reading

Red-Black Tree (RBT) Introduction

Red-Black Tree Overview

A red-black tree is a special data structure that can automatically balance itself, similar to an AVL tree.

A red-black tree has the following properties:

  • Each node is either red or black
  • The root must be black
  • Every leaf (NIL) is black
  • If a node is red, its children must be black
  • Every path from the root to a leaf has the same number of black nodes

Following these rules ensures the tree stays balanced during insertions and deletions. A red-black tree guarantees that when the number of nodes is n, the height is at most 2log(n+1).

In practice, it is often used to implement sets and dictionaries. In C++, std::set and std::map are backed by red-black trees.

Continue reading

An Example of Signals with `sigaction` on Unix

There are many ways for processes to communicate on Unix. This post introduces a simple way to use signals. You can first read Beej’s introduction. As the name suggests, a signal is a notification sent and received by processes. For example, when you use a shell, Ctrl-C can interrupt a program because the shell catches the SIGINT signal triggered by Ctrl-C, recognizes it as an interrupt signal, and terminates the program.

To send signals, you can use sigaction() or signal(). I recommend sigaction because it’s newer. For a detailed comparison, see the Stack Overflow thread “What is the difference between sigaction and signal?”.

If you want to trigger a signal, you can use kill() or sigqueue(). The difference is that the latter is Linux-only, but it lets you attach additional information via siginfo. In addition, some system calls can trigger signals as well. For example, if you try to send() to a non-existent socket, you’ll get a SIGPIPE.

Continue reading

Using `mmap` to Create Shared Objects

When you have many processes and want to implement shared memory to handle shared data, you can use shared memory to build the solution. To create shared memory, you can use mmap or System V shmget. However, according to the Stack Overflow answer “(How to use shared memory with Linux in C)”, shmget is somewhat outdated, while mmap is newer and more flexible.

Shared memory allows us to create a region of memory that can be shared. mmap returns a pointer to that region, with type void *. If we want to put data into it, we can use memcpy to copy objects, strings, or anything else into the shared region. We can also cast the void * directly to an object pointer—this way we create a shared object, and different processes can access the object directly.

Continue reading

NTU Observations and Reflections (9): Senior Year (Spring) & Logging Out

This was my eighth semester at National Taiwan University (NTU), and also my last. For most people, senior spring is relaxed: they have already completed their credits and have no graduation pressure. But because I changed departments and kept taking courses in other departments, I still had not completed my credits by senior spring. Because of that, I still had 12 credits to take, and I still had to go to campus almost every day.

Overall, senior spring felt a bit absurd to me. It was as if I did not do anything particularly well, and there was not much I could be proud of. There were a few things worth being happy about, and a few setbacks that left a stronger impression.

Continue reading

A Junior Programmer’s Path to Growth

Notes, Summary, and Commentary on The Clean Coder


Recently, I finished reading The Clean Coder (Chinese title: “無瑕的程式碼 番外篇-專業程式設計師的生存之道”). It happens to answer one of the most common questions I see online:

What is the difference between a junior engineer and a senior engineer?

Continue reading

NTU Observations and Reflections (8): Senior Year (Fall)

My days at National Taiwan University (NTU) have entered the fourth year. Without noticing, there is only one year left on campus, and it makes me very reluctant to leave. From entering NTU from high school to being about to graduate, I have changed a lot—going from wanting to be a physicist to becoming a software engineer, and changing my favorite sport from swimming to tennis. I have gone through so many things that I often even forget that I once experienced them: GIS Taiwan, the Green Collar Agricultural Market, internships at multiple companies, and all kinds of talks, among others.

Continue reading
  • Page 1 of 1