惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

A
About on SuperTechFans
小众软件
小众软件
WordPress大学
WordPress大学
Microsoft Azure Blog
Microsoft Azure Blog
Recent Announcements
Recent Announcements
博客园 - 三生石上(FineUI控件)
博客园_首页
N
Netflix TechBlog - Medium
IT之家
IT之家
H
Help Net Security
博客园 - 聂微东
Google DeepMind News
Google DeepMind News
罗磊的独立博客
T
Tailwind CSS Blog
F
Fortinet All Blogs
Hugging Face - Blog
Hugging Face - Blog
MongoDB | Blog
MongoDB | Blog
V
V2EX
量子位
云风的 BLOG
云风的 BLOG
爱范儿
爱范儿
博客园 - 司徒正美
The Cloudflare Blog
Engineering at Meta
Engineering at Meta

Stonecharioteer on Tech

I Traced My Traffic Through a Home Tailscale Exit Node What Was I Reading Last? In Three Not-So-Easy Pieces Dogfooding Is Hard Code blocks in your books, finally GoForGo v0.9.0 Merrilin - We built an app to read books I use a Macbook now Data Structures & Algorithms - Preparing for Interviews Using a local DNS namespace for local service discovery Direction KOllector - Publishing KOReader Highlights gbt: branches touched in the last 24 hours A Soiree into Symbols in Ruby Some Smalltalk about Ruby Loops Ruby Blocks Returning from Ruby Blocks, Procs and Lambdas My Linux Laptop Finally Works: How Claude Helped Me Fix Years of Annoyances TIL: Watchexec - Modern File Watching for Development Workflows A Less Busy Mind GoForGo - Learn Go through live examples Migrating My Old Blog to Hugo with Claude The Qtile Window Manager: A Python-Powered Tiling Experience Read the RFCs that Built the Internet Py-x-Protobuf - Or How I Learned to Stop Worrying and Love Protocol Buffers Python Reverse a List New Beginnings Leaving ChainSafe Systems Screen Lock for Cinnamon Desktop using Zenity and Terminal Commands Crews Not Teams A System for Getting Better at LeetCode
TIL: Architecture of Open Source Applications, Compiler D...
2020-09-16 · via Stonecharioteer on Tech

Today’s learning focused on understanding complex software architectures and language implementation techniques.

The Architecture of Open Source Applications provides detailed architectural analysis of major open source projects:

Volume Coverage:

Infrastructure Projects:

  • Apache web server: Multi-process architecture and module system
  • PostgreSQL: Query planning, storage engine, and ACID compliance
  • MySQL: Storage engines, replication, and performance optimization
  • Redis: In-memory data structures and persistence strategies

Development Tools:

  • Git: Distributed version control architecture
  • Mercurial: Alternative DVCS design decisions
  • Eclipse: Plugin architecture and IDE extensibility
  • LLVM: Compiler infrastructure and optimization passes

Application Frameworks:

  • Django: Web framework architecture and ORM design
  • Rails: Convention over configuration philosophy
  • jQuery: JavaScript library design patterns
  • Node.js: Event-driven architecture and non-blocking I/O

Architectural Insights:

Common Patterns:

Plugin Architecture:
- Core system provides stable API
- Extensions add functionality without core changes
- Examples: Eclipse, Apache modules, browser extensions

Layered Architecture:
- Clear separation of concerns
- Each layer depends only on lower layers
- Examples: Network stacks, operating systems

Event-Driven Architecture:
- Components communicate via events
- Loose coupling and high scalability
- Examples: Node.js, GUI frameworks

Performance Considerations:

  • Caching strategies: Redis, web servers, databases
  • Memory management: Garbage collection vs manual allocation
  • Concurrency models: Threading, async/await, actor systems
  • Data structure choices: Hash tables, B-trees, bloom filters

Compiler Development Resources

Comprehensive Compiler Articles

Phil Eaton’s Compiler Articles provide practical, hands-on compiler development guidance:

Language Implementation Steps:

  1. Lexical Analysis: Tokenizing source code
  2. Parsing: Building abstract syntax trees
  3. Semantic Analysis: Type checking and symbol resolution
  4. Code Generation: Producing target code
  5. Optimization: Improving performance and size

