Welcome to the official μHigh tutorial! This guide will teach you the μHigh programming language from the ground up, with hands-on examples and exercises.
- Getting Started
- Your First Program
- Variables and Constants
- Basic Input and Output
- Data Types
- Operators
- Control Flow
- Functions
- Classes and Objects
- Namespaces
- Advanced Features
- Best Practices
- Exercises
Before we begin coding, make sure you have μHigh set up:
- Clone the repository and build the compiler
- Create a new file with the
.uhextension, or use the interactive REPL - Run the provided install script to set up your environment
- Open your favorite text editor or IDE (like Visual Studio Code)
- Start writing your μHigh programs!
- Run the compiler to see your code in action with
uhigh yourfile.uh - Or experiment interactively with
uhigh repl
Quick Start with REPL: If you want to try μHigh immediately without creating files, start the interactive REPL with uhigh repl and begin typing μHigh expressions and statements.
Multi-line Input in REPL: When using the REPL, you can create multi-line blocks by pressing Ctrl+Enter for newlines. This is especially useful for if statements, loops, functions, and classes. Press Enter alone to execute your code.
Note: μHigh is designed to be similar to C# and Java, so if you have experience with those languages, you'll find μHigh familiar. Another Note: This tutorial assumes the μHigh compiler has fully implemented the features discussed here, so make sure you have the latest version. If any features are not yet implemented, you can still learn the syntax and concepts, and apply them once they are available.
Let's start with the traditional "Hello, World!" program:
namespace MyFirstApp
{
public class Program
{
public static func Main(args: string[]): void {AW
}
}
}What's happening here?
namespacegroups related code togetherclass Programdefines a class named Programpublic static func Mainis the entry point of your programConsole.WriteLine()prints text to the screen
Try it yourself: Change the message to say "Hello, μHigh!" instead.
Variables store data that can change, while constants store data that never changes.
// Declare a variable
var message: string
var count: int
var price: float
// Declare and assign at the same time
var name: string = "Alice"
var age: int = 25
var isStudent: bool = true
// μHigh can often figure out the type automatically
var city = "New York" // Automatically a string
var temperature = 72.5 // Automatically a float// Constants never change once set
const PI = 3.14159
const MAX_USERS = 1000
const COMPANY_NAME = "Tech Corp"Exercise: Create variables for your name, age, and favorite color. Print them out.
Console.WriteLine("Simple text")
Console.WriteLine("Hello, " + name) // Combining strings
Console.WriteLine("Age: " + age.ToString()) // Converting numbers to stringsusing StdLib
// Usage
var userName = IO.Input("What's your name? ")
Console.WriteLine("Hello, " + userName + "!")μHigh supports several built-in data types:
// Numbers
var wholeNumber: int = 42
var decimalNumber: float = 3.14159
var bigNumber: long = 1000000000
// Text
var singleChar: char = 'A'
var text: string = "Hello, World!"
// True/False
var isValid: bool = true
var isComplete: bool = false
// Special
var nothing: void // Used for functions that don't return anythingvar firstName = "John"
var lastName = "Doe"
var fullName = firstName + " " + lastName
// String properties and methods (using C# methods)
var length = fullName.Length
var uppercase = fullName.ToUpper()
var lowercase = fullName.ToLower()Note: Any method that is default in C# is also available in μHigh, such as ToUpper(), ToLower(), Length, etc.
Please refer to the CSharp documentation for more details on these methods.
Exercise: Create a program that asks for your first and last name, then displays your full name in uppercase.
var a = 10
var b = 3
var sum = a + b // Addition: 13
var difference = a - b // Subtraction: 7
var product = a * b // Multiplication: 30
var quotient = a / b // Division: 3 (integer division)
var remainder = a % b // Modulo: 1var x = 5
var y = 10
var isEqual = x == y // false
var isNotEqual = x != y // true
var isLess = x < y // true
var isGreater = x > y // false
var isLessOrEqual = x <= y // true
var isGreaterOrEqual = x >= y // falsevar isSunny = true
var isWarm = false
var niceDay = isSunny && isWarm // AND: false
var okDay = isSunny || isWarm // OR: true
var notSunny = !isSunny // NOT: falsevar counter = 10
counter = counter + 5 // Traditional way
counter += 5 // Shorthand: same as above
counter -= 3 // Subtract and assign
counter *= 2 // Multiply and assign
counter /= 4 // Divide and assign
counter++ // Increment by 1
counter-- // Decrement by 1var age = 18
if age >= 18 {
Console.WriteLine("You can vote!")
} else {
Console.WriteLine("Too young to vote.")
}
// Multiple conditions
var score = 85
if score >= 90 {
Console.WriteLine("Grade: A")
} else if score >= 80 {
Console.WriteLine("Grade: B")
} else if score >= 70 {
Console.WriteLine("Grade: C")
} else {
Console.WriteLine("Grade: F")
}// Count from 1 to 5
var counter = 1
while counter <= 5 {
Console.WriteLine("Count: " + counter)
counter++
}
// Loop until user enters "quit"
var input = ""
while input != "quit" {
input = input("Enter command (or 'quit' to exit): ")
if (input != "quit") {
Console.WriteLine("You entered: " + input)
}
}// Traditional for loop
for var i = 0; i < 10; i++ {
Console.WriteLine("Number: " + i)
}
// For-in loop (when arrays are implemented)
var numbers = [1, 2, 3, 4, 5]
for num in numbers {
Console.WriteLine("Value: " + num)
}Exercise: Write a program that asks the user to guess a number between 1 and 10, and keeps asking until they get it right.
Functions are reusable blocks of code that perform specific tasks.
// Function that doesn't return anything
public static func greet(): void {
Console.WriteLine("Hello from a function!")
}
// Function that takes parameters
public static func greetPerson(name: string): void {
Console.WriteLine("Hello, " + name + "!")
}
// Function that returns a value
public static func add(a: int, b: int): int {
return a + b
}
// Using the functions
greet()
greetPerson("Alice")
var result = add(5, 3)
Console.WriteLine("5 + 3 = " + result)// Function with multiple parameters
public static func calculateArea(width: float, height: float): float {
return width * height
}
// Function that uses other functions
public static func describeRectangle(w: float, h: float): void {
var area = calculateArea(w, h)
Console.WriteLine("Rectangle: " + w + " x " + h)
Console.WriteLine("Area: " + area)
}Exercise: Write a function that takes a temperature in Celsius and returns it in Fahrenheit. Formula: F = C × 9/5 + 32
Classes are blueprints for creating objects. Objects are instances of classes.
public class Person {
// Fields store data
private field name: string
private field age: int
// Constructor initializes the object
public Person(personName: string, personAge: int) {
this.name = personName
this.age = personAge
}
// Methods are functions that belong to the class
public func greet(): void {
Console.WriteLine("Hi, I'm " + this.name + " and I'm " + this.age + " years old.")
}
public func haveBirthday(): void {
this.age++
Console.WriteLine("Happy birthday! " + this.name + " is now " + this.age)
}
}// Create objects (instances of the class)
var person1 = Person("Alice", 25)
var person2 = Person("Bob", 30)
// Call methods on the objects
person1.greet()
person2.greet()
person1.haveBirthday()Namespaces organize your code and prevent naming conflicts.
namespace MyCompany.Utils {
public class Calculator {
public static func add(a: int, b: int): int {
return a + b
}
}
}
namespace MyCompany.Models {
public class User {
public field Name: string
public field Email: string
}
}
// Using classes from different namespaces
namespace MyCompany.Main {
public class Program {
public static func Main(args: array<string>): void {
var result = Utils.Calculator.add(5, 3)
var user = Models.User()
user.Name = "John Doe"
}
}
}match command {
"help" => showHelp(),
"exit" => exitProgram(),
"save" => saveFile(),
_ => Console.WriteLine("Unknown command: " + command)
}public class MathUtils {
public static field PI: float = 3.14159
public static func square(x: float): float {
return x * x
}
public static func circleArea(radius: float): float {
return PI * square(radius)
}
}
// Usage - no need to create an instance
var area = MathUtils.circleArea(5.0)- Use PascalCase for classes, methods, and properties:
MyClass,DoSomething() - Use camelCase for variables and fields:
userName,totalAmount - Use UPPER_CASE for constants:
MAX_SIZE,DEFAULT_COLOR
// Good: Organized and clear
namespace MyApp.Models {
public class User {
private field id: int
public field Name: string
public func constructor(userId: int, userName: string) {
this.id = userId
this.Name = userName
}
}
}// Calculate the compound interest
// Formula: A = P(1 + r/n)^(nt)
public static func calculateCompoundInterest(
principal: float, // Initial amount
rate: float, // Annual interest rate
compounds: int, // Times compounded per year
years: int // Number of years
): float {
var base = 1 + (rate / compounds)
var exponent = compounds * years
return principal * Math.Pow(base, exponent)
}-
Personal Introduction
- Create a program that asks for your name, age, and hobby
- Display a formatted introduction message
-
Simple Calculator
- Ask user for two numbers and an operation (+, -, *, /)
- Display the result
-
Number Guessing Game
- Generate a random number between 1-100
- Let the user guess until they get it right
- Give "higher" or "lower" hints
-
Grade Calculator
- Create a
Studentclass with name and grades - Add methods to calculate average and letter grade
- Create multiple students and display a report
- Create a
-
Simple Banking System
- Create
BankAccountclass with deposit/withdraw methods - Track transaction history
- Implement overdraft protection
- Create
-
Library Management
- Create
BookandLibraryclasses - Implement check-out/check-in functionality
- Track due dates and overdue books
- Create
-
Command Line Calculator
- Support multiple operations in one expression
- Handle parentheses and order of operations
- Add functions like sqrt, pow, etc.
-
Text-Based Adventure Game
- Create classes for Player, Room, Item
- Implement movement, inventory, and interactions
- Save/load game state
Congratulations! You've learned the basics of μHigh programming. Here are some next steps:
- Explore the Standard Library: Learn about built-in .NET classes and methods
- Build Projects: Start with small programs and gradually make them more complex
- Read the Language Reference: Check out LANGUAGE.md for detailed syntax
- Join the Community: Contribute to the μHigh project or help other learners
- Language Reference - Complete syntax documentation
- README - Project overview and setup
- Feature Roadmap - Upcoming language features
Happy coding with μHigh! 🚀