DEV Community

Discussion on: Explain "Memory Safe Programming Languages" Like I'm Five Please

Collapse
 
chaotic3quilibrium profile image
Jim O'Flaherty

If it wasn't such a poorly defined concept, then it might be possible to explain it, and then figure out how to reduce it to something consumable by a 5 year old.

However, "Memory Safe Programming Language" is a poorly defined concept. Why? Because it doesn't explain what "memory safe" means.

Technically, any FP (Functional Programming Language) practicing the fundamentals of "immutability" and "function referential transparency" are very "memory safe" from the perspective of not being able to change the state of a variable once it has been initialized.

Here's how Google's Gemini summarizes this.

And here is a great summary of the various FP languages and how they provide advantages.

That said, Java, C++, and even C can be made to be "memory safe" if one were to chose to very carefully and explicitly use immutability and "referential transparency".

In the end, the "Memory Safe Programming Language" is a false concept. All there can be are programming languages that make it more difficult to program incorrectly and which are more restrictive around how data is actually controlled.

tl;dr Technically, no such thing as "Memory Safe Programming Language" exists. That is fallacious concept that entirely misplaced the responsibility for effective and quality software design on a programming language instead of on the actual cause of the problems which is bad software engineering theory and practices.

Collapse
 
prosfilaes profile image
David Starner

Proper engineering means using the right the tools for the job. For physical construction, there's laws about this, because engineers have long learned that "effective and quality ... design" doesn't work if a building is built out of bad materials. They didn't blame some vague bad engineering theory and practices for the Grenfell Tower fire; they put the blame for the deaths on the use of flammable cladding.

Technically, there's no such thing as a "functional programming language" exists. It's a poorly defined concept that doesn't explain what "functional" means, and more precise definitions vary widely. But in reality, there's a general understanding of what a functional programming language is.

Likewise, "memory safe programming language" is not an entirely clear concept, but we should be able to agree that any language that can define an array of five elements and let you write to memory outside that array by accessing element 100 is not memory safe. That, and the ability to deallocate memory and then write to it, despite other parts of the code believing they have exclusive access to it, are the two issues that people have used to hack into systems that have generally be identified as a lack of memory safety.

Collapse
 
chaotic3quilibrium profile image
Jim O'Flaherty

I'm pretty sure you just repeated what I said, just in a passively aggressively oppositionally defiant tone.

Whatever floats your emotional boat, LOL!

Collapse
 
monjai profile image
mon-jai

I asked Gemini the same question. Here's how it response,

Imagine you're building a tower with blocks. Memory safe programming languages are like special sets with interlocking pieces. They make sure the blocks fit together correctly, so your tower won't crumble!

Regular programming languages can be like loose blocks. If you're not careful, you might accidentally use the wrong block or put it in the wrong spot. This can mess up your whole program, just like a wobbly tower.

Memory safe languages help prevent these mistakes by checking how you use the building blocks of your program, also known as memory. This helps create stronger, more reliable programs!

Collapse
 
chaotic3quilibrium profile image
Jim O'Flaherty

I asked it, too, to see it's answer. And it was the same answer given by a number of people replying to this thread. I even wondered why the OP didn't do this themselves.

That said, the answer demonstrates that the LLMs are just regurgitating what they have observed, and are not engaged in critical thinking about the actual problem itself.

If you will notice, I offered a response with critical thinking and did NOT use the AI/ML to compose it.

I think a huge number of people are going to get lost with the AI/ML LLM "looks like effective rational critical thinking", but it turns out that it isn't that at all.

And I suspect that the worst cases will be the marginal Software Engineers. They know just enough to inadvertently hurt themselves and others.

It strikes me as an excellent example of Hanlon's Razor:

"Do not attribute to malice that which is as easily attributed to ignorance."