News for hackers. Stuff that matters.
Re:John Carmack on Mutable Variables by throwaway2037 on Friday October 31, 2025 @04:45AM (#45769717)
In my IntelliJ (a recent version), if I write a small Java function like this:

    private static void blah()
    {
        final int abc = 3;
        for (int def = 7; def < 20; ++def)
        {
            System.out.print(def);
        }
    }
The variable 'def' is underlined. Mouse-over hint shows: 'Reassigned local variable'. To be clear, 'abc' is not underlined. When I write Java, I try to use the smallest variable scopes possible with as much final (keyword) as possible. It helps me to write more maintainable code, that is easier to read.
Re:John Carmack on Mutable Variables by xxs on Friday October 31, 2025 @09:38AM (#45771853)
1st) you use ++def in a loop, don't be weird; 2nd) if 'abc' is to be used in the loop body, define in the loop, e.g. for (int def = 7, abc =3; ...); 3rd) this is an IntelliJ bug - both 'def' and 'abc' in the sample are always defined.
Re:John Carmack on Mutable Variables by pacoverdi on Friday October 31, 2025 @10:09AM (#45772154)
3) looks like you read 'underlined' as 'undefined'
Re:John Carmack on Mutable Variables by xxs on Friday October 31, 2025 @10:20AM (#45772279)
true that, thanks!
Re:John Carmack on Mutable Variables by sitzkrieg on Friday October 31, 2025 @11:08AM (#45772852)
the only thing that is weird is your lack of understanding temporary variables
Re:John Carmack on Mutable Variables by xxs on Friday October 31, 2025 @11:11AM (#45772896)
perhaps... yet, Java doesn't have a definition for temporary variables
Re:John Carmack on Mutable Variables by throwaway2037 on Thursday November 06, 2025 @06:44PM (#45841964)

    > you use ++def in a loop, don't be weird
I come from a C++ background where it is always advised to use ++i instead of i++. It's just a habit. Does it stress you to read ++i over i++?
Re:John Carmack on Mutable Variables by xxs on Monday November 10, 2025 @04:27AM (#45874168)
>Does it stress you to read ++i over i++?

Of course not, I do use both. Admittedly i++ is a lot more common in Java, and for loops i++ is the standard idiom. Not using the standard idiom usually implies less practice, e.g. str.indexOf('x') < 0 is the standard one, not == -1. Even the backwards iteration is a postfix subtraction::

  for (int i = array.length; i-- > 0;) doStuff(array[i]);
Re:John Carmack on Mutable Variables by shagie on Friday October 31, 2025 @12:47PM (#45774068)
As an aside, you might also enjoy the inline inferred annotations.

https://www.jetbrains.com/help/idea/annotating-source-code.h...

Seeing @NotNull in there even if the author hasn't specifically written that can help in understanding (and not needing to consider) various branches.

Re:John Carmack on Mutable Variables by e-topy on Friday October 31, 2025 @01:19PM (#45774408)
This works in RustRover as well! Super useful.
Re:John Carmack on Mutable Variables by sn9 on Friday October 31, 2025 @02:48PM (#45775348)
Rust's type system specifically facilitates more powerful tools: https://github.com/willcrichton/flowistry