25 ms·
> these languages don't have non-member functions or variables Not true. Both have static imports. Which means in e.g. PI * Pow(Radius, 2); all three sym
by masklinn 6y ago
> these languages don't have non-member functions or variables
Not true. Both have static imports. Which means in e.g.
PI * Pow(Radius, 2);
all three symbols may or may not be part of the current class. In this case, only Radius is, the other two come from `using static System.Math` (it's straight from an official example for the `using static` directive).
Also
> it's either a member of the current object, or it's a local variable in the current function.
So they do have non-member variables, in local variables. Making it clear that something is not a local variable is valuable as it means the variable has a much larger scope than you might expect.
- brundolf 6y agoI didn't know about static imports. Technically those are still member functions, but you are able to call them without a prefix, so I retract that point. > So they do have non-member variables, in local variables. Making it clear that something is not a local variable is valuable as it means the variable has a much larger scope than you might expect. Yes, local variables are non-member variables. I'm just pointing out that people's habits may have been built in JavaScript or the like, where a non-member variable could be: - a global - from a closure, anywhere up the tree - an import from another file Whether or not the explicitness is still important in C# code, it's at least much more important in JavaScript and Python code (in fact I'm pretty sure both languages require it)
- masklinn 6y ago> Yes, local variables are non-member variables. I'm just pointing out that people's habits may have been built in JavaScript or the like, where a non-member variable could be: > - a global > - from a closure, anywhere up the tree > - an import from another file C# has "from a closure, anywhere up the tree" and "an import from an other file" though, the only thing it arguably doesn't have is "a global". > Whether or not the explicitness is still important in C# code, it's at least much more important in JavaScript and Python code (in fact I'm pretty sure both languages require it) Technically you can use the `with` statement to make it implicit in javascript. You should not, but you can.
- deleted 6y ago[deleted]
- Bjartr 6y agoHow common is it for code editing tools to be able to highlight local methods v statically imported ones differently? I know Eclipse does it, but I don't know how prevalent the feature is. e.g. Can Vim do it?
- kords 6y agoNot sure if Vim can do it, but code can be read outside of editors. Sometimes people review PRs in browsers. I can see why there might be a confusion when using static imports or properties/methods from the base class without the base keyword.