News for hackers. Stuff that matters.
Re:John Carmack on Mutable Variables by y0ned4 on Friday October 31, 2025 @05:22AM (#45769960)
When I started programming in Haskell, where all variables are immutable, I felt like I was in a straitjacket

Then, suddenly, the enlightenment

Re:John Carmack on Mutable Variables by criddell on Friday October 31, 2025 @07:58AM (#45771052)
How does Haskell deal with things like memory-mapped I/O or signal handlers where the value of a variable can be changed by factors outside of the programmer's control?
Re:John Carmack on Mutable Variables by how_gauche on Friday October 31, 2025 @08:58AM (#45771504)
Side effecting computations that depend on the "real world" go into an IO monad. The game in Haskell is shifting as much of the codebase as possible into pure functions/non-side-effecting code, because it's easier to reason about and prove correct.
Re:John Carmack on Mutable Variables by chuckadams on Friday October 31, 2025 @09:41AM (#45771883)
IORefs usually, which can only be manipulated within the IO monad, so they tend to only get used at the top level and passed down to pure functions as parameters.
Re:John Carmack on Mutable Variables by blub on Friday October 31, 2025 @07:37AM (#45770896)
How do you know it’s real? When one is in a straitjacket for a long time, the trauma might make the mind disassociate from the body, giving an illusion of freedom.

The brain is essentially dreaming it’s escaped while the body is still programming in Java.

Re:John Carmack on Mutable Variables by archerx on Friday October 31, 2025 @08:04AM (#45771090)
That made me laugh, thank you.
Re:John Carmack on Mutable Variables by kypro on Friday October 31, 2025 @06:23AM (#45770377)
I've had this experience with going from PHP and JS to typed languages. Many years ago I was a type sceptic, but after being forced to use them, I now can't stand not having strict typing.

I'm sure others have written about this, but these days I think good code is code which has a very small area of variability. E.g code which returns a value in a single place as a single type, has a very limited number of params (also of single type), and has no mutable variables. If you can break code into chunks of highly predictable logic like this it's so so much easier to reason about your code and prevent bugs.

Whenever I see methods with 5+ params and several return statements I can almost guarantee there will be subtle bugs.

Re:John Carmack on Mutable Variables by kalaksi on Friday October 31, 2025 @07:43AM (#45770944)
I initially started programming with C++, then did a bunch of scripting languages and then Rust and C#. I feel like there are pros and cons to strictness.

I don't like all scripting languages, but Python, for example, has a simple syntax and is easy and fast to learn and write. I think it also has a good standard library. Some things can be simpler because of the missing guardrails. But that's also the weakness and I wouldn't use it for large and complex software. You have to be more mindful to keep a good style because of the freedoms.

C++ and Rust are at the opposite end. Verbose to write and more difficult syntax. More stuff to learn. But in the end, that's the cost for better guarantees on correctness. But again, they don't fit all use cases as well as scripting languages.

I've experienced the good and the bad in both kind of languages. There are tradeoffs (what a surprise) and it's probably also subjective what kind of language one prefers. I think my _current_ favorites are Rust, C# and Python.

Re:John Carmack on Mutable Variables by maleldil on Friday October 31, 2025 @11:42AM (#45773328)
> Whenever I see methods with 5+ params

I don't see why that's a problem. If a function implements an algorithm with several parameters (e.g. a formula with multiple variables), those values have to be passed somehow. Does it make a difference if they're in a configuration object or as distinct parameters?

Re:John Carmack on Mutable Variables by runevault on Friday October 31, 2025 @02:10PM (#45774936)
Personally I'd tweak your last sentence to "return statements in the middle of a function."

Early returns at the very top for things like None if you pass in an Option type don't increase the risk of bugs, but if you have a return nested somewhere in the middle it makes it easier to either write bugs up front or especially have bugs created during a refactor. I certainly have had cases where returns in the middle of a beefy function caused me headaches when trying to add functionality.

Re:John Carmack on Mutable Variables by chuckadams on Friday October 31, 2025 @09:39AM (#45771863)
The lovely thing with Haskell is you have the ST monad that lets you have as many mutable variables as you want, as long as they stay within ST.