Elektrine lite

← Feed

@funkless_eck@sh.itjust.works

Post #3220061

2026-06-09 09:47 UTC

the list is the helpful part to understanding it. it would be terrible if, with bar being a list and foo being a member of the list if foo in bar: return true modified the list. So yeah, you want to look at the list not edit the list, it’s a pointer.

Replies (3)

  • @lime@feddit.nu 2026-06-09 09:53

    other way round surely? if you want to modify the original object, use a pointer. if you don’t, use a copy.

    Open ##3220306

  • @gerryflap@feddit.nl 2026-06-09 12:00

    Your example doesn’t make sense to me. Why would you modify the entire list by checking if something is in it? Also, you can totally edit the list via a pointer, that’s how you’re supposed to edit the list if you want any performance. Otherwise you’d be copying the list on every modification, which is terribly inefficient

    Open ##3222873

  • @Sylvartas@lemmy.dbzer0.com 2026-06-09 13:06

    A pointer to the list would allow you to modify whatever’s at that pointer’s address though. If you want to look at the list and not edit it you pass by const reference 99% of the time, and if your language doesn’t have that I don’t like it.

    Open ##3224318