this post was submitted on 05 Oct 2024
60 points (100.0% liked)

Programming

426 readers
15 users here now

Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!

Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.

Hope you enjoy the instance!

Rules

Rules

  • Follow the programming.dev instance rules
  • Keep content related to programming in some way
  • If you're posting long videos try to add in some form of tldr for those who don't want to watch videos

Wormhole

Follow the wormhole through a path of communities !webdev@programming.dev



founded 2 years ago
MODERATORS
top 50 comments
sorted by: hot top controversial new old
[–] zcd@lemmy.ca 44 points 4 months ago
[–] mox@lemmy.sdf.org 37 points 4 months ago (3 children)

With no context, this could be an honest attempt to learn about different tools, a thinly veiled set-up to promote a specific language, or an attempt to stir up drama. I can't tell which.

It's curious how such specific conditions are embedded into the question with no explanation of why, yet "memory safe" is included among them without specifying what kind of memory safety.

[–] Ephera@lemmy.ml 9 points 4 months ago (3 children)

Yeah, arguably the only answer to this question is Rust.

Java/C#/etc. are not fully compiled (you do have a compilation step, but then also an interpretation step). And while Java/C#/etc. are memory-safe in a single-threaded context, they're not in a multi-threaded context.

[–] starman@programming.dev 7 points 4 months ago* (last edited 4 months ago) (1 children)
[–] Ephera@lemmy.ml 4 points 4 months ago

I mean, yeah, valid point. JVM languages also have GraalVM for that purpose.

But I'm playing devil's advocate here. πŸ™ƒ

Arguably these don't count, because they're not the normal way of using these languages. Reflection isn't properly supported in them, for example, so you may not be able to use certain libraries that you'd normally use.

These also still require a minimal runtime that's baked into the binary, to handle garbage collection and such.
Personally, I enjoy fully compiled languages, because they generally don't lock you into an ecosystem, i.e. you can use them to create a library which can be called from virtually any programming language, via the C ABI.
You cannot do that with a language that requires a (baked-in) runtime to run.

But yeah, obviously someone just specifying "compiled" probably won't have all these expectations...

[–] Saizaku@lemmy.dbzer0.com 4 points 4 months ago (3 children)

