News for hackers. Stuff that matters.
Re:John Carmack on Mutable Variables by MetaWhirledPeas on Friday October 31, 2025 @02:08PM (#45774914)
> it'd require too much discipline to do such a thing in Python

Is Python that different from JavaScript? Because it's easy in JavaScript. Just stop typing var and let, and start typing const. When that causes a problem, figure out how to deal with it. If all else fails: "Dear AI, how can I do this thing while continuing to use const? I can't figure it out."

Re:John Carmack on Mutable Variables by codethief on Friday October 31, 2025 @02:34PM (#45775194)
I agree that Python is not too different and in general I treat my Python variables as const. One thing, however, where I resort to mutating variables more often than I'd like is when building lists & dictionaries. Lambdas in Python have horrible DX (no multi-line, no type annotations, bad type checker support even in obvious cases), which is why the functional approach to build your list, using map() and filter() is much more cumbersome than in JS. As a result, whenever a list comprehension becomes too long, you end up building your list the old-fashioned way, using a for loop and the_list.append().
Re:John Carmack on Mutable Variables by ndr on Saturday November 01, 2025 @07:24AM (#45780834)
In python there's no let, var nor const. So yes.
Re:John Carmack on Mutable Variables by filoeleven on Saturday November 01, 2025 @09:51AM (#45781656)
Javascript only enforces reassignments to const. So this,

  const arr = []
  arr.push(“grape nuts”]
is just peachy in JS and requires the programmer to avoid using it.

More importantly, because working immutably in JS is not enforced, trying to use it consistently either limits which libraries you can use and/or requires you to wrap them to isolate their side effects. ImmerJS can help a lot here, since immutability is its whole jam. I’d rather work in a language where I get these basic benefits by default, though.

Re:John Carmack on Mutable Variables by throwaway2037 on Monday November 03, 2025 @11:25AM (#45800822)

    > Javascript only enforces reassignments to const.
Java is the same with the keyword final. I never heard anyone complain about it. Are you asking for the special hell that is C++ const correctness?
Re:John Carmack on Mutable Variables by SAI_Peregrinus on Monday November 03, 2025 @12:07PM (#45801410)
Python doesn't have constants at the language level. You can create classes without setter properties, only getter properties, to have constant objects. This is rare, usually people just write the name in SCREAMING_SNAKE_CASE to document it's supposed to be a constant but Python will still allow mutating it.