Hacker News new | ask | show | jobs
by jenadine 649 days ago
Code is docs. One can just infer lifetime by reading the code.

(That said, having it encoded in the type system makes it many times easier)

7 comments

Asahi Lina posted a thread about how difficult this actually is in practice:

https://threadreaderapp.com/thread/1829852697107055047.html

> One can just infer lifetime by reading the code.

For trivial cases sure, for complex ones though this is akin to saying "you can know if there's any bugs by reading the code" which we all know is not true for any reasonable time investment put into reading the code.

>One can just infer lifetime by reading the code.

Enormously load-bearing "just" there. And if there's a subtle lifetime bug ... ?

Pretty sure I can get close to mapping that to solving the halting problem
Have you actually looked at Linux device model code? Or filesystem code? Or most other code? Most is poorly documented. Most is overcomplicated. Quite a bit is flat-out wrong.
One can just write correct code, of course.
Sure you can, particularly in simple cases. However some code needs years to understand because something seemingly unrelated happening elsewhere changes things. The kernel often has to run on several different CPUs at the same time, and shouldn't sync the CPU caches if it is possible to avoid it.