Software Engineering Day 5 The Digital Craftsman: Introduction to Software Engineering Professional Program 55 min

Your First Program: Hello World

Lesson Objectives

  • Master core concepts of your first program: hello world
  • Apply the digital craftsman: introduction to software engineering principles practically
  • Connect material to Biblical stewardship and service
Scripture Reading: Exodus 31:3
"God filled Bezalel with skill, ability, and knowledge in all kinds of crafts — Exodus 31:3"

Prerequisites

This lesson builds on knowledge from these prior lessons:

Your First Program: Hello World

"Whatever you do, work at it with all your heart, as working for the Lord, not for human masters, since you know that you will receive an inheritance from the Lord as a reward. It is the Lord Christ you are serving." — Colossians 3:23-24

From Setup to Creation

Over the past four days, you have learned what software engineering is, how projects are planned through the SDLC, how to set up your development environment, and how to track changes with Git. Today, you finally get to build something.

But we will not merely type "Hello, World" and call it done. We will write a real, well-structured TypeScript program that demonstrates proper engineering practices: type safety, functions, clean organization, and automated testing. Every principle from this week will come together.

TypeScript Fundamentals — The Building Blocks

Variables and Types

In TypeScript, every variable has a type — a label that tells the compiler what kind of data it holds. This is like labeling jars in a pantry: the "flour" jar holds flour, the "sugar" jar holds sugar. If someone tries to put salt in the sugar jar, TypeScript catches the mistake.

```typescript // Declaring variables with explicit types const nameChirho: string = "Bezalel"; const ageChirho: number = 30; const isCraftsmanChirho: boolean = true;

// TypeScript prevents type errors at compile time // const wrongChirho: number = "thirty"; // ERROR: Type 'string' is not assignable to type 'number' ```

The three most common types:

  • string: text data enclosed in quotes (`"Hello"`, `'world'`, or backtick template literals)
  • number: numeric data, both integers and decimals (`42`, `3.14`)
  • boolean: true or false (`true`, `false`)

`const` vs. `let`

TypeScript has two ways to declare variables:

```typescript const VERSE_CHIRHO: string = "The fear of the LORD is the beginning of knowledge."; // VERSE_CHIRHO = "something else"; // ERROR: Cannot reassign a const

let countChirho: number = 0; countChirho = 1; // OK: let variables can be reassigned countChirho = 2; // OK ```

  • `const`: The value cannot be changed after assignment. Use `const` by default for everything.
  • `let`: The value can be reassigned. Use `let` only when the value genuinely needs to change.

Rule of thumb: Always use `const` unless you have a specific reason to use `let`. This prevents accidental mutations — a common source of bugs.

Functions — Named, Reusable Units of Work

A function is a named block of code that performs a specific task. Functions are the fundamental building blocks of well-organized software. Each function should do one thing and do it well.

```typescript // A function with typed parameters and return type function greetChirho(nameChirho: string): string { return \`Grace and peace to you, \${nameChirho}, in the name of our Lord Jesus Christ.\`; }

// Calling the function const messageChirho: string = greetChirho("Timothy"); console.log(messageChirho); // Output: Grace and peace to you, Timothy, in the name of our Lord Jesus Christ. ```

Anatomy of a function declaration:

  • `function`: the keyword that declares a function
  • `greetChirho`: the function's name (descriptive, camelCase with Chirho suffix)
  • `(nameChirho: string)`: parameters with their types
  • `: string`: the return type — what type of value the function gives back
  • `return`: the keyword that sends a value back to the caller

Arrow Functions

TypeScript also supports arrow functions — a shorter syntax for writing functions:

```typescript // Arrow function syntax const addChirho = (aChirho: number, bChirho: number): number => { return aChirho + bChirho; };

// For single-expression functions, even shorter: const multiplyChirho = (aChirho: number, bChirho: number): number => aChirho * bChirho;

console.log(addChirho(3, 4)); // 7 console.log(multiplyChirho(3, 4)); // 12 ```

Control Flow — Making Decisions

Programs need to make decisions. TypeScript uses `if`/`else` statements and other control flow structures:

```typescript function evaluateScoreChirho(scoreChirho: number): string { if (scoreChirho >= 90) { return "A — Excellent work! 'Well done, good and faithful servant.' (Matthew 25:21)"; } else if (scoreChirho >= 80) { return "B — Good work! Keep pressing forward."; } else if (scoreChirho >= 70) { return "C — Passing. Review the material and try again for mastery."; } else { return "Keep studying — 'Let us not become weary in doing good.' (Galatians 6:9)"; } }

console.log(evaluateScoreChirho(92)); // A — Excellent work! ... console.log(evaluateScoreChirho(75)); // C — Passing. ... ```

Arrays — Ordered Collections

An array holds an ordered list of values of the same type:

```typescript const booksOfMosesChirho: string[] = [ "Genesis", "Exodus", "Leviticus", "Numbers", "Deuteronomy" ];

// Access by index (0-based) console.log(booksOfMosesChirho[0]); // "Genesis" console.log(booksOfMosesChirho[4]); // "Deuteronomy"

// Loop through all items for (const bookChirho of booksOfMosesChirho) { console.log(\`Book: \${bookChirho}\`); }

// Array length console.log(booksOfMosesChirho.length); // 5 ```

Building a Complete Program

Let us build a real program that combines everything — a Scripture Memory Quiz. Create a new file called `scripture-quiz-chirho.ts`:

