4 ms·
What about the cognitive load on someone reading person1 person2 person3. Now I have to realize person 3 in your code is person2 and person2 was person1, person
by cdevs 9y ago
What about the cognitive load on someone reading person1 person2 person3. Now I have to realize person 3 in your code is person2 and person2 was person1, person1 and person2 are now dangling and will never be touched again hopefully. I love the idea of pure functions but I have always thought there was a missing piece in functional programming.
- Anderkent 9y agoNo sane language makes you write person1 person2 person3. Immutability doesn't mean you can't reuse names; only that the reassignment is in lexical scope, and doesn't impact any other references to what you saw as person1.
- cdevs 9y agoRust calls it shadowing and throws this example: fn main() { let x = 5; let x = x + 1; let x = x * 2; println!("The value of x is: {}", x); } Sure this is a syntax example and you shouldn't be creating Immutable variable x and then adding +1 to it for no reason. If you did have a reason you should add it to the variable name so it's more likely developers say let xPlusOne = x + 1; Or a kitchen example: Let cream = getRefridgeratorItem(cream); Let whippedCream = blend(cream); So you reply no sane language makes you do this but why didn't the author show that? His goal was to make things more readable but lets be honest functional programmers would judge you all day for making a promise and then copying over that promise with something else. You may do it at work but the purist trolls hate reading it.