Ownership and Borrowing in D Nearly all non-trivial programs allocate and manage memory. Getting it right is becoming increasingly important, as programs get ever more complex and mistakes get ever more costly. The usual problems are: The challenge is in keeping track of which pointers are responsible for freeing the memory (i.e. owning the memory), which pointers are merely referring to the memory, where they are, and which are active (in scope). The common solutions are:
Solutions 2 and 3 more or less rely on faith in the programmer to do it right. Faith-based systems do not scale well, and memory management issues have proven to be very difficult to audit (so difficult that some coding standards prohibit use of memory allocation).
But there is a fourth way – Ownership and Borrowing. It’s memory efficient, as performant as manual management, and mechanically auditable. It has been recently popularized by the Rust programming language. It has its downsides, too, in the form of a reputation for having to rethink how one composes algorithms and data structures.
The downsides are manageable, and the rest of this article is an outline of how the ownership/borrowing (OB) system works, and how we propose to fit it into D. I had originally thought this would be impossible, but after spending a lot of time thinking about it I’ve found a way to fit it in, much like we’ve fit functional programming into D (with transitive immutability and function purity).
Reminder that these languages are designed for retarded programmers and you're probably one of them if you advocate for these.
Angel Evans
Reminder that everyone who says that is a LARPer.
Isaac Flores
It's an obvious choice, really. Overpay angsty white dudes who make rookie mistakes, or hire many competitively-paid professionals from the East who use quality languages.
Logan Gomez
...
Dominic Williams
...
Ryder Evans
oh yeah, Rust isn't stillborn. I heard the babe's cry myself. It cried out "Judith Butler", "Karl Marx", "Emma Goldman". So 'stillborn' is the wrong term. You might call it a post-birth abortion. Or an act of eugenics.
The weeb is immunized against all dangers: one may call him a degenerate, pedophile, weirdo, autist, it all runs off him like water off a raincoat. But call him a weeb and you will be astonished at how he recoils, how injured he is, how he suddenly shrinks back: "I’ve been found out."
Liam Hughes
Ha ha! It's funny because it's not even a little bit true.
Dominic Ortiz
sudo apt remove chrome* *google* fonts-noto*
sudo apt remove javascript-common
sudo apt remove rust* libstd-rust* cargo*
sudo apt remove snapd* libsnapd*
Brody Nelson
...
Cameron Robinson
Halfassing at its finest.
Jack Adams
guix package -i brain Ok, but really you're right about a few things: Google is cancer, but sane distros use ungoogled chromium. Snap packages are centralized crap, SaaSS owned by Canonical and their repo (the only one you can use actually) contains nonfree software. It shouldn't be used for desktop stuff, but it is not malicious by design. I don't like the syntax or all the hype around it, but it doesn't seem malicious. It even fixes some problems C has and weenies think of as features. sudo apt purge apt Install Guix, because APT is shit.
Bentley Morgan
based
Adrian Smith
You sound jealous, goon.
Josiah Barnes
You sound degenerate, weeb.
Lincoln White
doesnt matter, replace whats in use by and large (like C++ or Python) by actually being more useful and powerful without being complicated piece of shit, thanks
Thomas Perry
Wait, you mean that shoehorning C++11's syntax into a language that forces a type driven design pattern while adding idiosyncratic changes that have no benefit and act as a footgun for people coming from a different language WASN'T a great idea?
8frens, on the reals, should I abandon Rust and learn D?
Liam Parker
D's a lot of fun. The only complaints I saw on the forum were from being trying to use brand new features (like this one) and getting jerked around a bit as the language evolved. The big downside to D from the perspective of someone looking at Rust is that D is garbage-collected and the no-GC option isn't a first-class alternative. If you start with -betterC from the beginning you can avoid GC, but this is a very different (though still very good--better than C, like it says on the tin) experience.
Mason Gomez
filter and global report all rust shill threads
Jaxson Sullivan
this. and
Who let >>>/reddit/ in?
Samuel Carter
Probably yes, they didn't invented everything themselves. The same question. D seems to be what C++ should be - it has so consistent syntax.
Logan Diaz
LARPer spotted
kys
weeb spotted
Austin Morales
LARPer spotted. Syntax is one of the most important things in ANY language if you think differently, go and use brainfuck and show us syntax doesn't matter.
Eli Moore
LARPer spotted But brainfucks syntax is fine.
Daniel Butler
Better, if you think syntax is not important at all, use plain binary code - it (AFAIK) doesn't have any syntax. Go ahead, syntax is for LARPers! So write an OS in it or a browser or a reimplementation of grep, find, etc. In languages with normal syntax it is easier task. Can you code in LISP? Its syntax is great.
Grayson Diaz
Why are you trying to normalize pedophilia? I wonder (((Who))) has entered this thread?
You are just constantly repeating same thing. Also, why are you ignoring points? You aren't an unpaid anti Rust shill, are you?
Dominic Ward
What a shame. You aren't very creative. Why don't you post something useful to prove you actually know something. Post some Rust code. But you are just an amateur shill, aren't you? Or is Rust so bad programming language that there simply aren't any programs written in it?
C++ only started doing that that after it already had decent adoption. If it didn't have adoption, nobody would bother with it.
Anthony Brooks
Are you sure? I don't think there is anything quite as complicated as C++ except maybe APL.
So if you wrote down a note to yourself about how to do something, you would actually first define a bunch of categories and explicitly define their capabilities? Or write an abstract syntax tree? Or do whateverthefuck Forth does?
Or would it be more like: Open a file, Read each line and do this But don't do it if you see this other thing Close the file. Done.
C-like syntax dominates because it's close to how we write, and that's how most of us learn to encode information (which is a broader category that programming falls into). You didn't take class notes with a bunch of method-chaining or arrows everywhere.
Which is why I get tired of all this multi-paradigm shit. Your language shouldn't do and be everything for everyone. Imperative is fine. OO is fine. FP is also fine. Doing all three just seems to lead to code bases diverging into various dialects that appear unpredictably in code bases.
Go sucks in a lot of ways, but I've never had the problem of not understanding the source of a library I use. I rarely look at C, but it's usually not that confusing. Python, however takes too much from different styles. Python could look like Java or C or Scala (or all three) depending on who wrote it. Then I look at Rust code, and I'm wading through type definitions to find the logic I actually care about only to see some macro shit that I have to look up in another crate's docs.
Just glance over this shit. HTTPS://docs.Rust-lang.org/STD/vec/struct.vec.html
There are about 100 explicit trait implementations. 66 of them are for partial equality for arrays size 0-32 borrowed and then owned (I guess you're out of luck if you have an array of length 33). In the source for this craziness is a macro with a comment that less important trait methods were left out to reduce "code bloat". Really.
Isaac Sanchez
Forth is a wordcode interperter that mostly does stack operations.
would much rather use a language that's reasonably designed, thanks.
Logan Campbell
You can't add something to an array. An array in Rust is of fixed size. The length is part of the type signature. You would have to create an array of length 33, copy the the old stuff over and then put the new element in.
Hunter Morris
this person calls people 'cnile'. YOU ADD SOMETHING TO AN ARRAY BY EDITING THE SOURCE CODE BECAUSE YOUR PROGRAM NOW NEED +1 ELEMENTS CODE IS NOT SOMETHING YOU FRAME AND PUT ON A WALL CODE GETS EDITED AND CHANGES OVER TIME
Chase Morris
...
Cameron Cox
C borrowed from Algol. It's not good because it's C, it's good because it reads like most people think, unlike Lisps, for example. Rust is also a C-like, Mr. Valedictorian from University of Mumbai. Rust just also allows you to write a hideous mish-mash of functional and imperative style with macros and Java decorators (Oops, I mean proc-macros) sprinkled everywhere. Now that's sophistication! Always tomorrow, it seems.
Do other languages require explicit implementation of how to do an elementary operation like "are these the same?" The point is, there is an outrageous amount of really basic shit Rust forces you to explicitly define the behavior of. You can't even represent a struct without applying the Derive(debug) decorator. When do you NOT want that ability? Does duck-typing really cause that many mission critical errors? Because you're spending a lot of time telling the rust compiler, "yes, rust, you can show this in an error message" or "yes, rust, you can compare these things of the same type." Sensible, opinionated defaults are really refreshing sometime.
Larry Wall, in his infinite love for NEETkind, sent his only begotten daughter Camelia to die for our sins. Take not her name in vain. Accept her into your heart and be saved from your floating point arithmetic sins.
Josiah Scott
Rust has a dynamically sized array. It is called Vec.
Yes ? When you don't want to accidentally expose stuff, like for example passwords. Yes Btw you're an actual fucking retard. Go to university or pick up a few books.
Liam Mitchell
You constantly complain about LARPing but you never post code or contribute anything of substance.
Jack Hall
Found the newfag. I posted a lot of code on Zig Forums. Also what code should I post? Does anyone on Zig Forums contribute anything of substance? You sure as hell aren't.
Hunter Ross
Are you fucking serious? If you're developing the program, then you need to hide program internals from yourself? Better blindfold myself before I open up my editor! Why is your sensitive user input getting passed around in the clear in the first place? Do you not realize your structs are private by default? This contrivance is hysterical, irrational paranoia. Rust shills are so emotionally unstable they'll throw out the most nonsensical defenses. The accusations of C++'s unsafety floating around in Rust's fluff-pieces on Medium are grossly exaggerated and ignore every post C++11 feature. Never mind the fact that most modern languages are memory safe to begin with. But, yeah, let's kill any sane default behavior because what-if-I'm-retarded?
D, why couldn't you be the language big tech decided to shill?
Some of us do have jobs.
Leo Hughes
Yes Programmers fuck up something as simple as don't free the same pointer twice. Why wouldn't they fuck up accidentally outputting secrets? You're so fucking retarded. If you derive Debug your structs aren't private anymore because you can inspect the Debug output. Which of those don't use a GC? What does that have to do with what I wrote though?
Daniel Howard
This is a Redditor meme. Most business problems are being solved with garbage collected languages. What is this board written in? If you can do HFT at Jane Street in OCaml, the GC is not your problem.
I also don't know why you think that hiding debugging info from yourself is a feature or even prevents the programming error you described, but I wish you luck in your comp sci 102 class this fall.
Gavin Rogers
Most software is also complete fucking garbage, especially whatever heap of shit Zig Forums runs on.
Luke Cooper
Who are you quoting? But that's the whole point of Rust. Also no debugging info is hidden. gdb doesnt give a shit if your type implements Debug or not. I never had this class. I didn't go to a burger university.
Evan Diaz
With a nuanced opinion like that, you must be really smart. I bet you get paid a lot for your quality software.
University of Mumbai student detected
Carter James
More like one of the top German universities. Protip: Everything does suck. Most software is a badly designed patchwork of braindamage. Just take a look at this: danluu.com/deconstruct-files/
Nicholas Wood
People much smarter than both of us combined are saying that most modern software is complete shit.
that text makes everything storage related look really bad
Hunter Mitchell
Are you that idiot who made a thread to suck your own dick over some toy event loop you wrote in C++ as part of your "environmentally friendly" blockchain vaporware bullshit? How about you confine your bullshit to your ivory tower where you continue to solve no useful problems whatsoever.