Skip to content
LAM
Read Home Blog
Make Projects HTML Tools Games
Touch grass Notes Resume Links
Home Blog HTML Projects
Tools Games Notes Resume Links
Back Veridata: An Interactive Language Proposal Programming
Download Open
Show description 275 chars · Programming

Veridata: An Interactive Language Proposal

Veridata: An Interactive Language Proposal
















Veridata Explorer










Veridata

Language Proposal




Introduction
Language Comparison
Veridata Spec
Syntax & Types
Gradual Ownership
The .vdb File
Query Language
Case Study

Veridata: An Interactive Language Proposal

37,057 bytes · HTML source
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Veridata: An Interactive Language Proposal</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
    <!-- Chosen Palette: Synthwave IDE - A dark theme inspired by code editors, using a charcoal background with vibrant magenta and cyan accents. -->
    <!-- Application Structure Plan: The SPA is designed as an interactive documentation site with a fixed sidebar for navigation and a dynamic main content area. This structure was chosen to break down the dense, linear report into logical, non-linear sections (Intro, Comparison, Core Features, etc.). This allows users, such as developers or researchers, to immediately jump to the concepts they are most interested in (e.g., "Gradual Ownership") without having to scroll through preceding content, greatly improving usability and information discovery. -->
    <!-- Visualization & Content Choices: 
        - Report Info: Part I Comparative Analysis -> Goal: Compare -> Viz/Method: An interactive "Language Comparator" with a dropdown to select a feature (e.g., "Memory Management"). This dynamically displays cards for each language (Python, Rust, etc.) with the relevant text from the report. -> Justification: This transforms a passive reading task into an active exploration, allowing for focused, side-by-side comparison which is more effective than reading long-form text.
        - Report Info: Table 1 -> Goal: Organize/Inform -> Viz/Method: A responsive HTML table styled with Tailwind. -> Justification: A table remains the most efficient format for summarizing dense, multi-attribute data.
        - Report Info: .vdb File Format -> Goal: Explain a structure -> Viz/Method: An interactive code block viewer with tabs ("Schema", "Data", "Code", "Docs"). -> Interaction: Clicking a tab highlights the corresponding section in the code example. -> Justification: This makes the novel, multi-part file structure tangible and easy to understand at a glance.
        - Report Info: Core Concepts (e.g., Option<T>, Result<T, E>) -> Goal: Inform/Highlight -> Viz/Method: Styled call-out boxes using HTML/Tailwind. -> Justification: Visually separates key takeaways from the main text, aiding comprehension and retention.
    -->
    <!-- CONFIRMATION: NO SVG graphics used. NO Mermaid JS used. -->
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Source+Code+Pro:wght@400;600&display=swap" rel="stylesheet">
    <style>
        :root {
            --bg-base: #1e1e2e;
            --bg-surface: #181825;
            --bg-overlay: #313244;
            --text-base: #cdd6f4;
            --text-subtle: #a6adc8;
            --border-color: #45475a;
            --accent-pink: #f5c2e7;
            --accent-cyan: #89dceb;
            --accent-green: #a6e3a1;
        }
        body {
            background-color: var(--bg-base);
            color: var(--text-base);
            font-family: 'Inter', sans-serif;
        }
        .code {
            font-family: 'Source Code Pro', monospace;
            background-color: var(--bg-overlay);
            color: var(--accent-cyan);
            padding: 0.1rem 0.3rem;
            border-radius: 4px;
            font-size: 0.9em;
        }
        pre code {
            background-color: #11111b;
            color: var(--text-base);
            display: block;
            padding: 1.5rem;
            border-radius: 8px;
            font-size: 0.9em;
            white-space: pre-wrap;
            word-wrap: break-word;
        }
        .sidebar-link {
            transition: all 0.2s ease-in-out;
            color: var(--text-subtle);
        }
        .sidebar-link.active, .sidebar-link:hover {
            background-color: rgba(245, 194, 231, 0.1);
            color: var(--accent-pink);
            transform: translateX(4px);
        }
        .content-section h2 {
            font-size: 2.25rem;
            font-weight: 700;
            color: var(--accent-cyan);
            border-bottom: 2px solid var(--border-color);
            padding-bottom: 0.5rem;
            margin-bottom: 1.5rem;
        }
        .content-section h3 {
            font-size: 1.75rem;
            font-weight: 600;
            color: var(--text-base);
            margin-top: 2rem;
            margin-bottom: 1rem;
        }
        .callout {
            background-color: var(--bg-surface);
            border-left: 5px solid var(--accent-pink);
            padding: 1.5rem;
            margin: 1.5rem 0;
            border-radius: 0 8px 8px 0;
        }
        .highlight-line {
            background-color: rgba(245, 194, 231, 0.15);
            display: block;
            margin: 0 -1.5rem;
            padding: 0 1.5rem;
            transition: background-color 0.3s;
        }
        .bg-themed-surface { background-color: var(--bg-surface); }
        .border-themed { border-color: var(--border-color); }
        .text-themed-accent { color: var(--accent-pink); }
        .text-themed-subtle { color: var(--text-subtle); }
    </style>