Arguably modern c++ ( aka if you don't use raw pointers), fits all categories.

load more comments (3 replies)
[–] nous@programming.dev 4 points 4 months ago (1 children)

How are they not memory safe in a multi-threadded context?

[–] unique_hemp@discuss.tchncs.de 4 points 4 months ago (1 children)

There's nothing to prevent data races. I myself have fallen into the trap of using the same list from multiple threads.

[–] nous@programming.dev 10 points 4 months ago (1 children)

I don't think data races are generally considered a memory safety issue. And a lot of languages do not do much to prevent them but are still widely considered memory safe.

[–] Ephera@lemmy.ml 4 points 4 months ago (1 children)

Yeah, that is why I prefixed that whole comment with "arguably".

I feel like the definition of memory safety is currently evolving, because I do think data races should be considered a memory safety issue.
You've got a portion of memory and access to it can be done wrongly, if the programmer isn't careful. That's what memory safety is supposed to prevent.

Rust prevents that by blocking you from passing a pointer for the same section of memory into different threads, unless you use a mutex or similar.
And because Rust sets a new safety standard, I feel like we'll not refer to Java and such as "memory-safe" in twenty years, much like you wouldn't call a car from the 90s particularly safe, even though it was at the time.

[–] Saizaku@lemmy.dbzer0.com 5 points 4 months ago (2 children)

There's a reason why data races aren't considered a memory safety issue, because we have a concept that deals with concurrency issues - thread safety.

Also for all it's faults, thread and memory safety in java aren't issues. In fact java's concurrent data structures are unmatched in any other programming language. You can use the regular data structures in java and run into issues with concurrency but you can also use unsafe in rust so it's a bit of a moot point.

[–] Ephera@lemmy.ml 4 points 4 months ago

Oof, I guess, you're not wrong that we've defined data races to be the separate issue of thread safety, but I am really not a fan of that separation.

IMHO you cannot cleanly solve thread safety without also extending that solution to the memory safety side.
Having only one accessor for a portion of memory should just be the n=1 case of having n accessors. It should not be the other way around, i.e. that multiple accessors are the special case. That just leads you to building two different solutions, and to thread safety being opt-in.

That's also the major issue I have with Java's solution.
If you know what you're doing, then it's no problem. But if you've got a junior hacking away, or you're not paying enough attention, or you just don't realize that a function call will take your parameter across thread boundaries, then you're fucked.
Well, unless you make everything immutable and always clone it, which is what we generally end up doing.

load more comments (1 replies)
[–] Buttons@programming.dev 4 points 4 months ago

The question mine as well be "what is your favorite compiled language?". There is a lot of overlap between the possible answers.

[–] AbelianGrape 4 points 4 months ago

Yeah, I like subleq.

  • compiler is extremely fast, faster even than tinycc
  • strongly statically typed: all values are ints. Since it's all of them, you don't even need to write it!
  • memory safe: the entire (virtual) address space is guaranteed to be accessible at all times so there's no way to leak any of it (can't release it anyway) or to segfault (it's all accessible).

Subleq is the obvious winner in my mind.

[–] FizzyOrange@programming.dev 32 points 4 months ago (1 children)

Rust for now, by a wide margin. But I'm following other languages that I think have the potential to surpass it, including Vale (promises way more than it delivers currently), Koka, Hylo, maybe Lobster.

[–] tooLikeTheNope@lemmy.ml 6 points 4 months ago* (last edited 4 months ago) (4 children)
load more comments (4 replies)
[–] Dhs92@programming.dev 28 points 4 months ago
[–] germanatlas@lemmy.blahaj.zone 25 points 4 months ago (1 children)

That is a very specific subset

[–] sus@programming.dev 26 points 4 months ago (1 children)

Garbage collection is still allowed, and technically JIT languages are still compiled so it really isn't that restrictive

load more comments (1 replies)
[–] demesisx@infosec.pub 24 points 4 months ago* (last edited 4 months ago) (1 children)

As others have said, Haskell and Rust are pretty great. A language that hasn’t been mentioned that I REALLY want to catch on, though, is Unison.

Honorable mention to my main driver lately: Purescript

[–] cyclohexane@lemmy.ml 3 points 4 months ago (1 children)
[–] demesisx@infosec.pub 13 points 4 months ago* (last edited 4 months ago)

Hard to describe in one phrase other than to say:

NixOS is to Linux as Unison is to Haskell

Content-addressing used in the context of programming languages in the service of solving the problem of distributed systems and their inability to share code across time and space.

Haskell has a content-addressed module that was perhaps influenced by Unison.

Here’s an excellent interview with one of the authors of Unison:

https://youtu.be/zHzpoVgqgc4

[–] lambdabeta@lemmy.ca 20 points 4 months ago (1 children)

Ada, hands down. Every time I go to learn Rust I'm disappointed by the lack of safety. I get that it's miles ahead of C++, but that's not much. I get that it strikes a much better balance than Ada (it's not too hard to get it to compile) but it still leaves a lot to be desired in terms of safe interfacing. Plus it's memory model is more complicated than it needs to be (though Ada's secondary stack takes some getting used to).

I wonder if any other Ada devs have experience with rust and can make a better comparison?

[–] collapse_already@lemmy.ml 5 points 4 months ago

I have done quite a bit of C, C++, Ada, and Pascal development. I recently got into Rust. I am still getting used to Rust, but it feels a bit like someone tried to apply Ada to C++. I like the modern development environment, but I am slower writing code than I would be in Ada or C++. The one feature of Ada that I really like and want other languages to adopt is the Rep spec. I write driver code and being able to easily and explicitly identify which symbol corresponds to which bit is really good.

[–] apoisel@discuss.tchncs.de 18 points 4 months ago (1 children)
[–] cyclohexane@lemmy.ml 8 points 4 months ago (9 children)

Sad I had to scroll to the end to see this.

Ocaml is brilliant and has the nicest type features. It's almost like Haskell but more approachable imo.

load more comments (9 replies)
[–] Andromxda@lemmy.dbzer0.com 13 points 4 months ago

Hands down, Rust πŸ¦€

[–] ICastFist@programming.dev 12 points 4 months ago

