Chapter 1: Hello, World!

Chapter 1: Hello, World!

Overview

Every programming journey begins with a simple question: "How do I make the computer say something?" The "Hello, World!" program is more than tradition—it's your first proof that you can communicate with a computer in its own language.

In Ruchy, we believe this first step should be immediate and rewarding, not buried under complexity.

"I still remember the first time I made a computer print 'Hello, World!' It was magical - like teaching a very literal friend to speak. That same feeling of wonder drove me to create Ruchy, where your first program works immediately, not after hours of setup." - Noah Gift

Learning Objectives

By the end of this chapter, you will be able to:

  • Write and execute your first Ruchy program
  • Use the println function to display output
  • Understand string literals and function calls
  • Experiment with variables and string interpolation
  • Work with multiple data types in print statements
  • Avoid common beginner mistakes

1.1 Your First Ruchy Program

Here's your first Ruchy program - click Run to execute it in your browser!

What's happening:

  • println(...) is a built-in function that prints text to the screen
  • "Hello, World!" is a string literal enclosed in double quotes
  • When you click Run, you'll see the output appear below the code

You can also run this locally:

$ ruchy run hello.ruchy
Hello, World!

Or try it instantly in the REPL:

$ ruchy repl
>>> println("Hello, World!")
Hello, World!

1.2 Core Concepts

The println Function

println is Ruchy's built-in function for printing text to the screen. It:

  • Takes any number of arguments
  • Prints them separated by spaces
  • Automatically adds a newline at the end
  • Returns () (unit type) when done

String Literals

In "Hello, World!":

  • Double quotes " mark the beginning and end of text
  • Everything inside is treated literally as text
  • This creates a str type in Ruchy

Function Calls

The syntax println(...) is a function call:

  • println is the function name
  • Parentheses () contain the arguments
  • Multiple arguments are separated by commas

1.3 Multiple Arguments

You can pass multiple values to println, and they'll be printed separated by spaces:

Output:

Hello World from Ruchy

Try changing the words above and clicking Run again!

1.4 Variables and String Interpolation

Ruchy supports multiple ways to work with variables in strings:

Output:

Hello, Alice
Hello, Alice!
Hello, Alice!

F-String Advantages:

  • Cleaner syntax than concatenation
  • Supports format specifiers: f"{pi:.2}" for 2 decimal places
  • More readable for complex strings
  • Zero performance overhead

Experiment: Try changing "Alice" to your own name and run the code!

1.5 Working with Different Types

println can display many different data types:

Output:

The answer is 42
Pi is approximately 3.14159
Is Ruchy awesome? true

Experiment: Try adding your own print statements with different numbers, booleans, or text!

1.6 Common Pitfalls

Forgetting Quotes

Error: Forgetting to put quotes around literal text will cause a parsing error:

// ❌ This won't work - intentional error example
// println(Hello, World!);

// Always use quotes for literal text.

Correct way:

fun main() {
    println("Hello, World!");  // ✅ Quotes required
}

Mixing Quote Types

Error: Starting with one quote type and ending with another:

// ❌ Quotes don't match - intentional error example
// println("Hello, World!');

// Use either "..." or '...' but be consistent.

Correct way:

fun main() {
    println("Hello, World!");  // ✅ Matching quotes
}

Case Sensitivity

Error: Ruchy function names are case-sensitive:

// ❌ Wrong capitalization - intentional error example
// PrintLn("Hello, World!");  // Capital P and L won't work

Correct way:

fun main() {
    println("Hello, World!");  // ✅ Lowercase println
}

1.7 Generated Code Insight

Ever wonder what happens "under the hood" when you write Ruchy code? Let's peek behind the curtain.

Your Ruchy code:

fun main() {
    println("Hello, World!");
}

Transpiles to this optimized Rust:

fn main() {
    println!("Hello, World!");
}

What's happening:

  • Ruchy's println function becomes Rust's println! macro
  • Ruchy automatically wraps top-level code in a main() function
  • The string literal stays exactly the same
  • No runtime overhead - this compiles to native machine code

Why this matters:

  • You get Rust's performance without Rust's complexity
  • Your code can integrate seamlessly with existing Rust libraries
  • The generated code is readable and debuggable

The Bottom Line: Ruchy gives you Python-like simplicity with Rust-like performance. You're not sacrificing speed for ease of use.

1.8 Interactive Playground

Time to experiment! Try creating your own personalized greeting:

Your Challenge:

  1. Personal Greeting: Create a greeting that includes your name, age, and why you're learning Ruchy
  2. Data Mix: Use println with at least 4 different data types in one call
  3. String Interpolation: Use f-strings to create a personalized message

The interactive block above is your playground - experiment, break things, and learn!

Summary

In this chapter, you learned:

  • println(...) is your tool for displaying output
  • String literals use double quotes: "text"
  • Function calls use parentheses: function_name(arguments)
  • Variables let you store and reuse values
  • F-strings provide clean string interpolation syntax
  • Multiple types can be printed together
  • Ruchy transpiles to clean, efficient Rust code

Now that you can make Ruchy speak, let's learn about storing and manipulating information with variables and types in the next chapter.

Next Steps

Continue your learning journey:

  • Chapter 2: Variables and Types - storing and manipulating data
  • Chapter 3: Functions - organizing code into reusable blocks
  • Chapter 4: Practical Patterns - real-world coding techniques