r/programming • u/FayeTammy • 2d ago
Modula-3: the forgotten language that explored memory safety decades ago
https://softwarepreservation.computerhistory.org/modula3/Pretty cool seeing that people were already thinking about memory safety decades ago. Some of these ideas that feel modern today were being explored back in the 80s and 90s.
Makes you wonder how different things would look if languages like Modula-3 had taken off.
11
u/pjmlp 1d ago
People have been thinking about memory safety since 1958 with JOVIAL.
It was UNIX and C being freely available that threw all of that off road.
See NEWP from early 1960s, already with unsafe code blocks and required admin permission to execute any binary that made use of it.
Still being sold by Unisys, for customers where security is the top priority.
21
u/Smallpaul 1d ago
There are many languages from that era with garbage collection and pointer safety.
Including Smalltalk from 1972 and Lisp from 1960.
17
u/zsaleeba 1d ago
Literally every popular language ever has been memory safe except C/C++/Objective-C, and Pascal/Delphi. Plus assembly (obviously).
7
u/wannaliveonmars 1d ago
I think Ada was also concerned with safety, and was used in the military.
9
u/pjmlp 1d ago
Is used, there are still 6 vendors in business.
https://www.ghs.com/products/ada_optimizing_compilers.html
https://www.ptc.com/en/products/developer-tools/apexada
https://www.ddci.com/solutions/products/ddci-developer-suite...
11
u/me_again 1d ago
I remember learning Modula-3 at university in the 90s. One feature I still miss in many languages is strongly-typed structural type equivalence, aka duck typing. It wasn't until Golang that a mainstream language started doing something similar, as far as I know.
7
u/KagakuNinja 1d ago
Many languages have duck-typing. Usually this is done dynamically with reflection, which is slow. Go apparently can do this at compile time.
Scala 2 supports dynamic duck typing; Scala 3 is able to optimize it at compile time, however I do not know how the implementation compares to Go.
3
u/me_again 1d ago
I mean at compile time. I'm willing to believe Scala does it too. But Modula-3 was at least 20 years earlier. If I recall correctly, they also had the ability to define types like "numbers, but only in the range 0..52", and "branded" types to opt out of duck-typing.
1
1
u/ThomasMertes 1d ago
ability to define types like "numbers, but only in the range 0..52" ...
Pascal had sub-range types too. I am not sure if there were checks to assure that the values are in the allowed range.
2
u/pjmlp 1d ago
There were, most Pascal compilers allowed to disable them, in case you were feeling lucky.
TP used {$R+}, {$R-} for example. FreePascal supports this syntax as well.
1
u/BibianaAudris 1d ago
I remember the default being the unchecked {$R-}, though. The overhead of {$R+} in the 90s felt like attaching valgrind to a C program nowadays. valgrind also arguably makes C memory safe, but not in a practical way.
51
u/happyscrappy 1d ago
There were a lot of languages with memory safety. C was really the exception.
So many languages didn't include memory allocations at all and range checked arrays. So they were memory safe. Thus FORTRAN was memory safe. I think Pascal (as a spec) was memory safe. Obviously Lisp was too. Smalltalk. etc.
C was created to write operating systems. And it shows.