Post #4362182
2026-07-26 12:44 UTC
Typeless variables are a delusion, they’re just guessing what type they should be for you.
Replies (1)
-
@KairuByte@lemmy.dbzer0.com 2026-07-27 05:41
Not… really. I can kinda see where you’re coming from, but if you are assigning a .ToString() to a variable, the only type it could be is a string. It’s not guessing, it’s inference. You’ve provided enough information to know what the type is, so it is now that type. The moment you introduce ambiguity, such as var test = 1 there are many things that variable could be, so you can no longer infer its type. Inference is not guessing. Can it go wrong? Certainly! But its quite rare. And the solution in those rare cases is explicit typing.