Simply, a memory safe language prevents memory related bugs. These bugs are usually in the form of accessing or setting areas of memory they should not be able to. The problem is the program may continue to run despite the memory having been corrupted meaning the program may give incorrect results. There are tools that can help find possible errors in existing C/C++ code but they are not always reliable. It makes sense to use a language that has safety as a priority when creating new programs and to investigate moving old programs to one of the newer languages.
One method a language may use to be memory safe is through the use of a Garbage Collector (GC). This runs with the program and handles memory allocations and access, if the program tries to access memory it shouldn't, the program will stop and throw up an error. The penalty for using a GC is that they can make the programs slower and they use more memory. These are both becoming less of an issue through more advanced compilers and GC's.
Rust is different in that it uses an ownership memory model which means it does not have or need a GC, memory allocation and access can be verified at compile time.
This is not an exhaustive list of languages, just the most popular and ones I have actually used. The number of ticks and crosses does not indicate how good or bad a language is, just how many good or bad points I can remember. I may refer to the languages standard library as well as the actual language as well.
This refers to C# on .NET Core / 5+, not the 4.8 Framework version.
C# can be used for almost everything, from mobile development to server side programs. Given that it is used to run many Microsoft
services, they make sure each version is faster and more memory efficient than the one before, there are many blog posts
detailing the improvements made and how it has reduced Microsoft's requirements and saved them money.
At the other end of the spectrum, I have ported some of my old C# programs to the latest version and have indeed noticed the programs have been quicker and used less memory. The real problem I find is the short support length. At the time, I converted my programs to .NET 3.1 and they worked great and made use of the newer features. Now the 3.1 runtime is not available, the programs will not run unless I recompile them for a newer version of .NET (8?). New versions of .NET also drop support for older operating systems too.
If the above can be ignored, C# has a lot going for it as highlighted below. There is the issue that most users will not have the latest .NET Runtime installed but Microsoft are clear on what needs to be installed. There is also the option to build your exe with the required .NET components included in it which may be useful in some situations though it does mean a much bigger exe.
✔️ Getting faster and more memory efficient with each version!
✔️ Supports a wide range of processors and operating systems (to a degree).
✔️ Great documentation usually with clear examples.
✔️ C# and its Standard Library offer support for many tasks meaning you can avoid reinventing the wheel.
➖ On platforms that are not Windows, you cannot make GUI based applications.
❌ Compiling is not quick which does slow the build-test cycle
❌ Short support length, even using LTS versions means recompiling every 3 years to run on supported runtime.
❌ Most users will not have the necessary .NET Runtime installed.
Click the link for more about C# and .NET.
In the past I have describe D as a nicer C compiler with some useful extras added. Although not 100% memory safe yet, it is getting better and for the most part, bounds checking is the main thing I am interested in. I have ported some C programs to D and it was fairly straight forward, during this process, missed errors were caught which is great. One of the great features about D is the fast compilation times, that and clear error messages help speed up the development progress. D also features lots of advanced features which I do not use such as template and mixins.
Like many languages listed here, D's memory management is handled by a garbage collector. Although optional, it is required by most programs that do anything complicated. D's garbage collector is not as advanced as Java or C#'s but using the built in profiler, it is easy to see where allocations are happening and adjust accordingly. The profiler is very easy to use and has helped me fine tune many of my programs.
The standard library is not as fully featured as those of C# or Java which may limit what D can be used for out of the box but it's speed, ease of use and C migration features (such as importC) make it a good choice for many tasks. Although the forum is full of improvement ideas, they are slow to appear. Documentation is also a bit weak which is one of the reasons I have put a few documents in the D section of this website.
The language is far from perfect (I would like to see it steal some niceties from Go) but I liked it enough to give it its own section on this website.
✔️ Very fast compilation times and easy to use compiler.
✔️ Familiar language syntax makes it easier to use.
✔️ The built-in debug tool for viewing allocations is great and underrated.
✔️ Produces standalone exe files that are not dependant on a separate runtime or virtual machine.
➖ Not as fully featured as some languages listed but also not backed by a mega corp...
❌ Not completely safe by default yet.
❌ The default compiler does not produce the quickest code.
❌ Progress on improving the language is slow.
Visit the D Programming Language website.
Designed at Google, Go focuses on simplicity and safety. Go is a general purpose language but it has a focus on networking, this not too surprising coming from Google. Despite this, the language is good for a lot of uses and comes with a nice set of tools for profiling and maintaining code. The language removes a lot of features present in other languages to keep things simple which makes it quick to learn. The syntax is a bit different from the usual C style but does not take long to get used to. Programs made with Go are also very fast and build fast, though a straight port of a C/C++ program to Go may not be optimum and you may need to look up the Go way of doing things.
The compiler forces good practice by giving errors about unused variables and 'go fmt' will format your code in the preferred layout.
✔️ Produces standalone exe files that are not dependant on a separate runtime or virtual machine.
✔️ The language is much simpler than most here which makes it quick to learn.
✔️ As it is used by Google, they have great incentive to make it quicker and reduce memory usage which they do!
✔️ Built-in code formatter 'go fmt' is great!
✔️ Supports a wide range of processors and operating systems.
❌ The language is missing some useful features.
❌ Exe files can relatively large for small programs.
Find out more about Google Go.
Java programs can run on any computer that has a Java Virtual Machine (JVM) on it. For example, the Java Jar files on this site can run on Mac's or Windows PC exactly as they are. This is one of the major advantages of Java. As Java is an open language, you can find builds of it made by many companies, I use the one by Adoptium but you can also get Java builds from Amazon and even Microsoft.
Java has been around for many years and can be used for most tasks, from server tasks to GUI applications. The main arguments against Java are usually down to application speed (less of an issue now) and memory usage. I find Java nice to use and the compiler very quick which helps development. The other main downside to Java is most users are unlikely to have it installed.
✔️ Write Once Run Anywhere if the target computer has Java installed, even GUI apps.
✔️ Very long support. I am holding at Java 11 which is supported until 20232.
✔️ Fully featured language / standard library with great documentation and examples.
✔️ Great backwards compatibility.
❌ Most users will not have Java installed and knowing what to install is not clear.
❌ Java programs usually use more memory than those made with the other languages listed here.
Get the Adoptium Java installer.
Rust is a memory safe language that does not rely on a runtime to handle memory management. The method of memory safety Rust uses is ownership memory model with a borrow checker. More simply, the compiler tracks where and how memory is used rather that relying on a 'garbage collector' that runs with the program and manages memory. This means the programs are faster though compilation is slower.
The main project of note that uses Rust is the Firefox browser but it is starting to be used more and more by companies like Microsoft and Google more.
✔️ Produces very very fast exe files. The Rust version of my Iff2Bmp was much faster than the other versions.
✔️ Produces standalone exe files that are not dependant on a separate runtime or virtual machine.
✔️ Although not quick, the compiler is very helpful at pointing out issues and offering how to fix them.
➖ No random numbers by default...
❌ Porting programs can be tricky due to the borrow checker and how differently memory is managed.
❌ Complicated syntax
Click for more information about Mozilla Rust.
Zig gets a mention purely as it is starting to get more attention. It is not 100% safe but it is also not near a version 1.0 release yet. Many of the release modes include a Safe option and by default, it includes some safety checks. It is looking to target the same low-level market that Rust (and D) are in.
Given that the language is still in the early stages and I've not used it for much more than simple 'Hello World' programs, it would be unfair to do a lists of tick and crosses. Check it out using the link below:
Find out more about the Zig programming language.
Created
18 / 08 / 2024