Skip to main content

Featured

Space Explorers Book 7: Answers and Explanations

Memunic Space Explorers › Book 7: Memoon and the Search for Another Home › Answers and Explanations Answers and Explanations Habitable means life could live there; inhabited means life does live there. A world can be habitable and empty, as an unoccupied flat has a roof and water but nobody in it. The Moon has almost no air, so water would boil or freeze, and its gravity is only about one-sixth of Earth’s, too weak to keep air. Accept also: no greenhouse blanket, so it swings between very hot and very cold. Venus. It matches Earth in size and roughly in mass, but its thick carbon dioxide air traps heat, making it hot and crushing. “Twin” is only true for size and weight. A dip of 1 per cent means (planet width divided by star width) squared is 0.01, so the ratio is 0.1: the planet is about a tenth as wide as the star. Repeats at the same gap show the planet is going round the star in 12 days, and rule out a one-time event such as a passing object. A planet shines only by reflected l...

Byte by Byte Book 8: Chapter 1 – How Code Runs: Compilers, Interpreters and Paradigms

Byte by Byte › Book 8: Real-World Coding, Data and AI › Chapter 1: How Code Runs: Compilers, Interpreters and Paradigms

Chapter 1: How Code Runs: Compilers, Interpreters and Paradigms

Illustration from Byte by Byte Book 8: Chapter 1 – How Code Runs: Compilers, Interpreters and Paradigms

🔎 The Case

The Makers' Summit opens in Cloudhall. Frost projects a list of problems onto the glass wall: Kachui's riverbank floods without warning, Simbha's Games booking desk is chaos, the Truth Desk is drowning in reports. Then Glim walks in, holding a scroll. "I wrote a program," he says, "in a language nobody else here uses. Your machines can't run it." Vega tilts her head. "Every language can run. You just need the right translator." The first job of the Summit: understand how code written by people becomes something a machine can execute.

💡 The Concepts

Machine code. A CPU only understands machine code: binary instructions specific to its type of processor (its instruction set). Writing in binary is slow and error-prone, so people write in high-level languages such as Python, JavaScript and Java, which use words and symbols close to English and maths. Assembly language sits in between: short codes such as MOV and ADD , one per machine instruction, converted by an assembler.

Translators. High-level code must be translated into machine code. There are two main ways:

CompilerInterpreter
How it worksTranslates the whole program first, producing a separate executable fileTranslates and runs one statement at a time
Speed of the finished programFastSlower
ErrorsReports all errors after compiling; nothing runs until they are fixedStops at the first error it reaches
Need the source code to run?No, only the executableYes, every time
ExamplesC, C++, GoClassic Python, JavaScript in older browsers

Many modern languages mix both. Java is compiled into bytecode, a halfway code that the Java Virtual Machine (JVM) runs on any computer. This is why Java's motto is "write once, run anywhere". Python also compiles to bytecode behind the scenes before its interpreter runs it. Modern browsers use JIT (just-in-time) compilation to make JavaScript fast.

Kinds of errors.

  • Syntax error: breaks the grammar of the language (a missing bracket). The translator catches it.
  • Runtime error: happens while the program runs (dividing by zero, opening a missing file).
  • Logic error: the program runs but gives the wrong answer. Only testing catches it.

