I understand that requiring var inside structs was likely inherited from Swift. However, this makes Mojo and Swift clear outliers among modern languages.
Most other languages do not require any extra keyword for struct/record fields:
- C++:
std::string name; - Rust:
name: String, - Go:
Name string - Zig:
name: []const u8, - Python (dataclasses):
name: str
In all these cases, the surrounding struct context already makes the intent obvious. Forcing var here adds visual noise without providing additional value.
This appears to go against Chris Lattner’s stated design philosophy for Mojo:
“In Mojo however, we intentionally stay close to Python to make it easier to learn (and many other reasons). The cases we diverge (e.g. requiring static types) are related to the core mission and use-cases we need to support.”
I don’t see how requiring var in struct fields serves the core mission. Rust, Go, and Zig show that statically typed, compiled languages can do perfectly well without it.
This fits into the broader pattern I’ve raised before: var is currently overloaded across too many contexts (local variables, function parameters, struct fields, etc.). It seems the var keyword is sometimes defended based on historical habit rather than questioning whether it truly adds value in every context.
While this may feel familiar to Swift developers, it creates unnecessary friction for Python developers — Mojo’s main target audience.
A cleaner approach, consistent with my earlier proposal, would be as simple as:
struct Person:
name: String
age: Int
I’m sharing this feedback because I genuinely want Mojo to succeed and offer the best possible experience for Python developers. An outside perspective can sometimes be helpful.
Happy to hear the team’s thoughts on this.