Practical Implementation:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Simplified tokenizer example
#[derive(Debug, PartialEq)]
enum Token {
    Number(i64),
    Identifier(String),
    Plus,
    Minus,
    LeftParen,
    RightParen,
    EOF,
}

struct Lexer {
    input: Vec<char>,
    position: usize,
}

impl Lexer {
    fn next_token(&mut self) -> Token {
        self.skip_whitespace();

        match self.current_char() {
            Some('+') => { self.advance(); Token::Plus }
            Some('-') => { self.advance(); Token::Minus }
            Some('(') => { self.advance(); Token::LeftParen }
            Some(')') => { self.advance(); Token::RightParen }
            Some(c) if c.is_ascii_digit() => self.read_number(),
            Some(c) if c.is_ascii_alphabetic() => self.read_identifier(),
            None => Token::EOF,
            _ => panic!("Unexpected character: {:?}", self.current_char()),
        }
    }

    fn read_number(&mut self) -> Token {
        let mut number = String::new();
        while let Some(c) = self.current_char() {
            if c.is_ascii_digit() {
                number.push(c);
                self.advance();
            } else {
                break;
            }
        }
        Token::Number(number.parse().unwrap())
    }
}

Cannoli - Python Compiler in Rust

Cannoli demonstrates implementing a Python subset compiler in Rust:

Architecture Overview:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// AST representation
#[derive(Debug, Clone)]
pub enum Expr {
    Number(i64),
    String(String),
    Identifier(String),
    BinaryOp {
        left: Box<Expr>,
        op: BinaryOperator,
        right: Box<Expr>,
    },
    Call {
        func: Box<Expr>,
        args: Vec<Expr>,
    },
}

#[derive(Debug, Clone)]
pub enum Stmt {
    Expression(Expr),
    Assignment {
        target: String,
        value: Expr,
    },
    If {
        condition: Expr,
        then_body: Vec<Stmt>,
        else_body: Option<Vec<Stmt>>,
    },
    While {
        condition: Expr,
        body: Vec<Stmt>,
    },
}

Code Generation Strategy:

  • Target LLVM IR for optimization and portability
  • Implement Python semantics (dynamic typing, reference counting)
  • Handle Python-specific features (list comprehensions, generators)
  • Provide runtime support for built-in functions

Oil Shell - Unix Shell in Python Subset

Oil Shell represents a modern approach to Unix shell design:

Design Goals:

Compatibility and Innovation:

  • Bash compatibility: Run existing shell scripts
  • Oil language: New shell language with better syntax
  • Type safety: Optional typing for shell variables
  • Error handling: Better error reporting and debugging

Architecture Improvements:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
# Traditional bash
if [ -f "$file" ]; then
    lines=$(wc -l < "$file")
    if [ "$lines" -gt 100 ]; then
        echo "Large file: $lines lines"
    fi
fi

# Oil shell equivalent
if test -f $file {
    var lines = $(wc -l < $file)
    if (lines > 100) {
        echo "Large file: $lines lines"
    }
}

Implementation Strategy:

Python-Based Implementation:

  • Written in OPy (Oil Python) - a subset of Python
  • Transpiles to Python for execution
  • Uses Python’s parsing and AST capabilities
  • Leverages Python’s standard library

Language Features:

# Variables with types
var name: Str = "example"
var count: Int = 42
var files: List[Str] = glob("*.txt")

# Better string handling
var msg = "Hello $name, you have $count files"

# Structured data
var config = {
    host: "localhost",
    port: 8080,
    debug: true
}

# Error handling
try {
    var result = $(command_that_might_fail)
} catch {
    echo "Command failed"
    exit 1
}

Supporting Resources

LaTeX Learning

Understanding LaTeX syntax and best practices, particularly for technical documentation and mathematical notation in compiler documentation.

Educational Compiler Projects:

  • Small-C: Historical compiler for C subset
  • LLVM tutorials: Official documentation for compiler backend
  • “So You Want to Be a Compiler Wizard”: Career guidance for compiler developers

Advanced Topics:

  • JIT compilation: Runtime code generation techniques
  • Functional programming: Implementing languages with first-class functions
  • Python singledispatch: Method overloading for interpreter implementation

These resources provide comprehensive coverage of both the theoretical foundations and practical implementation techniques needed for understanding and building complex software systems, from compilers to shells to large-scale applications.