News for hackers. Stuff that matters.
Re:Zig; what I think after months of using it by saithound on Tuesday February 04, 2025 @11:03PM (#42943611)
Shadowing always has been a feature, doubly so in languages which lack linear types.

It is a promise to the reader (and compiler) that I will have no need of the old value again.

Notice that applying the naming convention you suggest does nothing to prevent the bug in the code you quoted. It might be just as easy to write

const initial_foo = Foo.init(); > const foo_feature_A = try initial_foo.addFeatureA(); > const foo_feature_B = try initial_foo.addFeatureB();

but it's also just as wrong. And even if you get it right, when the code changes later, somebody may add const foo_feature_Z = try foo_feature_V.addFeatureX();. Shadowing prevents this.

Re:Zig; what I think after months of using it by nine_k on Tuesday February 04, 2025 @11:14PM (#42943698)
Said promise should also be checked for sanity. E.g.

  for i in range(N) {
    for i in range(M) {
      # Typo; wanted j.
      # The compiler should complain.
    }
  }
Re:Zig; what I think after months of using it by Maxatar on Tuesday February 04, 2025 @11:15PM (#42943710)
The Rust compiler would complain in this case that the initial i variable is unused. Unused variables should be named with an underscore, _.