The philosophy of programming: Logical thinking-good software

Programming is the new literacy. But how do we write good programs? Here are the recurrent questions we need to solve:

  • How do we come up with algorithmic solutions to a problem?
  • Then, how do we know the solution actually works?
  • Even if we’re sure it works, how do we tell the computer to execute it?

Fun fact — if you have hard time grinding any of these questions, you are actually doing philosophy.

To see why, let’s examine some interesting similarities between programming and philosophical reasoning. what is computer science all about computer science course computer science requirements computer science subjects computer science

The first principle: you have to think hard.

Computers do nothing smarter than we can do — the difference is, they do it with faster speed.

But they cannot solve an actual problem like “how do I get to my office from home?”

An effective method can (in principle) be carried out by a human being unaided by any machinery except paper and pencil.

— The Church-Turing Thesis

The merit of programming still lies in the reasoning part. That is, translating a real world problem into simple instructions that a computer can execute.

Of course, different programming languages have different levels of semantic abstractions. A Python program might be shorter than its C counterpart. But that just changes the amount of translations. We cannot get rid of the translation work. But we’ll leave this discussion for later. what is computer science all about computer science course computer science requirements computer science subjects computer science

A programmer’s reasoning flow

Now we are staring at some problem description. We may first look for small-scale input-output examples to understand the problem:

Induction. We need an algorithm that can handle such examples. Now you are doing induction: generalizing principles from experience.

Deduction. How do we know if it works for other unknown input? We do deduction to prove the correctness of our algorithm.

Ontology. We have to maintain data in computer memory. The goal is to make them efficient for the computers to process. In order words, what data structure can best capture the dynamic flow of my information?

Induction again. Then comes the very final stage: debugging. We induce the buggy part of the program from analyzing the unexpected outputs. what is computer science all about computer science course computer science requirements computer science subjects computer science

An example

Now let’s examine the above process by following this real example: finding the shortest path from vertex A to vertex E.

A simple map. Numbers denote the edge distance.

For small scale problems, we can solve them by instincts. Like, it’s very straightforward for us to recognize the solution A-C-E just by looking.

But what about more complex topologies? What about different edge weights?

We need help from computers. Yet it’s not straight forward to tell a computer what to do. There is a gap between how humans think and how a computer works. what is computer science all about computer science course computer science requirements computer science subjects computer science

Prev1 of 6

Leave a Reply

Your email address will not be published. Required fields are marked *