Remix.run Logo
KnuthIsGod 10 hours ago

Sigh.

Ownership and borrowing are so much less baroque in D than in Rust. And compile times are superb.

In a better world, we would all be using D instead of C, C++ or Rust.

However in this age of Kali...

chhs 9 hours ago | parent | next [-]

For those curious what ownership and borrowing looks like in D: https://dlang.org/blog/2019/07/15/ownership-and-borrowing-in...

fooker 8 hours ago | parent | next [-]

This is a somewhat simplistic view of ownership and borrowing for modern programming languages.

Pointers are not the only 'pointer's to resources. You can have handles specific to your codebase or system, you can have indices to objects in some flat array that the rest of your codebase uses, even temporary file names.

An object oriented (or 'multi paradigm') language has to account for these and not just literal pointers.

This is handled reasonably well both in Rust and C++. (In the spirit of avoiding yet another C++ vs Rust flamewar here, yes the semantics are different, no it doesn not make sense for C++ to adopt Rust semantics)

tgv 5 hours ago | parent [-]

How does Rust (or C++) treat array indices as resources? And won't that defy the reason to use indices over pointers?

randfur 9 hours ago | parent | prev | next [-]

I don't know D so I'm probably missing some basic syntax. If pointers cannot be copied how do you have multiple objects referencing the same shared object?

andsoitis 8 hours ago | parent [-]

> If pointers cannot be copied

They can.

uecker 9 hours ago | parent | prev [-]

Is there any experience on how this works in practice?

torginus 8 hours ago | parent | prev | next [-]

OOP and ownership are two concepts that mix poorly - ownership in the presence of OOP-like constructs is never simple.

The reason for that is OOP tends to favor constructs where each objects holds references to other objects, creating whole graphs, its not uncommon that from a single object, hundreds of others can be traversed.

Even something so simple as calling a member function from a member function becomes incredibly difficult to handle.

Tbh - this is with good reason, one of the biggest flaws of OOP is that if x.foo() calls x.bar() in the middle, x.bar() can clobber a lot of local state, and result in code that's very difficult to reason about, both for the compiler and the programmer.

And it's a simple case, OOP offers tons of tools to make the programmers job even more difficult - virtual methods, object chains with callbacks, etc. It's just not a clean programming style.

Edit: Just to make it clear, I am not pointing out these problems, to sell you or even imply that I have the solution. I'm not saying programming style X is better.

FeepingCreature 8 hours ago | parent | next [-]

I work at a D company. We tend to use OOP only for state owners with strict dependencies, so it's rare to even get cycles. It is extremely useful for modeling application state. However, all the domain data is described by immutable values and objects are accessed via parameters as much as fields.

When commandline apps were everywhere, people dreamed of graphical interfaces. Burdened by having to also do jobs that it was bad at, the commandline got a bad reputation. It took the dominance of the desktop for commandline apps to find their niche.

In a similar way, OOP is cursed by its popularity. It has to become part of a mixed diet so that people can put it where it has advantages, and it does have advantages.

pjmlp 7 hours ago | parent | prev | next [-]

It worked alright for Rust, and yes Rust does support OOP, there are many meanings to what is OOP from CS point of view.

I have ported Ray Tracing in One Weekend into Rust, while keeping the same OOP design from the tutorial, and affine types were not an impediment to interfaces, polymorphism and dynamic dispatch.

abbbyz 7 hours ago | parent | prev | next [-]

>one of the biggest flaws of OOP is that if x.foo() calls x.bar() in the middle, x.bar() can clobber a lot of local state, and result in code that's very difficult to reason about

That's more a problem of having mutable references, you'd have the same problem in a procedural language.

arcadia_leak 8 hours ago | parent | prev [-]

On the flipside, with OOP is usually quite easy to put a debugger breakpoint on a particular line and see the full picture of what the program is doing.

In diehard FP (e.g. Haskell) it's hard to even place a breakpoint, let alone see the complete state. In many cases, where implementing a piece of logic without carrying a lot of state is impossible, functional programming can also become very confusing. This is especially true when introducing certain theoretical concepts that facilitate working with IO and state, such as Monad Transformers.

torginus 7 hours ago | parent [-]

That is true, but on the flip-flip side, while procedural or FP programs are usually easy to run piecewise, with OOP, you have to run the entire app, and navigate to the statement in question to be even able to debug it.

Imho, most FP languages have very serious human-interface issues.

It's no accident that C likes statements (and not too complex ones at that). You can read and parse a statement atomically, which makes the code much easier to read.

In contrast, FP tends to be very, very dense, or even worse, have a density that's super inconsistent.

pjmlp 9 hours ago | parent | prev | next [-]

Slowly it is going to be only skills.md.

I agree with the sentiment, I really like D and find a missing opportunity that it wasn't taken off regarding adoption.

Most of what made D special in D is nowadays partially available in mainstream languages, making the adoption speech even harder, and lack of LLM training data doesn't help either.

bigstrat2003 9 hours ago | parent | next [-]

> lack of LLM training data doesn't help either.

That shouldn't stop any self-respecting programmer.

pjmlp 9 hours ago | parent | next [-]

Self respecting developers are an endangered species, otherwise we would not have so much Electron crap.

Those that learn to do robot maintenance, are the ones left at the factory.

feastingonslop 9 hours ago | parent | prev | next [-]

Nor does it stop self-respecting LLMs.

gigatexal 9 hours ago | parent | prev | next [-]

Exactly. We wrote code before LLMs and we can after their advent too

pjmlp 9 hours ago | parent [-]

Yeah, that is why carpenters are still around and no one buys Ikea.

tjr 8 hours ago | parent | next [-]

Is your proposition that programmers are now incapable of writing code?

