this post was submitted on 14 Oct 2023
1206 points (98.6% liked)

Programmer Humor

37208 readers
916 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

founded 5 years ago
MODERATORS
 

Programmers can answer all existential questions with ease

all 50 comments
sorted by: hot top controversial new old
[–] raubarno@lemmy.ml 30 points 2 years ago (2 children)

If you fork a process, then it's the two separate processes but sharing the same memory with copy-on-write mapping.

[–] mofongo@lemm.ee 12 points 2 years ago (1 children)

Is that actually more efficient if I need my child process to do something different with different data?

[–] raubarno@lemmy.ml 7 points 2 years ago (2 children)

It's more efficient for memory until you start working with different data. Threads also rely on the same syscall on Linux, clone(2), but they don't share the entire context by default, so they're more lightweight. It is recommended to use pthreads(3) API instead of fork(2).

[–] dan@upvote.au 3 points 2 years ago* (last edited 2 years ago)

Also, if you care about Windows, threads are far lighter than processes on that platform. Starting a new process is relatively slow compared to other platforms.

[–] mofongo@lemm.ee 2 points 2 years ago

Ah thx for the info

[–] jaybone@lemmy.world 29 points 2 years ago* (last edited 2 years ago) (1 children)

If you just clone a reference to them, then you are just pointing another finger at them.

Is this really an analogy that resonates with programmers today?

[–] peter@feddit.uk 5 points 2 years ago (1 children)

If you clone a reference to someone you have a completey separate body but any actions taken affect the original as well

[–] Darken@reddthat.com 7 points 2 years ago (1 children)

I believe it is just a wormhole pointing to the original so even if it may look like another body it's just the original being manipulated through the warped spacetime continuum

[–] 30isthenew29@lemmy.world 1 points 2 years ago (1 children)

Why would the clone be connected…?

[–] wallace@suppo.fi 2 points 2 years ago

Because it's only a reference to the original.

[–] Matriks404@lemmy.world 23 points 2 years ago* (last edited 2 years ago) (3 children)

They are, on the exact moment they are cloned. On the next attosecond they are not.

Edit: Well, if they are cloned on the cellular level, otherwise it's just NO.

[–] LufyCZ@lemmy.world 6 points 2 years ago (2 children)

What if they're placed into two completely identical environments?

[–] Sotuanduso@lemm.ee 9 points 2 years ago (2 children)

Quantum multiverse theory says that happens all the time.

[–] WhiskyTangoFoxtrot@lemmy.world 1 points 2 years ago

Is there a universe where that doesn't happen all the time?

[–] hansl@lemmy.world 1 points 2 years ago

What if it happened already?

[–] lugal@lemmy.ml 2 points 2 years ago (1 children)

You have no idea what cloning is, right? You're too young to remember Dolly

[–] comador@lemmy.world 1 points 2 years ago
[–] A7thStone@lemmy.world 2 points 2 years ago

Why cellular level?

[–] candyman337@sh.itjust.works 21 points 2 years ago* (last edited 2 years ago) (1 children)

The real answer btw is no, cloned animals aren't identical to their original, same base traits, but for example in cows spot position will be different

Also unless you can copy their memories, they just won't be the same person.

And then they'd have two different life experiences and would immediately begin to differ.

[–] andrew_bidlaw@sh.itjust.works 5 points 2 years ago (1 children)

And we also change every milisecond. How long this process takes? It may seem irrelevant but copy of you 5 seconds ago is not you now. It's your restored back up.

[–] theneverfox@pawb.social 4 points 2 years ago (1 children)

Unless your pause execution of the original or there's an ongoing synchronization during the cloning process

[–] andrew_bidlaw@sh.itjust.works 1 points 2 years ago (1 children)

Sync would lag anyway, I think, if we are pedantic.

Pausing the execution of the original via execution solves the problem of who's original here tho. One's still functioning.

[–] theneverfox@pawb.social 3 points 2 years ago

Well it depends on the method of sync... Doing it through updates would lag, but what if it was through something like quantum effects, or even by treating both bodies and brains like a contiguous organism until the cloning is complete? Like with a cell dividing, there's no original

[–] swab148@startrek.website 12 points 2 years ago (3 children)

Okay, now do the Trolley Problem.

[–] hinterlufer@lemmy.world 7 points 2 years ago

easy:

    break
[–] comrade_pibb@hexbear.net 4 points 2 years ago

throw IllegalStateException()

[–] nao@sh.itjust.works 12 points 2 years ago* (last edited 2 years ago) (3 children)

If you copy by reference there’s still only one person.

What is clone by reference?

[–] HeapOfDogs@lemmy.world 3 points 2 years ago (1 children)
[–] 30isthenew29@lemmy.world 3 points 2 years ago* (last edited 2 years ago)

We are all one.

[–] MrNemobody@lemmy.world 1 points 2 years ago

You in the mirror.

[–] cupcakezealot@lemmy.blahaj.zone 1 points 2 years ago

Technically the Borg

[–] kibiz0r@lemmy.world 11 points 2 years ago

https://www.mentalfloss.com/article/76908/trouble-star-trek-transporters

If the transporter takes all the atoms that make up a person, encodes them, beams them somewhere else, and then reassembles them, how can we know that the resulting "person" is the same person who went in?

[–] cupcakezealot@lemmy.blahaj.zone 10 points 2 years ago

Depends if you add the ethicator or not

[–] backhdlp@lemmy.blahaj.zone 8 points 2 years ago

Is it a copy or a hardlink?

Did you remember to override .Equals and .GetHashCode?

[–] ItsMeForRealNow@lemmy.world 5 points 2 years ago

If you clone them, you'll lose their functions.

[–] Mio@feddit.nu 5 points 2 years ago

Make a deep clone

[–] 30isthenew29@lemmy.world 4 points 2 years ago

It’s not, it’s a copy, but if you think all consciousness is the same, then maybe.

[–] theneverfox@pawb.social 4 points 2 years ago

Huh. Now my confusion about the chicken and the egg debate makes a lot more sense, it seems odd to me that such an easily answered question ended with so much confusion

I'm now realizing it's only a debate with non programmers, I thought it was a mutual ADHD communication thing, now I'm realizing maybe it's just because they learned about inheritance

[–] JayDee@lemmy.ml 1 points 2 years ago (1 children)

Imagine if you saw someone who looked exactly like you and mimicked your exact actions, but they were just 3 or 4 feet to the left of you. That's by reference (I think)

Contrasting an exact copy of you that can think for itself and has autonomy, which is by value (I think)

[–] derfl007@lemmy.wtf 3 points 2 years ago

By value could be described as, the exact same as you at the time of cloning, but it will be its own object and in no way connected to your actions.

Whereas by reference would be exactly what you described