I Built a Language Where Objects and Dictionaries Are the Same Thing
After two years of compiler development, I just shipped Sona v0.7.0—a language built around one core insight: objects and dictionaries should be unified, not separate concepts.
The Problem I Kept Running Into
I was constantly switching between languages for different parts of the same project:
Python for data processing (great dicts, verbose classes)
JavaScript for logic (great objects, weird edge cases)
Go for performance (verbose everything)
Each language had the right pieces, but never quite fit together. I wanted something that felt as natural as JavaScript's object model but with Python's clarity and none of the historical baggage.
The Core Innovation: Unified Object/Dictionary Syntax
In Sona, there's no distinction between object properties and dictionary keys:
sona// This is a dictionary
let config = {
"app_name": "MyApp",
"version": "1.0.0",
"features": {"auth": true, "analytics": false}
}
// But you can access it like an object
config.debug = true
config.features.logging = true
print(config.app_name) // "MyApp"
Classes work the same way:
sonaclass GamePlayer {
constructor(name) {
this.name = name
this.stats = {"hp": 100, "level": 1}
this.inventory = []
}
method levelUp() {
this.stats.level = this.stats.level + 1
this.stats.hp = this.stats.hp + 10
return this // Enable chaining
}
}
let player = GamePlayer("Alice")
player.levelUp().levelUp()
print(player.stats.level) // 3
Why This Actually Matters
- No context switching between syntaxes sona// Same syntax for everything user.profile.settings.theme = "dark" config.database.host = "localhost" api.endpoints.users.timeout = 5000
- Natural method chaining sonaplayer.spawn() .move(10, 5) .attack("fireball") .collectLoot()
- Seamless data modeling sonalet library = Library("City Central") library.books = [ {"title": "1984", "author": "Orwell", "available": true}, {"title": "Dune", "author": "Herbert", "available": false} ]
// Add methods to existing data
library.findAvailable = function() {
return this.books.filter(book => book.available)
}
The Technical Implementation
This isn't just syntactic sugar. The language is built with:
LALR(1) parser with proper AST design using Lark
Lexical scoping with full closure support
Method resolution order for inheritance
Unified property access across all object types
Python ecosystem integration without Python's syntax quirks
The object model treats everything as a dictionary with methods, but with proper OOP semantics for inheritance and method dispatch.
Real-World Examples
Configuration management:
sonalet config = loadConfig("app.json") // Returns a dict
config.validateRequired() // But has methods
config.database.reconnect() // Nested objects work naturally
Game development:
sonalet enemy = Enemy("goblin")
enemy.ai = {"aggression": 0.7, "patrol_range": 50}
enemy.ai.decision_tree = DecisionTree()
enemy.think().move().attack()
Data processing:
sonalet data = parseCSV("sales.csv")
data.forEach(row => {
row.profit = row.revenue - row.costs
row.margin = row.profit / row.revenue
})
What's Next
v0.8.0 roadmap:
Enhanced class system with multiple inheritance
Pattern matching for data structures
LSP support for IDE integration
Package manager for module distribution
Performance optimizations
Longer term:
Bytecode compilation for performance-critical code
Web assembly target for browser deployment
GUI framework leveraging the unified object model
Why I Built This
I didn't build Sona because the world needed another language. I built it because I kept hitting the same friction points:
Switching between obj.prop and dict["key"] syntax
Verbose class definitions for simple data structures
Inconsistent method chaining across different object types
Context switching between languages for different parts of the same project
Sona is my attempt to create a language that feels consistent and predictable while still being powerful enough for real work.
Try It Out
The language is mature enough for real experimentation:
GitHub: https://github.com/Bryantad/Sona
Documentation: Comprehensive examples and language guide
REPL: Interactive development environment
Standard library: Math, string, I/O, HTTP client, JSON parsing
The Bigger Picture
This project taught me that small, consistent design decisions compound into something that feels completely different. Sona doesn't have any revolutionary features—it just makes a few things work the way you expect them to.
If you've ever found yourself fighting with a language's object model or wishing for more consistent syntax, I'd love your feedback. The goal isn't to replace your production stack, but to offer a cleaner tool for prototyping, scripting, and learning.
What do you think? Does unified object/dictionary syntax solve real problems, or is this just elegant complexity?
Follow the project on GitHub and let me know what you build with it. The best way to validate a language design is to see what people create when they're not fighting the syntax.
Top comments (0)