Fundamentals 8 min read

What Is Programming? A Simple Introduction Using a Cooking Analogy

The article explains programming fundamentals by likening code to cooking, defining programming as algorithms plus data structures, illustrating basic concepts such as conditionals, loops, and abstraction through simple code examples, and emphasizing the difference between novice and expert approaches.

AntTech
AntTech
AntTech
What Is Programming? A Simple Introduction Using a Cooking Analogy

In everyday work, many technical colleagues enjoy sharing their insights, and this article is selected to introduce the basics of programming to a broader audience.

Programming, put simply, is the process of expressing what you want to achieve or describe through a series of logical steps so that it can be executed or visualized. More formally, programming can be expressed as:

编程 = 算法 + 数据结构

An algorithm is a method for solving a problem, a step‑by‑step description of the solution. A data structure is a way of organizing and storing data, like a bookshelf for books.

To make the concept concrete, consider the everyday problem of getting dinner ready after returning home at 5 pm so that the family can eat by 6:30 pm. Two possible algorithms are:

编程问题:17:00 回到家,怎么让家人在 18:30 之前吃上饭?
算法一:先煮上饭然后去买菜
算法二:买完菜再回来煮饭

We can model the cooking process as an object with methods:

做饭 = {
  煮饭() {},
  买菜() {},
  切菜() {},
  做菜() {},
}

The core of programming lies in how we structure these methods. A novice might write:

做饭 = {
  开始() {
    煮饭(); 买菜(); 切菜(); 做菜();
  },
  煮饭() {},
  买菜() {},
  切菜() {},
  做菜() {
    if (家里没有油了) { 买油(); 炒菜(); }
    else { 炒菜(); }
  }
}
做饭->开始();

An expert adds a checking step before buying ingredients, ensuring nothing is missed:

做饭 = {
  开始() {
    煮饭();
    检查结果 = 检查();
    买菜(检查结果); 切菜(); 做菜();
  },
  检查() {
    if (家里没有油了) { 买菜的时候要买油 }
    if (家里没有辣椒了) { 买菜的时候要买辣椒 }
  },
  煮饭() {},
  买菜() {},
  切菜() {},
  做菜() {},
}
做饭->开始();

This demonstrates that the expert’s program is more thorough, reducing missing steps and improving efficiency.

Abstraction further simplifies code. By defining a generic 做菜 method that handles washing, cutting, and frying, we can apply it to any dish listed in a menu:

做饭 = {
  开始(菜单) {
    煮饭();
    买菜(菜单);
    菜单->逐一(做菜);
  },
  买菜() {},
  煮饭() {},
  做菜(菜品) {
    洗菜(菜品);
    切菜(菜品);
    炒菜(菜品);
  }
}
菜单 = 辣椒炒肉、红烧狮子头、剁椒鱼头;
做饭->开始(菜单);

Without abstraction, the code becomes repetitive and verbose, as shown below:

做饭 = {
  煮饭() {},
  买菜() {},
  洗菜() {},
  切菜() {},
  做菜() {},
}
做饭->煮饭();
做饭->买菜();
做饭->洗菜(辣椒炒肉);
做饭->切菜(辣椒炒肉);
做饭->炒菜(辣椒炒肉);
做饭->洗菜(红烧狮子头);
做饭->切菜(红烧狮子头);
做饭->炒菜(红烧狮子头);
做饭->洗菜(剁椒鱼头);
做饭->切菜(剁椒鱼头);
做饭->炒菜(剁椒鱼头);

The article concludes that while programming itself is not overly complex, writing good programs requires solid algorithms, an understanding of execution environments, and the ability to handle changing requirements.

programmingsoftware engineeringData StructuresAlgorithmsbasicsabstraction
AntTech
Written by

AntTech

Technology is the core driver of Ant's future creation.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.