Programming paradigms. A paradigm is a style of organising a program.

  • Procedural: a sequence of steps grouped into procedures (functions). You did this in Books 6 and 7.
  • Object-oriented (OOP): programs built from objects that bundle data and behaviour (Chapter 5).
  • Event-driven: code waits and reacts to events such as clicks and key presses (Chapter 4; Scratch's "when this sprite clicked" in Book 4 was event-driven).
  • Declarative: you describe what you want, not how (HTML, CSS and SQL are declarative).

Most real languages are multi-paradigm: Python and JavaScript support procedural, object-oriented and event-driven styles.

Real World: Your phone's apps are mostly compiled for its processor (ARM). The same Java or Kotlin code runs on thousands of different Android phones because of a virtual machine layer.

🛠️ Build It

  1. Open Google Colab, click New notebook, and run:
import dis
def add(a, b):
    return a + b
dis.dis(add)

You are looking at Python bytecode: lines such as LOAD_FAST and BINARY_OP . This is what the Python interpreter actually runs.

  1. Make three errors on purpose and name each type:
print("Summit"          # 1
print(10 / 0)           # 2
average = 10 + 20 / 2   # 3: we wanted the average of 10 and 20
  1. Open Edge, press F12, choose Console, type 2 + 3 * 4 and press Enter. You just ran JavaScript through the browser's built-in engine.

✅ Case Closed

Glim's scroll is written in an old language called Pascal. Frost finds a Pascal compiler in Cloudhall's archives, compiles the scroll into an executable, and it runs. Glim's program is a flood-gauge reader for Kachui's river. "I broke things for long enough," he mutters. "I want to build one." Memoon decides to give him a chance, and to test his code properly.

❓ Test Yourself

  1. Why can't a CPU run Python code directly?
  2. Give two differences between a compiler and an interpreter.
  3. What is bytecode, and what runs Java bytecode?
  1. Classify each: (a) pritn("hi") (b) a program that calculates area as length + breadth (c) a program crashing when a file is missing.
  2. Name the paradigm: (a) a button that plays a sound when clicked (b) an HTML page (c) a Dog object with a bark() method.
  3. Challenge: Fix the three errors in Build It step 2 so the program prints the correct average.

📚 Key Terms

machine code · instruction set · assembly language · assembler · high-level language · compiler · interpreter · executable · bytecode · Java Virtual Machine (JVM) · JIT compilation · syntax error · runtime error · logic error · paradigm · procedural · object-oriented · event-driven · declarative · multi-paradigm

Keep learning with Byte by Byte

Explore Book 8: Real-World Coding, Data and AI. Find the ebook, purchase details and teaching slides on MemuniCity.

Watch this chapter on YouTube

Comments

Popular posts from this blog

CA-7 Job Status and Failure Reason Codes

Here are the various status codes that You may see for jobs in the Queue or Logs in CA-7. R-C0002 R-C0003 R-C0099 R-C0255 R-JCLER A-U0002 A-U0004 A-U0015 A-U0043 A-U4095 A-SOC7 A-U4000 Reason Code/Job Status Code explanation: The indication of the job's current disposition. Values and their meanings are: A-Snnnn-- The job has failed with a system abend. A-Unnnn --The job has failed with a user abend. C-Cnnnn --The job has completed successfully and is going through completion processing. E-ARFATT-- An error occurred during the attempt to attach ARF definitions. This can result if the ARFSET specified is not defined. A diagnostic message may have been written to the CA-7 log, the OS console, or to the trailer queue for the job (in which case it can be displayed using LQ,JOB=x,LIST=ALL). E-ARFERR ---The job encountered an error in the ARF processing. Do a LARFQ command for the job to get more specific information. E-SEGERR --The job has been requeued...

Whistling Winds and Waterfalls: 4 Days of Magic in Shillong

Nestled in the clouds, where the scent of pine trees mingles with the rhythm of waterfalls and the tunes of local guitar-strumming youth—Shillong is more than a place. It’s a vibe. If you’ve got 3 nights and 4 days, you’ve got just enough time to fall in love. Here’s how to make the most of it—food, fun, fog and fantastic views included. Day 1: Shillong, We’re Coming for You! You land in Guwahati, barely out of the airport when the hills start calling. You hop into your cab, Spotify on, windows down, and the three-hour ride to Shillong begins. Just when you think it can’t get better, you stop at Umiam Lake —a lake so calm, it looks like someone ironed the water. By evening, you’re sipping hot chai in Laitumkhrah, maybe nibbling on spicy momos or pork jadoh from a roadside stall. You’re checked into your charming hotel ( Tripura Castle if you fancy old-world royalty, Ri Kynjai if you’re into lakeside poetry). The breeze whispers secrets of waterfalls and pine forests. Sleep well, drea...

Installing and Configuring Hadoop on Ubuntu as a Pseudo Distributed Single Node Cluster

Briefly what is psuedo-distributed single node Hadoop cluster: It is a Hadoop distributed cluster having Single Node. All the five daemons (NN,DN,JT,TT,SNN) are running as individual JVM (java process) instances. We will get all distributed features of Hadoop. This mode is used to develop, test, and staging (before production) Map Reduce programs quickly. It writes all the system, daemon and user logs to different files on the cluster To install Hadoop in this mode, we have to modify the hadoop-env.sh, core-site.xml, hdfs-site.xml, mapred-site.xml. hadoop-env.sh contains all the Environment variables which are required for running Hadoop. All the default values are fine, Only we have to modify the JAVA_HOME=“The location of Java Home Directory” Core-site.xml contains all the cluster specific information like io, temp directory, sorting, file system uri etc. Hdfs-site.xml contains all the parameters which are specific to HDFS like name node directory, data node directory...