The Case for a New Programming Language

Disclaimer: I only know web frontend/backend and mobile development with several teams. So everything I say needs to be seen in this context.

In beginning of the 90s I was writing internet code in C directly using TCP/IP as an ‘abstraction’ layer. Bugs were plenty and development was a pain. Then Java arrived and made development much more pleasant. Java with exceptions created nicer to read exception stack traces than C did with core dumps and also prevented many common C bugs.

  • With automatic garbage collection Java has a lot less memory leaks compared to C with manual memory management with malloc/free
  • With typed references you can be sure the data sent to a method is of type T whereas pointers in C could point to anything
  • Without pointer arithmetic Java prevents a class of bugs from corrupted pointers
  • Exceptions force developers to deal with error states, much better than magic return codes in C
    • A recent study pointed out that most total outages of SaaS components are caused by sloppy error handling
    • Sadly Java implemented exceptions in a way that makes most people hate them.

After it’s initial leap to prevent bugs, Java lost it’s focus on creating a better language than C with some minor exceptions later, e.g. Generics to prevent class cast exceptions.

Reasons for bugs in general from my experience:

  • Requirement Bugs
    • Missing requirements
    • Interfering complex requirements
    • Misunderstood requirements
  • State Bugs
    • Consistently modifying complex (interdependent) state, e.g. in concurreny but also elsewhere, is hard
    • Uninitialized state (null pointer exceptions)
      • Not injected
        • Not set during construction
    • Reuse of variables
  • Problems with method overloading
  • Not understanding existing code

Most of the programming languages that came after Java focused on power instead of safety – on and off the JVM. Some have features to prevent bugs like nullable types or no overloading, but none makes bug prevention their main goal.

Why should a language make bug prevention make their main goal instead of more powerful expressiveness?

Bugs cost a lot of time, rework and motivation. If a bug is detected after release it takes some effort and money to fix (replicate, test, decide if it’s a bug, track bug, find root cause, fix, write tests, retest, release). Even with the best way to handle bugs (fix them first), they impact development schedules and create uncertainty. I’ve also found few developers that enjoy fixing bugs. For many fixing bugs demotivates them. Finding bugs also lowers the perception of  product quality. This alienates developers from their work. Fixing bugs also get’s developers and product managers out of their productivity and creativity zones. After ‘managing’ development in some companies I’ve come to the conclusion that a zero bug policy is the best way to handle those critters. A language that reduces or makes it impossible to write bugs could have a huge impact on development (Why more powerful expressiveness is not a good programming language goal I’ll cover in another post).

So from my perspective there is a need for a programming language that focuses to prevent more classes of bugs and makes code easy to read.

Some thoughts what this language would look like compared to e.g. Java:

  • No inheritance
  • “Count ” + i does not work (auto convert of Int to String) – No type coercion
  • No method overloading
  • Only ‘data’ classes which implement automatically provide copy, equals, hashcode, …
  • Possible to declare functions as pure (pure can only use pure)
  • No Null Value
  • No Security Bugs (Unsafe Strings, Type HtmlString, SafeString etc.)
  • Use of modules, “module A uses B,C”, check violations
  • Good compiler errors e.g. like in Play Framework or Elm
  • Use Option everywhere in the standard library, support Monads with language constructs
  • Nativ support for type constraints (tagged unboxed types) like String ~ Email
  • No features that are risky, hard to understand or with which you could shoot your foot off
  • One right way to do things
  • As few magic as possible

Currently I don’t see any new language (JVM or other) to address all of this. So this makes me play with some languages I could fork to start this new language – but I have no clue about compilers. Kotlin would be an excellent base and I’m currently looking into what ideas Ceylon and Fantom bring to the table to prevent bugs.

If you have ideas how to make a language safer, what bugs you’ve seen often or general feedback, reply to @codemonkeyism