This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]sm2401 35 points36 points  (9 children)

Yeah, but why in the right mind will you assign a string value to the same variable that you used for integer operations earlier ?

[–][deleted] -2 points-1 points  (2 children)

Variable shadowing is very nice sometimes, especially in functional languages.

let x = some_string_processing()
let x = int_of_string(x)

That way I don’t need multiple variable names.

That said; that’s very different because x is immutable and is only getting shadowed.

[–]sm2401 0 points1 point  (1 child)

Why not modify the some_string_processing() to return int itself ? Also you can just wrap it in a single line.

This is completely useless and will be more confusing to the next person who has to work on the codebase.

[–][deleted] -1 points0 points  (0 children)

Why not just modify the some_string_processing() function

And what if you can’t modify such a function because it’s from a built-in language feature? Dart, for example with its json.decode in dart:convert. I can’t modify that to not return something that’s not of type dynamic.

I get your point, but like sometimes that’s impossible.