Skip to content

Harneet Programming Language - Beginner's Guide

Welcome to Harneet! This guide will teach you everything you need to know about the Harneet programming language, designed especially for newcomers to programming. Inspired by Go and some Python.

What is Harneet?

Harneet is a simple, easy-to-learn programming language that's perfect for beginners. It has clean syntax inspired by Go and includes essential programming concepts like variables, arithmetic, and decision-making.

Think of Harneet as a friendly way to learn programming fundamentals before moving on to more complex languages.

Note: Harneet is actively evolving, and some features common in other languages may not yet be available. It is not intended for production use.

Getting Started

Installation & Running Programs

  1. Build Harneet (one-time setup):

    just build
    # This creates the 'harneet' program
    

  2. Try the interactive mode (REPL):

    just repl
    # Type commands and see results immediately
    

  3. Run a program file:

    ./harneet examples/hello.ha
    # Runs code from a file (uses .ha extension)
    

Example 1: Your First Program

Let's start with the classic "Hello, World!" program:

First Program
1
2
3
package main
import fmt
fmt.Println("Hello, World!")

What this does: - import fmt loads the formatting module (needed for printing) - fmt.Println() is a command that prints text to the screen - The text inside quotes "Hello, World!" is what gets printed - Every statement in Harneet can be on its own line

Try it yourself: 1. Save this code in a file called hello.ha 2. Run it with: ./harneet hello.ha

Example 2: Simple Calculator

Simple Calculator
package main
var num1 int = 15
var num2 int = 4

fmt.Println("Number 1:", num1)
fmt.Println("Number 2:", num2)
fmt.Println("Sum:", num1 + num2)
fmt.Println("Difference:", num1 - num2)
fmt.Println("Product:", num1 * num2)
fmt.Println("Division:", num1 / num2)
fmt.Println("Remainder:", num1 % num2)

Example 3: Grade Checker

Grade Checker
package main
var score int = 85

fmt.Println("Your score:", score)

if score >= 90 {
    fmt.Println("Grade: A - Excellent!")
}

if score >= 80 and score < 90 {
    fmt.Println("Grade: B - Good job!")
}

if score >= 70 and score < 80 {
    fmt.Println("Grade: C - Not bad!")
}

if score < 70 {
    fmt.Println("Grade: F - Study more!")
}

Example 4: Multiline Strings

Multiline Strings
package main
import fmt, strings

function main() {
    // Create a multiline string for SQL
    var createUserTable = `
        CREATE TABLE users (
            id INTEGER PRIMARY KEY,
            username VARCHAR(50) NOT NULL,
            email VARCHAR(100) UNIQUE,
            created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
        )
    `

    fmt.Println("SQL Query:")
    fmt.Println(createUserTable)

    // Multiline strings work with all string functions
    var queryLength, _ = strings.Len(createUserTable)
    fmt.Printf("Query length: %d characters\n", queryLength)

    // No escaping needed for quotes or backslashes
    var configData = `{
        "database": {
            "host": "localhost",
            "path": "C:\\data\\myapp.db"
        },
        "message": "Welcome to \"MyApp\"!"
    }`

    fmt.Println("\nConfiguration:")
    fmt.Println(configData)
}

Getting Help

  • Run examples: just test runs all example programs
  • Try interactive mode: just repl for experimenting
  • Browse the documentation: Use the left navigation to explore topics
  • Practice: The examples/ folder has more programs to study

Congratulations!

You now know the basics of the Harneet programming language! That said, there are still more things to learn. We encourage you to go through the remaining of this document, to know more Harneet Programming language. Remember: - Programming is like learning a new language - it takes practice - Every expert was once a beginner - The most important thing is to keep experimenting and having fun!

Happy coding! 🚀