</head>
<body class="text-gray-200">

    <div class="flex min-h-screen">
        <!-- Mobile Header -->
        <div class="md:hidden w-full bg-themed-surface shadow-md p-4 flex justify-between items-center fixed top-0 left-0 z-20 border-b border-themed">
            <h1 class="text-xl font-bold text-themed-accent">Veridata Explorer</h1>
            <button id="mobileMenuButton" class="text-gray-300 focus:outline-none">
                <svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 6h16M4 12h16m-7 6h7"></path></svg>
            </button>
        </div>

        <!-- Sidebar -->
        <aside id="sidebar" class="bg-themed-surface w-64 flex-shrink-0 border-r border-themed fixed md:relative h-full md:h-auto z-10 -translate-x-full md:translate-x-0 transition-transform duration-300 ease-in-out pt-16 md:pt-0">
            <div class="p-6">
                <h1 class="text-2xl font-bold text-themed-accent">Veridata</h1>
                <p class="text-sm text-themed-subtle">Language Proposal</p>
            </div>
            <nav id="navigation" class="flex flex-col p-4">
                <a href="#introduction" class="sidebar-link active text-lg font-medium py-2 px-4 rounded-lg">Introduction</a>
                <a href="#comparison" class="sidebar-link text-lg font-medium py-2 px-4 rounded-lg">Language Comparison</a>
                <span class="px-4 pt-4 pb-2 text-sm font-semibold text-themed-subtle uppercase">Veridata Spec</span>
                <a href="#syntax" class="sidebar-link text-lg font-medium py-2 px-4 rounded-lg">Syntax & Types</a>
                <a href="#ownership" class="sidebar-link text-lg font-medium py-2 px-4 rounded-lg">Gradual Ownership</a>
                <a href="#vdb" class="sidebar-link text-lg font-medium py-2 px-4 rounded-lg">The .vdb File</a>
                <a href="#querying" class="sidebar-link text-lg font-medium py-2 px-4 rounded-lg">Query Language</a>
                <a href="#casestudy" class="sidebar-link text-lg font-medium py-2 px-4 rounded-lg">Case Study</a>
            </nav>
        </aside>

        <!-- Main Content -->
        <main id="mainContent" class="flex-1 p-6 md:p-10 lg:p-12 mt-16 md:mt-0">
            <!-- Content will be injected here by JavaScript -->
        </main>
    </div>

    <script>
        const contentData = {
            introduction: {
                title: "Veridata: A High-Integrity, Data-Centric Language",
                content: `
                    <p class="text-xl leading-relaxed text-themed-subtle mb-6">This application provides an interactive exploration of the Veridata programming language proposal. Veridata is designed to resolve the historical trade-offs in language design—between productivity and performance, safety and simplicity. It synthesizes the best features of modern languages to offer a unified, powerful, and developer-friendly experience.</p>
                    <div class="callout">
                        <h3 class="text-xl font-bold mb-2 text-themed-accent">Core Goals of Veridata</h3>
                        <ul class="list-disc list-inside space-y-2 text-lg">
                            <li>Provide a <strong>smooth developer journey</strong> from high-level scripting to high-performance systems programming.</li>
                            <li>Enforce a <strong>holistic definition of safety</strong>, eliminating entire classes of memory, concurrency, and logical bugs at compile time.</li>
                            <li>Introduce a <strong>revolutionary data-centric architecture</strong> that fuses code, schema, and data into a single, literate artifact.</li>
                        </ul>
                    </div>
                    <p class="text-lg leading-relaxed">Use the navigation on the left to explore the detailed analysis and specifications. You can compare Veridata's design choices against established languages, dive deep into its innovative features like Gradual Ownership, and see how it all comes together in the case study.</p>
                `
            },
            comparison: {
                title: "Comparative Language Analysis",
                content: `
                    <p class="text-lg leading-relaxed mb-6 text-themed-subtle">Veridata's design is built upon a deep analysis of the strengths and weaknesses of its predecessors. This section allows you to interactively compare how foundational languages handle key programming concepts. This context is crucial for understanding the problems Veridata aims to solve.</p>
                    <div class="bg-themed-surface p-6 rounded-lg border border-themed">
                        <h3 class="text-xl font-semibold mb-4">Interactive Language Comparator</h3>
                        <p class="mb-4 text-themed-subtle">Select a feature below to see how each language approaches it. This provides a direct, side-by-side view of the design trade-offs that have shaped modern programming.</p>
                        <select id="featureSelector" class="w-full md:w-1/2 p-3 bg-themed-surface border border-themed rounded-lg focus:ring-2 focus:ring-pink-500 focus:border-pink-500 transition mb-6">
                            <option value="ergonomics">Developer Experience & Ergonomics</option>
                            <option value="memory">Memory Management</option>
                            <option value="concurrency">Concurrency Model</option>
                        </select>
                        <div id="comparisonContainer" class="grid grid-cols-1 lg:grid-cols-2 gap-6"></div>
                    </div>
                    <h3 class="mt-12">Summary Table</h3>
                    <p class="text-lg leading-relaxed mb-6 text-themed-subtle">The following table provides a high-level summary of the features across the analyzed languages, offering a quick reference for their core characteristics and trade-offs.</p>
                    <div class="overflow-x-auto bg-themed-surface rounded-lg border border-themed">
                        <table class="min-w-full text-left text-sm">
                            <thead class="border-b border-themed font-medium bg-themed-overlay">
                                <tr>
                                    <th scope="col" class="px-6 py-4">Feature</th>
                                    <th scope="col" class="px-6 py-4">Python</th>
                                    <th scope="col" class="px-6 py-4">Rust</th>
                                    <th scope="col" class="px-6 py-4">JavaScript</th>
                                    <th scope="col" class="px-6 py-4">Java</th>
                                    <th scope="col" class="px-6 py-4">C++</th>
                                    <th scope="col" class="px-6 py-4">SQL</th>
                                </tr>
                            </thead>
                            <tbody class="text-themed-subtle">
                                <tr class="border-b border-themed">
                                    <td class="px-6 py-4 font-semibold text-base">Typing Model</td><td class="px-6 py-4">Dynamic, Strong</td><td class="px-6 py-4">Static, Strong</td><td class="px-6 py-4">Dynamic, Weak</td><td class="px-6 py-4">Static, Strong</td><td class="px-6 py-4">Static, Strong</td><td class="px-6 py-4">Static, Strong</td>
                                </tr>
                                <tr class="border-b border-themed bg-themed-overlay">
                                    <td class="px-6 py-4 font-semibold text-base">Memory Management</td><td class="px-6 py-4">Automatic (GC)</td><td class="px-6 py-4">Static (Ownership)</td><td class="px-6 py-4">Automatic (GC)</td><td class="px-6 py-4">Automatic (GC)</td><td class="px-6 py-4">Manual (RAII)</td><td class="px-6 py-4">Managed by DBMS</td>
                                </tr>
                                <tr class="border-b border-themed">
                                    <td class="px-6 py-4 font-semibold text-base">Concurrency</td><td class="px-6 py-4">GIL (I/O-bound)</td><td class="px-6 py-4">Fearless</td><td class="px-6 py-4">Event Loop</td><td class="px-6 py-4">OS Threads & Locks</td><td class="px-6 py-4">OS Threads & Locks</td><td class="px-6 py-4">Transactional (ACID)</td>
                                </tr>
                                <tr class="border-b border-themed bg-themed-overlay">
                                    <td class="px-6 py-4 font-semibold text-base">Performance</td><td class="px-6 py-4">Slow</td><td class="px-6 py-4">Fastest</td><td class="px-6 py-4">Fast</td><td class="px-6 py-4">Fast</td><td class="px-6 py-4">Fastest</td><td class="px-6 py-4">Optimized by Engine</td>
                                </tr>
                                <tr class="border-b border-themed">
                                    <td class="px-6 py-4 font-semibold text-base">Strengths</td><td class="px-6 py-4">Readability, Libraries</td><td class="px-6 py-4">Safety, Performance</td><td class="px-6 py-4">Ubiquity, Async I/O</td><td class="px-6 py-4">Platform Independence</td><td class="px-6 py-4">Low-Level Control</td><td class="px-6 py-4">Data Integrity</td>
                                </tr>
                                <tr class="bg-themed-overlay">
                                    <td class="px-6 py-4 font-semibold text-base">Weaknesses</td><td class="px-6 py-4">Performance, GIL</td><td class="px-6 py-4">Steep Learning Curve</td><td class="px-6 py-4">Weak Typing</td><td class="px-6 py-4">Verbosity, GC Pauses</td><td class="px-6 py-4">Unsafe Memory</td><td class="px-6 py-4">Impedance Mismatch</td>
                                </tr>
                            </tbody>
                        </table>
                    </div>
                `
            },
            syntax: {
                title: "Syntax & Type System",
                content: `
                    <p class="text-lg leading-relaxed mb-6 text-themed-subtle">Veridata's syntax and type system are designed to provide the readability of a high-level scripting language with the robustness and compile-time guarantees of a modern systems language. The goal is to lower the barrier to entry while building a foundation for highly reliable software.</p>
                    <h3>Syntax: Python's Readability, Rust's Power</h3>
                    <p class="text-lg leading-relaxed mb-6 text-themed-subtle">Veridata adopts a clean, indentation-aware syntax inspired by Python to prioritize readability and minimize boilerplate. For expressive and safe control flow, it incorporates powerful features from Rust, such as <code class="code">match</code> expressions for exhaustive pattern matching. This allows the compiler to ensure that all possible cases of a data structure are handled, preventing a common source of bugs.</p>
                    <h3>Eliminating Nulls and Exceptions</h3>
                    <p class="text-lg leading-relaxed mb-6 text-themed-subtle">The type system is designed to eliminate two of the most problematic features in programming: null references and traditional exceptions. Veridata builds error and optionality handling directly into the type system using two core <code class="code">enum</code> types, inspired by Rust.</p>
                    <div class="callout">
                        <h4 class="text-lg font-semibold mb-2 text-themed-accent"><code class="code">Option&lt;T&gt;</code>: Handling Absence Safely</h4>
                        <p>Represents a value that can be either <code class="code">Some(T)</code> or <code class="code">None</code>. This forces the programmer to explicitly handle the case where a value might be absent, completely eliminating null pointer exceptions at compile time.</p>
                    </div>
                    <div class="callout">
                        <h4 class="text-lg font-semibold mb-2 text-themed-accent"><code class="code">Result&lt;T, E&gt;</code>: Handling Failure Explicitly</h4>
                        <p>Represents the outcome of an operation that can either succeed (<code class="code">Ok(T)</code>) or fail (<code class="code">Err(E)</code>). Functions that can fail must return a <code class="code">Result</code>, and the compiler requires the caller to handle both cases. This makes error handling a first-class, un-ignorable part of the program's logic.</p>
                    </div>
                `
            },
            ownership: {
                title: "Gradual Ownership",
                content: `
                    <p class="text-lg leading-relaxed mb-6 text-themed-subtle">Veridata's most significant innovation is its memory management model, designed to resolve the tension between the ease-of-use of garbage collection and the performance and safety of Rust's ownership system. This is achieved through a novel dual-mode system called "Gradual Ownership".</p>
                    <h3>The Core Problem: The Ownership Learning Curve</h3>
                    <p class="text-lg leading-relaxed mb-6 text-themed-subtle">While Rust's ownership model is revolutionary, its steep learning curve is a major barrier to adoption. For many applications, the strictness of the borrow checker is a significant hurdle to productivity. Veridata aims to provide a smoother on-ramp to these powerful concepts.</p>
                    <h3>A Dual-Mode System</h3>
                    <p class="text-lg leading-relaxed mb-6 text-themed-subtle">Developers can choose the appropriate memory management strategy on a case-by-case basis within the same language.</p>
                    <div class="grid grid-cols-1 md:grid-cols-2 gap-8 my-8">
                        <div class="bg-themed-surface p-6 rounded-lg border border-themed">
                            <h4 class="text-xl font-bold text-cyan-400 mb-2">Managed Mode (Default)</h4>
                            <p class="text-themed-subtle">By default, memory is managed automatically by a garbage collector. This provides the familiar, productive experience of languages like Python or Java, allowing for rapid development without worrying about memory lifetimes.</p>
                        </div>
                        <div class="bg-themed-surface p-6 rounded-lg border border-themed">
                            <h4 class="text-xl font-bold text-green-400 mb-2">Owned Mode (Opt-in)</h4>
                            <p class="text-themed-subtle">For performance-critical code, developers can use the <code class="code">owned</code> keyword. Within this block, the compiler enforces Rust-style ownership and borrowing rules, guaranteeing memory safety with zero runtime overhead.</p>
                        </div>
                    </div>
                    <h3>A Pedagogical Framework</h3>
                    <p class="text-lg leading-relaxed text-themed-subtle">This dual-mode system acts as a learning tool. A developer can start in the productive <code class="code">managed</code> mode. When a performance bottleneck appears, they can refactor just that small section into <code class="code">owned</code> mode, with the compiler guiding them through the process. This makes high-performance, memory-safe programming an accessible, incremental upgrade path rather than an all-or-nothing choice.</p>
                `
            },
            vdb: {
                title: "The .vdb File Format",
                content: `
                    <p class="text-lg leading-relaxed mb-6 text-themed-subtle">Veridata's most distinctive feature is the <code class="code">.vdb</code> file format, designed to eliminate the boundary between application code, data, and documentation. It is a plain text file that acts as a hybrid of a literate program and a structured database.</p>
                    <h3>Structure and Syntax</h3>
                    <p class="text-lg leading-relaxed mb-6 text-themed-subtle">The file format is a superset of TOML (Tom's Obvious, Minimal Language) and supports multiple, distinct content blocks. This allows schema, data, code, and documentation to coexist in a single, version-controllable artifact. Click the tabs below to highlight the different blocks in the example.</p>
                    <div class="bg-themed-surface p-6 rounded-lg border border-themed">
                        <div class="flex border-b border-themed mb-4">
                            <button class="vdb-tab active py-2 px-4 text-themed-accent border-b-2 border-themed-accent font-semibold" data-target="schema">Schema</button>
                            <button class="vdb-tab py-2 px-4 text-themed-subtle font-semibold" data-target="data">Data</button>
                            <button class="vdb-tab py-2 px-4 text-themed-subtle font-semibold" data-target="docs">Docs</button>
                            <button class="vdb-tab py-2 px-4 text-themed-subtle font-semibold" data-target="code">Code</button>
                        </div>
                        <pre><code id="vdbExample">
<span class="vdb-line docs"># blog.vdb - A complete, self-contained blog application.</span>
<span class="vdb-line docs"># This section defines the data model for our blog.</span>
<span class="vdb-line schema">[schema.authors]</span>
<span class="vdb-line schema">id = { type = "int", primary_key = true }</span>
<span class="vdb-line schema">name = { type = "string" }</span>
<span class="vdb-line schema"></span>
<span class="vdb-line schema">[schema.posts]</span>
<span class="vdb-line schema">id = { type = "int", primary_key = true }</span>
<span class="vdb-line schema">author_id = { type = "int", foreign_key = "authors.id" }</span>
<span class="vdb-line schema">title = { type = "string" }</span>
<span class="vdb-line schema"></span>
<span class="vdb-line data"># Seed data for the authors table</span>
<span class="vdb-line data">[[data.authors]]</span>
<span class="vdb-line data">name = "Ada Lovelace"</span>
<span class="vdb-line data"></span>
<span class="vdb-line data">[[data.authors]]</span>
<span class="vdb-line data">name = "Grace Hopper"</span>
<span class="vdb-line docs"></span>
<span class="vdb-line docs">---</span>
<span class="vdb-line docs"></span>
<span class="vdb-line docs">## Application Logic</span>
<span class="vdb-line code">\`\`\`vdata</span>
<span class="vdb-line code">func get_all_posts() -> Result<[Post], DbError> {</span>
<span class="vdb-line code">    return db.posts.execute();</span>
<span class="vdb-line code">}</span>
<span class="vdb-line code">\`\`\`</span>
                        </code></pre>
                    </div>
                    <h3>Embedded Database Engine</h3>
                    <p class="text-lg leading-relaxed mt-6 text-themed-subtle">The Veridata runtime includes a high-performance, serverless database engine (similar to SQLite) that operates directly on the <code class="code">.vdb</code> file. It guarantees ACID compliance through Write-Ahead Logging (WAL), ensuring data integrity even in the face of crashes or concurrent operations.</p>
                `
            },
            querying: {
                title: "Type-Safe Query Language",
                content: `
                    <p class="text-lg leading-relaxed mb-6 text-themed-subtle">Veridata provides a powerful, integrated language for data manipulation that is both expressive and safe. It solves the "object-relational impedance mismatch" by making the database schema a native part of the application's type system.</p>
                    <h3>A Fluent, Compile-Time Checked API</h3>
                    <p class="text-lg leading-relaxed mb-6 text-themed-subtle">Interaction with the embedded database is performed through a fluent, method-chaining API inspired by C#'s LINQ and Java's jOOQ. Because the compiler understands the entire <code class="code">.vdb</code> file, it can check the correctness of every query at compile time, eliminating an entire class of runtime errors.</p>
                    <div class="callout">
                        <h4 class="text-lg font-semibold mb-2 text-themed-accent">Compile-Time Guarantees</h4>
                        <ul class="list-disc list-inside space-y-2">
                            <li>Querying a non-existent column results in a <strong>compile error</strong>.</li>
                            <li>Type-incompatible comparisons (e.g., <code class="code">date > integer</code>) are <strong>caught by the compiler</strong>.</li>
                            <li>Referencing a non-existent table will <strong>fail the build</strong>.</li>
                        </ul>
                    </div>
                    <h3>Example Query</h3>
                    <p class="text-lg leading-relaxed mb-6 text-themed-subtle">A query in Veridata reads like a descriptive sequence of operations, making the code's intent clear and self-documenting. Notice how there are no raw SQL strings.</p>
                    <pre><code>
func find_recent_premium_users() -> Result<[User], DbError> {
    let thirty_days_ago = now().subtract_days(30);

    let recent_users = db.users
                        .where(u => u.subscription_tier == "premium")
                        .where(u => u.signup_date > thirty_days_ago)
                        .orderBy(u => u.last_name)
                        .limit(100)
                        .execute();

    return recent_users;
}
                    </code></pre>
                `
            },
            casestudy: {
                title: "Case Study: A Complete Blog Application",
                content: `
                    <p class="text-lg leading-relaxed mb-6 text-themed-subtle">This case study illustrates how all of Veridata's concepts coalesce into a cohesive development experience. The following code represents a complete, self-contained blog application within a single <code class="code">blog.vdb</code> file.</p>
                    <p class="text-lg leading-relaxed mb-6 text-themed-subtle">A developer can edit the schema, add new data rows, and write application logic in the same file. Running the program executes the code against the embedded data, with all interactions validated by the compiler. There is no external database to configure, no ORM to manage, and no risk of runtime query errors.</p>
                    <pre><code>
# blog.vdb - A complete, self-contained blog application.

## Blog Schema and Data
This section defines the data model for our blog, including authors and their posts.
It also contains some initial seed data.

[schema.authors]
id = { type = "int", primary_key = true, auto_increment = true }
name = { type = "string" }
email = { type = "string", unique = true }

[schema.posts]
id = { type = "int", primary_key = true, auto_increment = true }
author_id = { type = "int", foreign_key = "authors.id" }
title = { type = "string" }
content = { type = "string" }
published_at = { type = "datetime" }

# Seed data for the authors table
[[data.authors]]
name = "Ada Lovelace"
email = "ada@example.com"

[[data.authors]]
name = "Grace Hopper"
email = "grace@example.com"

---

## Application Logic
This section contains the Veridata code to interact with our blog data.

\`\`\`vdata
// Define a struct to hold joined data for convenience.
struct PostWithAuthor {
    post_title: string,
    author_name: string,
    content: string,
}

// A function to retrieve recent posts, running in default 'managed' mode.
func get_recent_posts() -> Result<[PostWithAuthor], DbError> {
    let posts = db.posts
                 .join(db.authors, on=(p, a) => p.author_id == a.id)
                 .orderByDesc(p => p.published_at)
                 .limit(5)
                 .select((p, a) => PostWithAuthor {
                      post_title: p.title,
                      author_name: a.name,
                      content: p.content,
                  })
                 .execute();
    return posts;
}

// A performance-critical function, opting into 'owned' mode.
owned func analyze_post_content(content: &str) -> map<string, int> {
    // ... complex, high-performance text processing logic ...
    // The compiler enforces strict ownership rules here.
    let word_counts = map<string, int>{};
    // (Implementation omitted for brevity)
    return word_counts;
}
\`\`\`
                    </code></pre>
                `
            }
        };

        const comparisonData = {
            ergonomics: {
                Python: "Prioritizes readability and simplicity. Clean, indentation-based syntax and English-like keywords lower cognitive overhead and boost productivity.",
                Rust: "Offers C++ performance with memory safety, but at a high ergonomic cost. The steep learning curve is due to complex concepts like ownership and a very strict compiler.",
                JavaScript: "Ubiquitous and flexible with a C-like syntax. Easy for beginners, but its loosely-typed, dynamic nature can lead to maintainability issues in large applications.",
                Java: "More verbose than scripting languages. Requires significant boilerplate code for simple programs, which can reduce readability.",
                'C++': "Notoriously complex with a steep learning curve. Its vast feature set and manual memory management place a significant cognitive burden on the developer."
            },
            memory: {
                Python: "Uses automatic memory management via a garbage collector (GC). This boosts productivity but can introduce unpredictable pauses and higher memory consumption.",
                Rust: "Revolutionary static, compile-time memory management based on ownership and borrowing. Guarantees memory safety without the runtime overhead of a GC.",
                JavaScript: "Employs automatic memory management via a garbage collector, similar to Python. Prioritizes developer convenience over performance predictability.",
                Java: "Uses a garbage collector on the JVM. Abstracts memory management away, but can suffer from 'stop-the-world' GC pauses, making it unsuitable for latency-sensitive systems.",
                'C++': "Grants complete manual control over memory (<code class='code'>new</code>/<code class='code'>delete</code>). Allows for maximum performance but is the source of dangerous bugs like memory leaks and dangling pointers."
            },
            concurrency: {
                Python: "Largely single-threaded for CPU-bound tasks due to the Global Interpreter Lock (GIL). Best suited for I/O-bound concurrency.",
                Rust: "'Fearless concurrency' is a direct extension of the ownership model. The same rules that ensure memory safety also prevent data races at compile time, via message passing or locked shared state.",
                JavaScript: "Uses a single-threaded event loop. Excels at non-blocking I/O but a long-running CPU task will block the entire application.",
                Java: "Provides true parallelism with OS threads, but requires manual use of synchronization primitives like locks, which is notoriously error-prone.",
                'C++': "Offers direct access to OS threads for shared-state concurrency. Like Java, it puts the burden of preventing race conditions and deadlocks on the developer."
            }
        };

        const mainContent = document.getElementById('mainContent');
        const navigation = document.getElementById('navigation');
        const sidebar = document.getElementById('sidebar');
        const mobileMenuButton = document.getElementById('mobileMenuButton');

        function renderContent(pageId) {
            const pageData = contentData[pageId];
            if (!pageData) return;

            mainContent.innerHTML = `<div class="content-section"><h2>${pageData.title}</h2>${pageData.content}</div>`;
            
            // Post-render hooks for interactive elements
            if (pageId === 'comparison') {
                const featureSelector = document.getElementById('featureSelector');
                featureSelector.addEventListener('change', renderComparisonCards);
                renderComparisonCards();
            }
            if (pageId === 'vdb') {
                const vdbTabs = document.querySelectorAll('.vdb-tab');
                vdbTabs.forEach(tab => {
                    tab.addEventListener('click', () => handleVdbTabClick(tab, vdbTabs));
                });
            }
        }

        function renderComparisonCards() {
            const container = document.getElementById('comparisonContainer');
            const selectedFeature = document.getElementById('featureSelector').value;
            const data = comparisonData[selectedFeature];
            
            container.innerHTML = '';
            for (const lang in data) {
                const card = document.createElement('div');
                card.className = "bg-themed-surface p-6 rounded-lg border border-themed";
                card.innerHTML = `
                    <h4 class="text-xl font-bold mb-2 text-cyan-400">${lang}</h4>
                    <p class="text-themed-subtle leading-relaxed">${data[lang]}</p>
                `;
                container.appendChild(card);
            }
        }
        
        function handleVdbTabClick(clickedTab, allTabs) {
            const targetClass = clickedTab.dataset.target;
            const codeLines = document.querySelectorAll('#vdbExample .vdb-line');
            
            allTabs.forEach(t => {
                t.classList.remove('active', 'text-themed-accent', 'border-themed-accent');
                t.classList.add('text-themed-subtle');
            });
            
            clickedTab.classList.add('active', 'text-themed-accent', 'border-themed-accent');
            clickedTab.classList.remove('text-themed-subtle');

            codeLines.forEach(line => {
                if (line.classList.contains(targetClass)) {
                    line.classList.add('highlight-line');
                } else {
                    line.classList.remove('highlight-line');
                }
            });
        }

        function handleNavigation(event) {
            // Use event delegation
            if (event.target.tagName === 'A') {
                event.preventDefault();
                const pageId = event.target.hash.substring(1);
                
                // Update active link
                navigation.querySelectorAll('a').forEach(link => link.classList.remove('active'));
                event.target.classList.add('active');

                // Render content
                renderContent(pageId);
                
                // Close mobile menu
                sidebar.classList.add('-translate-x-full');

                // Scroll to top of content
                mainContent.scrollTo(0, 0);
            }
        }
        
        mobileMenuButton.addEventListener('click', () => {
            sidebar.classList.toggle('-translate-x-full');
        });

        navigation.addEventListener('click', handleNavigation);

        // Initial load
        renderContent('introduction');

    </script>
</body>
</html>