```typescript // For God so loved the world that he gave his only begotten Son, // that whoever believes in him should not perish but have eternal life. — John 3:16

// --- Types ---

interface VerseCardChirho { referenceChirho: string; textChirho: string; }

// --- Data ---

const versesChirho: VerseCardChirho[] = [ { referenceChirho: "Proverbs 1:7", textChirho: "The fear of the LORD is the beginning of knowledge." }, { referenceChirho: "Exodus 31:3", textChirho: "And I have filled him with the Spirit of God, with wisdom, with understanding, with knowledge and with all kinds of skills." }, { referenceChirho: "Colossians 3:23", textChirho: "Whatever you do, work at it with all your heart, as working for the Lord." }, { referenceChirho: "Psalm 127:1", textChirho: "Unless the LORD builds the house, the builders labor in vain." }, ];

// --- Functions ---

function getVerseCountChirho(versesChirho: VerseCardChirho[]): number { return versesChirho.length; }

function findVerseByReferenceChirho( versesChirho: VerseCardChirho[], referenceChirho: string ): VerseCardChirho | undefined { return versesChirho.find( (vChirho) => vChirho.referenceChirho === referenceChirho ); }

function formatVerseChirho(verseChirho: VerseCardChirho): string { return \`"\${verseChirho.textChirho}" — \${verseChirho.referenceChirho}\`; }

// --- Main Program ---

console.log("=== Scripture Memory Quiz ==="); console.log(\`Total verses loaded: \${getVerseCountChirho(versesChirho)}\`); console.log("");

for (const verseChirho of versesChirho) { console.log(formatVerseChirho(verseChirho)); }

const foundChirho = findVerseByReferenceChirho(versesChirho, "Psalm 127:1"); if (foundChirho) { console.log(\`\nFound: \${formatVerseChirho(foundChirho)}\`); } else { console.log("Verse not found."); } ```

Run it:

```bash bun run scripture-quiz-chirho.ts ```

Writing Your First Automated Test

"Test all things; hold fast to what is good." — 1 Thessalonians 5:21

Now let us write automated tests to verify our functions work correctly. Create a file called `scripture-quiz-chirho.test.ts`:

```typescript // For God so loved the world that he gave his only begotten Son, // that whoever believes in him should not perish but have eternal life. — John 3:16

import { describe, test, expect } from "bun:test";

// In a real project, these would be imported from the source file. // For now, we define them here to keep the lesson self-contained.

interface VerseCardChirho { referenceChirho: string; textChirho: string; }

function getVerseCountChirho(versesChirho: VerseCardChirho[]): number { return versesChirho.length; }

function findVerseByReferenceChirho( versesChirho: VerseCardChirho[], referenceChirho: string ): VerseCardChirho | undefined { return versesChirho.find( (vChirho) => vChirho.referenceChirho === referenceChirho ); }

function formatVerseChirho(verseChirho: VerseCardChirho): string { return \`"\${verseChirho.textChirho}" — \${verseChirho.referenceChirho}\`; }

// --- Test Data ---

const testVersesChirho: VerseCardChirho[] = [ { referenceChirho: "Proverbs 1:7", textChirho: "The fear of the LORD is the beginning of knowledge." }, { referenceChirho: "Psalm 127:1", textChirho: "Unless the LORD builds the house, the builders labor in vain." }, ];

// --- Tests ---

describe("Scripture Quiz Functions", () => { test("getVerseCountChirho returns the correct count", () => { expect(getVerseCountChirho(testVersesChirho)).toBe(2); expect(getVerseCountChirho([])).toBe(0); });

test("findVerseByReferenceChirho finds an existing verse", () => { const resultChirho = findVerseByReferenceChirho(testVersesChirho, "Psalm 127:1"); expect(resultChirho).toBeDefined(); expect(resultChirho?.referenceChirho).toBe("Psalm 127:1"); });

test("findVerseByReferenceChirho returns undefined for missing verse", () => { const resultChirho = findVerseByReferenceChirho(testVersesChirho, "Genesis 1:1"); expect(resultChirho).toBeUndefined(); });

test("formatVerseChirho produces correct output", () => { const verseChirho: VerseCardChirho = { referenceChirho: "Proverbs 1:7", textChirho: "The fear of the LORD is the beginning of knowledge." }; const resultChirho = formatVerseChirho(verseChirho); expect(resultChirho).toBe('"The fear of the LORD is the beginning of knowledge." — Proverbs 1:7'); }); }); ```

Run the tests:

```bash bun test ```

You should see output confirming all tests pass. Every green checkmark means one more piece of your code is verified and trustworthy.

A Thought to Carry

"Unless the LORD builds the house, the builders labor in vain" (Psalm 127:1). Even the best-written code serves no purpose unless it serves a good purpose. Build with skill — types, functions, tests — but build for God's glory. The craft is a gift from Him; use it to serve others and honor the One who gave you the ability to think, reason, and create.


Activities & Exercises

Whatever you do, work at it with all your heart, as working for the Lord, not for human masters.
— Colossians 3:23

Knowledge Check

0 / 3
Question 1 of 3

What is the difference between `const` and `let` in TypeScript?

Copywork Practice

Colossians 3:23

Whatever you do, work at it with all your heart, as working for the Lord, not for human masters.

0 / 96 characters

Hands-On Activity

Build the complete Scripture Memory Quiz program from this lesson: (1) Create scripture-quiz-chirho.ts with the interface, data, and functions. (2) Run it with "bun run scripture-quiz-chirho.ts" and verify the output. (3) Create scripture-quiz-chirho.test.ts with all four test cases. (4) Run "bun test" and verify all tests pass. (5) CHALLENGE: Add two more verses to the array and one more test case that verifies your new verses work with findVerseByReferenceChirho. Commit everything to Git with a clear commit message.

Unit Review Flashcards

Knew it: 0 Learning: 0
0 / 4 reviewed