news.volyx.in

John Carmack on mutable variables (twitter.com)

515 points by azhenley · 267 days ago · 627 comments on HN

Article summary

John Carmack discusses the importance of avoiding mutable variables and using single assignment in programming, citing benefits such as easier debugging and fewer errors. He notes that making almost every variable const at initialization is good practice and wishes it was the default in languages. Carmack's comments sparked a discussion on the benefits and drawbacks of mutable variables, with some agreeing that immutability by default is a good practice. The conversation also touched on the trade-offs between different programming paradigms and languages.

Main themes

  • Mutable variables
  • Immutability by default
  • Programming best practices
  • Language design
  • Functional programming
  • Object-oriented programming

What commenters say

  • Using immutable variables by default can make code easier to reason about and debug, but may require more boilerplate code in some cases.
  • Some programmers prefer the flexibility of mutable variables, while others see them as a source of errors and bugs.
  • Functional programming languages, which often emphasize immutability, can be less familiar and more difficult to learn for some developers.
  • The choice of programming language and paradigm depends on the specific needs and goals of the project, and no single approach is universally best.
  • Adding new language features, such as syntactic sugar, can be beneficial but also risks making the language more complex and harder to learn.
  • Immutability by default can help prevent certain types of errors, such as use-after-free bugs, but may not be suitable for all use cases or performance-critical code.
  • The trade-offs between different programming paradigms, such as functional and object-oriented programming, are complex and depend on the specific context and goals of the project.
  • Some developers prefer languages with a more minimalist design, while others value the expressiveness and flexibility of more feature-rich languages.