Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> /// BAD: This mutates `input`, which may be unexpected by the caller.

> [...]

> /// GOOD: `input` is preserved and a new object is created for the output.

Neither of these are good or bad without knowing their context and understanding their tradeoffs. In particular, sometimes you want to mutate an existing object instead of duplicating it, especially if it's a big object that takes awhile to duplicate.



If you don't mutate, you don't need to duplicate.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: