logoalt Hacker News

kgeisttoday at 2:02 PM2 repliesview on HN

I applaud the effort, but every time there's a new hobbyist programming language on HN, almost always it's something I've already seen in countless other hobbyist languages, just a slight variation of it based on the author's personal tastes. It doesn't tell me why I should adopt it over language X. What I'd like to see is exploration of novel practical ideas that would make certain types of projects much faster to write/read compared to most other languages.

For example, a typical web service I work on:

    - uses JSON APIs
    - it's fully stateless (uses external DBs/caches for persistence)
    - has the concepts of value objects, entities, architectural layers (app, domain, infra), ports/adapters etc.
    - only entities are proper rich objects, while most of the code is stateless services that operate on requests + entities + value objects
    - stateless services are composed (via interfaces) into a dependency tree (stored in the dependency container)
Currently I'm playing around with an idea for a language that makes writing things like that fast and compact to read. Something like:

    module my_service

    layer app {
        service Adder {   // stateless service
            uses base int // a value-based dependency, injected in the container below

            method add(x int) int {
                return base + x
            }
        }

        service Doubler {
            uses a Adder  // delegates to another service

            method double(x int) int {
                return a.add(x) + a.add(x)
            }
        }
    }

    container {       // dependency container construction with injections
        A = Adder { base: 10 }
        D = Doubler { a: A }
    }

    // automatically generates a web server that exposes a JSON API with method "double" and accepts the "n" argument
    endpoint double(n int) int {
        return D.double(n)
    }
This is a synthetic example, but you get the idea (entitites and value objecst omitted here)

What do you think? Does it make sense? It basically moves something usually implemented by a framework into the language, but that's the entire point: a language optimized for writing compact, architecturally safe stateless services in a few lines of code. For example, since we know a request's memory is bound to that request (no global state), we can have very optimized memory management without a full GC => improved latency. Or for example, we can have compile-time checks for things like dependency direction validation (i.e. the domain layer cannot reference the infrastructure layer) to keep the architecture clean, etc.


Replies

jjicetoday at 2:25 PM

I like these hobby languages just because they help expose and experiment with interesting higher level language constructs. Because of that, I don't really care if they try to sell me on the language or not.

As for your concept, I think this is super interesting. A language catered towards higher level abstractions that we use for web services these days is very appealing. The service and container constructs are particularly enticing.

onlyrealcuzzotoday at 4:13 PM

I would recommend building a macro system and/or library for an existing language - that most closely aligns with your goals.

It seems like your goal is to make things more declarative / readable.

Creating a language is a pretty large undertaking, and unless you need to do it to achieve your goals, I wouldn't recommend it - unless you really just want to see what it's all about and make one.