pjmlp 8 hours ago | parent [-]

Eventually yes, when incapable becomes a synonymous with finding a job in an AI dominated software factory industry.

Enterprise CMS deployment projects have already dropped amount of assets teams, translators, integration teams, backend devs, replaced by a mix of AI, SaaS and iPaaS tools.

Now the teams are a fraction of the size they used to be like five years ago.

Fear not, there will be always a place for the few ones that can invert a tree, calculate how many golf balls fit into a plane, and are elected to work at the AI dungeons as the new druids.

tmtvl 7 hours ago | parent | next [-]

While I don't share this cynical worldview, I am mildly amused by the concept of a future where, Warhammer 40,000 style, us code monkeys get replaced by tech priests who appease the machine gods by burning incense and invoking hymns.

anonzzzies 8 hours ago | parent | prev [-]

Same for ERP/CRM/HRM and some financial systems ; all systems that were heavy 'no-code' (or a lot of configuration with knobs and switches rather than code) before AI are now just going to lose their programmers (and the other roles); the business logic / financial calcs etc were already done by other people upfront in excel, visio etc ; now you can just throw that into Claude Code. These systems have decades of rigid code practices so there is not a lot of architecting/design to be done in the first place.

gspr 8 hours ago | parent | prev | next [-]

> Yeah, that is why carpenters are still around and no one buys Ikea.

I'm sorry, what? Are you suggesting that Ikea made carpenters obsolete? It's been less than 6 months since last I had a professional carpenter do work in my house. He seemed very real. And charged very real prices. This despite the fact that I've got lots of Ikea stuff.

cinntaile 8 hours ago | parent [-]

Compared to before, not a lot of carpenters/furniture makers are left. This is due to automation.

1718627440 4 hours ago | parent | next [-]

Nah, IKEA has replaced moving furniture with throwing it away and rebuying it. Prior to IKEA hiring a carpenter was also something that is done a few times in a lifetime/century. If anything it has commodized creating new furniture.

gspr 6 hours ago | parent | prev [-]

> Compared to before, not a lot of carpenters/furniture makers are left.

Which is it? Carpenters or furniture makers? Because the two have nothing in common beyond the fact that both professions primarily work with wood. The former has been unaffected by automation – or even might plausibly have more demand due to the overall economic activity caused by automation! The latter certainly has been greatly affected.

The fact that people all over the thread are mixing up the two is mindboggling. Is there a language issue or something?

tmtvl 4 hours ago | parent | next [-]

There is a language issue: carpenter is used as synonym of woodworker. It's like someone who doesn't know anything about computers using the term 'memory' to mean storage rather than working memory (i.e. RAM).

cinntaile an hour ago | parent | prev [-]

From the context it was pretty obvious what the original poster meant, as long as you charitably interpret their message. As per the site guidelines.

stephenr 8 hours ago | parent | prev [-]

> that is why carpenters are still around and no one buys Ikea

The irony in this statement is hilarious, and perfectly sums up the reality of the situation IMO.

For anyone who doesn't understand the irony: a carpenter is someone who makes things like houses, out of wood. They absolutely still fucking exist.

Industrialised furniture such as IKEA sells has reduced the reliance on a workforce of cabinet makers - people who make furniture using joinery.

Now if you want to go ask a carpenter to make you a table he can probably make one, but it's going to look like construction lumber nailed together. Which is also quite a coincidence when you consider the results of asking spicy autocomplete to do anything more complex than auto-complete a half-written line of code.

cake-rusk 7 hours ago | parent | next [-]

I think you have misunderstood what a carpenter is. A carpenter is someone who makes wooden furniture (among other things).

gspr 5 hours ago | parent [-]

> I think you have misunderstood what a carpenter is. A carpenter is someone who makes wooden furniture (among other things).

I think _you_ have misunderstood what a carpenter is. At least where I live, you might get a carpenter to erect the wood framing for a house. Or build a wooden staircase. Or erect a drywall. I'm sure most carpenters worth their salt could plausibly also make wooden furniture, at an exorbitant cost, but it's not at all what they do.

I sanity checked with Wiktionary, and it agrees: "A person skilled at carpentry, the trade of cutting and joining timber in order to construct buildings or other structures."

cake-rusk 20 minutes ago | parent [-]

https://dictionary.cambridge.org/dictionary/english/carpente...

a person whose job is making and repairing wooden objects and structures

fuzztester 6 hours ago | parent | prev [-]

https://en.wikipedia.org/wiki/Carpentry

Carpenters make many things besides houses.

See the section "Types of carpentry".

usrnm 9 hours ago | parent | prev [-]

Self-respecting programmers write assembly for the machines they built themselves. I swear, kids these days have no respect for the craft

gmueckl 8 hours ago | parent | prev | next [-]

My experience is that all LLMs that I have tested so far did a very good job producing D code.

I actually think that the average D code produced has been superior to the code produced for the C++ problems I tested. This may be an outlier (the problems are quite different), but the quality issues I saw on the C++ side came partially from the ease in which the language enables incompatible use of different features to achieve similar goals (e.g. smart_ptr s new/delete).

baruch 8 hours ago | parent | prev [-]

I work with D and LLMs do very well with it. I don't know if it could be better but it does D well enough. The problem is only working on a complex system that cannot all be held in context at once.

pjmlp 8 hours ago | parent [-]

I based my opinion on this recent thread, https://forum.dlang.org/thread/bvteanmgrxnjiknrkeyg@forum.dl...

Which the discussion seems to imply it kind of works, but not without a few pain points.

fuzztester 6 hours ago | parent | prev [-]

Kali Yuga.

https://en.wikipedia.org/wiki/Kali_Yuga