Skip to content
TheChatArchiveThe Chat Archive
Claudeclaude-opus-4-20250514· AnthropicHugging Face LMArena Human Preference 140K

I have an aversion to object oriented design. I'm using python and am designing an…

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with Geminigemini-2.5-pro-preview-05-06’s answer.
  1. User

    I have an aversion to object oriented design. I'm using python and am designing an entity with data and behavior which in OO design would naturally map onto an object. Give me a package namespace / functional alternative to something like class MyEntity.

  2. Claude Assistant

    Here's a functional approach using a package namespace structure:

    myentity/
    ├── __init__.py
    ├── data.py
    ├── operations.py
    └── validators.py
    

    myentity/data.py

    from typing import NamedTuple, Dict, Any
    
    # Immutable data structure
    class EntityData(NamedTuple):
        id: str
        name: str
        value: float
        metadata: Dict[str, Any]
    
    # Constructor function
    def create(id: str, name: str, value: float, metadata: Dict[str, Any] = None) -> EntityData:
        return EntityData(id, name, value, metadata or {})
    

    myentity/operations.py

    from .data import EntityData
    
    def update_value(entity: EntityData, new_value: float) -> EntityData:
        return entity._replace(value=new_value)
    
    def add_metadata(entity: EntityData, key: str, value: Any) -> EntityData:
        new_metadata = {**entity.metadata, key: value}
        return entity._replace(metadata=new_metadata)
    
    def calculate_score(entity: EntityData) -> float:
        return entity.value * len(entity.metadata)
    

    myentity/validators.py

    from .data import EntityData
    
    def is_valid(entity: EntityData) -> bool:
        return (
            entity.id != "" and
            entity.name != "" and
            entity.value >= 0
        )
    
    def validate_value_range(entity: EntityData, min_val: float, max_val: float) -> bool:
        return min_val <= entity.value <= max_val
    

    myentity/init.py

    from .data import create, EntityData
    from .operations import update_value, add_metadata, calculate_score
    from .validators import is_valid, validate_value_range
    
    __all__ = [
        'create',
        'EntityData',
        'update_value',
        'add_metadata',
        'calculate_score',
        'is_valid',
        'validate_value_range'
    ]
    

    Usage:

    import myentity
    
    # Create entity
    entity = myentity.create("123", "example", 42.0)
    
    # Operations return new instances
    updated = myentity.update_value(entity, 50.0)
    with_meta = myentity.add_metadata(updated, "category", "premium")
    
    # Validation
    if myentity.is_valid(with_meta):
        score = myentity.calculate_score(with_meta)
    

    This approach gives you:

    • Clear separation of data and behavior
    • Immutable data structures
    • Pure functions that return new instances
    • Namespace organization without classes
    • Easy testing of individual functions
    • No hidden state or side effects
  3. User

    Is there a formal name for this design practice? How popular is it versus OO? Is it gaining / losing popularity? How popular is it in python specifically versus other languages? Is there a language where this type of pattern is dominant over OO?

  4. Claude Assistant

    This design practice is most commonly called Functional Programming (FP), though the specific pattern you're asking about combines several concepts:

    • Functional Core, Imperative Shell - Gary Bernhardt's term for isolating pure functions from side effects
    • Data-Oriented Design - Separating data structures from functions that operate on them
    • Procedural Programming with Immutability - When you use modules/namespaces without classes but with immutable data

    Popularity vs OO

    Object-oriented programming still dominates in industry, but functional programming has been steadily gaining ground since around 2010. The trend isn't strictly "FP replacing OO" but rather "multi-paradigm" approaches becoming more common. Many developers now use functional concepts within primarily OO codebases.

    In Python Specifically

    Python is interesting because:

    • The language itself is multi-paradigm and doesn't force either approach
    • The standard library and most popular frameworks (Django, Flask) are heavily OO
    • However, there's a growing functional Python community using libraries like:
      • toolz / cytoolz for functional utilities
      • pyrsistent for immutable data structures
      • returns for functional error handling
      • Type hints with NamedTuple and dataclasses with frozen=True

    The pattern is less common in Python than in languages with stronger FP traditions, but it's definitely used in data science, financial computing, and by teams with FP backgrounds.

    Languages Where FP Dominates

    Several languages make this pattern the default or only option:

    Pure Functional Languages:

    • Haskell - No mutable state, everything is functions and immutable data
    • Elm - Similar to Haskell but for frontend web development
    • PureScript - Haskell-inspired, compiles to JavaScript

    Functional-First Languages:

    • Clojure - Immutable by default, namespace-based organization
    • Elixir/Erlang - Module-based, no classes, immutable data
    • F# - Supports OO but functional is idiomatic
    • OCaml/ReasonML - Module system instead of classes

    Multi-paradigm but FP-friendly:

    • Rust - Has structs and traits instead of classes, encourages functional style
    • Scala - Supports both but many teams use it functionally
    • JavaScript - Increasingly functional with React, Redux, and immutability libraries

    The trend seems to be toward languages and frameworks that support both paradigms, letting teams choose based on the problem domain.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.