Nim. Small compiler, small executables, easy to understand (except the macros, I still can't get my head around them).

FreePascal. Yeah yeah, Pascal's dead, etc etc, but it being so verbose and strict certainly help programmers (or at least me) keeping things somewhat tidy.

Also shoutout to V

[–] AsudoxDev@programming.dev 11 points 4 months ago
[–] KindaABigDyl@programming.dev 10 points 4 months ago

Rust and Haskell (I think Haskell counts)

[–] xigoi@lemmy.sdf.org 10 points 4 months ago
[–] 1rre@discuss.tchncs.de 9 points 4 months ago* (last edited 4 months ago) (3 children)

C is memory safe if you program it well enough, so I guess C

[–] sus@programming.dev 24 points 4 months ago* (last edited 4 months ago)

every single language (except Vlang of course) is memory safe if you program it perfectly.

Very, very few humans are capable of doing that, especially with C.

[–] SatouKazuma@programming.dev 17 points 4 months ago

C? Memory safe? HAHAHAHA

[–] MajorHavoc@programming.dev 4 points 4 months ago* (last edited 4 months ago) (1 children)

Lol. The people downvoting your comment need to get good.

[–] Tja@programming.dev 4 points 4 months ago

Skill issue.

[–] BorgDrone@lemmy.one 9 points 4 months ago
[–] UFODivebomb@programming.dev 7 points 4 months ago

Scala 3 native. If the compiler was faster I'd be even happier. Curious to try Ada

[–] cinnamon_tea@programming.dev 6 points 4 months ago* (last edited 4 months ago)

You forgot that beauty - "undefined behavior"!

Memory-safety can guarantee only so much safety! C++ can still blow up in your face, even with all the alleged memory-safety built into C++, thanks to all the UB traps in C and C++.

Rust is the closest language that has no such "gotchas".

[–] undefined@links.hackliberty.org 6 points 4 months ago* (last edited 4 months ago) (2 children)

Crystal, but only because I’m a full time Ruby on Rails (and sometimes Hanami!) programmer.

It’s fantastic, and I had an excuse to use it at work when we needed to gather PHP Watchdog logs from a MySQL database and format, output them to STDOUT in a Kubernetes environment. (This was necessary for our log monitoring tools expecting data in a standard way, AKA not connecting to a database. πŸ€¦β€β™‚οΈ)

I know there are perhaps better options out there (Go, Rust, etc.) but from a Rubyist’s point of view Crystal gives you that β€œflow” from working in a beautiful language but with the performance boost of compiled software.

load more comments (2 replies)
[–] 30p87@feddit.org 6 points 4 months ago (2 children)

C++, with some Skill

/s

but seriously, I don't know any language with a good, C/Cpp-like Syntax (so not Rust), with a good compiler (again not Rust). So I'm sticking to Cpp.

[–] uthredii@programming.dev 6 points 4 months ago

You should check out zig, its compiler can even be used for c/c++. If you have time to listen to an interview, this developer voices interview on zig explains some of the advantages of this: https://www.youtube.com/watch?v=5_oqWE9otaE&t=3970s

[–] Hundun 3 points 4 months ago

What's so bad about the Rust compiler? I know it's slow, but given all the analysis it's doing, it makes sense. And, from my own experience, setting correct optimization levels for dependencies along with a good linker makes incremental builds plenty fast.

[–] MajorHavoc@programming.dev 5 points 4 months ago* (last edited 4 months ago) (1 children)

Python with MyPy.

(Almost any language can meet those criteria, with enough shenanigans.)

[–] arthur@lemmy.zip 5 points 4 months ago (1 children)

But that's not compiled, not to binary at least.

[–] MajorHavoc@programming.dev 8 points 4 months ago

But that's not compiled, not to binary at least.

Well...sort of.

(Everything is weirder than it seems at first glance.)

[–] yogsototh@programming.dev 4 points 4 months ago* (last edited 4 months ago) (3 children)

purescript if you count β€œcompile to js” as compiled.

Otherwise Haskell

load more comments (3 replies)
[–] DavidDoesLemmy@lemmynsfw.com 4 points 4 months ago

Kotlin is nice

load more comments
view more: next β€Ί