DEV Community

Jack Delahunt
Jack Delahunt

Posted on

Fixing C++ with a new open source project

If you have ever written any code in C++ I first want to say sorry for all the needless pain you have been through but I am trying to make your life easier.

Many people have given their opinion on C++ and why they either don't like it or why you should never use it. Personally I actually do like C++ for the most part but there are some very obvious issues that can be addressed.

The first problem is how C++ compilers deal with parts of your code needing other parts and how it doesn't deal with them at all. Use before declaration and out of order declarations are normal and expected in a normal language and C++ does not and will not ever have this. You can see how old school C++ really is when you have to start thinking about header files and how they are included. These are just issues that shouldn't exist anymore.

// its 2022 this should work...
struct Bar {
   Foo foo;
};

struct Foo {};
Enter fullscreen mode Exit fullscreen mode

C++ also has an issue of trying to be every language in existence all at once. To this day I don't think a single person knows what every keyword means and most still don't know all the ways to use static. Normally I wouldn't be annoyed by this but the fact that using seven keywords in a function declaration is considered "best practice" is enough for me to bring it up.

// how Bjarne Stroustrup writes foo examples
virtual int inline long constexpr volatile unsigned const long foo() const noexcept = delete;

Enter fullscreen mode Exit fullscreen mode

I couldn't bring up the flaws of C++ without talking about the STL. It is honestly the saddest part of the language. Want to see the data within this object when debugging? Want to have short compile times? Want to know how and when your memory is being deallocated? Well good luck because the STL fails on all of these issues.

This is where my new and hopefully improved solution comes in but with some asterisks. My goal is to create a language as simple as C but with more modern features that C++ also provides but correctly this time. There is no need to complicate the language itself as we do not need extra problems to solve as developers, this is where languages such as C and Go inspired me.

Some things my language has or plans of having.

  • Easy to use generic functions and structs
  • Absolutely 0 exceptions
  • Absolutely 0 constructors
  • Absolutely 0 destructors
  • Clear separation of static strings and mutable ones
  • Absolutely 0 private anything
  • Custom allocators that you can be set project wide (including stdlib)
  • Absolutely 0 header files
  • Declare your structs and functions in any order
  • Auto pretty printing of any struct

I said before there were some asterisks to all this. While C++ has a lot of issues with has a huge amount of support, every library you know is probably usable in C or C++ and throwing that all out would be a shame. That is my Liam generates C++, and in fact the standard library for Liam is all written in C++ but just made available in Liam through some features in the language. To get people to leave C++ I do need to keep it around just long enough so people can jump ship.

The plan is to have already written C++ code made available in Liam without having to rewrite libraries all over again currently this is still in development but basic features are working.

Here is some syntax samples of the language, everything here is working and already implemented.

import "stdlib/io.liam";

struct Person {
   name: String,
   age: u64
}

fn main(): u64 {
    let person := new Person {
        # this is not cpp new does not heap alloc
        make_string("your name"),
        25
    };

    print[String](person.name);
}
Enter fullscreen mode Exit fullscreen mode

Please checkout and even contribute here. I would love to see what the community can do for the project.

Top comments (0)