I'm new to The Cornell Lab. They sure do have a lot of cool #bird stuff! This morning's discovery was Project FeederWatch. It's a nifty visual database where you can mix and match region, food, and feeder type to figure out what birds you might attract to your yard.
Having gone to the office today (my employer's slowly transitioning away from letting folks work from wherever/whenever), I was late for the train back home, so I took a detour by the river and met this very friendly pair of mallards.
(These are barely-cropped phone shots! Didn't have my camera with me nor a tele lens in my phone – they got really close.)
#birding #birds #birdwatching #birdphotography #birdsofmastodon #photography #wildlife #wildlifephotography #naturephotography
@TimPurdum @khalidabuhakmeh @SmartmanApps Unity used to support a couple of other languages (a flavor of JavaScript and something called Boo), but now it's just C#.
--
Using capitalization and/or underscores to allow a user to quickly see what is private vs. public makes perfect sense to me.
--
That might be true if there were capitalization standards that were consistently followed even by standard libraries.
UnityEngine.Random.value -- oh, value must be a private static field, right? (Or would that be called _value?) Nope, it's a public property. (One part of the Unity documentation gives its declaration as "public static float value;", but elsewhere it's described as a property.) For added fun, it yields a different value each time it's accessed. I don't know why it's not a method.
string -- a local variable? A primitive type like int? Nope, it's a class name.
This is the source of my confusion and frustration.
@SmartmanApps Ah, yes, that does explain that confusion.
I'm still wondering about this:
If the field is private (as almost all fields should be), then it should be called myi, right?
If so, that field and the argument to the constructor have exactly the same name. You'd need:
private IThing myi;
MyClass(IThing myi)
{
this.myi = myi;
}
You could do it with a leading underscore:
private IThing _myi;
MyClass(IThing myi)
{
_myi = myi;
}
In any case, having two different variables that differ by one character (either an underscore or initial capitalization) strikes me as a bad idea. A trivial typo could easily lead to a syntactically correct program that does something different from what was intended.
(Mind you, many years of Java made me perfectly happy with
Thing thing = new Thing();
but there Thing is a class and thing is an instance.)
@SmartmanApps I'm not talking about different scopes but about different access levels. The convention in question would want you to declare
public int X;
but
private int x;
Both are fields with the same scope, but the latter can only be accessed within this class.
--
"Why is the argument to classconstructor all lower" - as per comments, it only has scope within the constructor
--
Yes, I get that, but by the same logic shouldn't the argument to MyMethod be myi instead of MyI?
As written, the MyMethod argument MyI shadows the field MyI, so there's no way within MyMethod to refer to the field without using "this".
UnityEngine.Random:
Uses nondeterministic properties (?!) instead of methods to return random values.
Does not follow Microsoft's convention for capitalizing property names.
Makes the upper bounds inclusive, unlike just about every other random library, because why the hell not.
Directly addressing your point, I liked Java's answer much better:
this.x = x;
My students get confused about even that. X = x seems like a recipe for disaster.
Worse, one version of the C# convention would make both private fields and method arguments camel case, which would prevent you from doing this very thing.
Even worse, if you change your mind about the visibility of a field, you're supposed to rename it! (Bonus pain if you believe private fields should start with underscores.)
There's only one field in your example: MyI. C# makes it private by default, right? The convention would be for it to be camel, not Pascal, right?
Why is the argument to classconstructor all lower but the argument to MyMethod Pascal?
I assume classconstructor should be ClassName.
In MyMethod, the argument MyI shadows the field with exactly the same name, so you'd have to resort to the this.MyI trick anyway if you wanted to access the field.
Building the scope into the name seems like a terrible idea. I see many downsides and no benefit.
@futurebird My dog (who may secretly be a cat) chooses this moment to ring the bell to go outside.
@Rivikah @futurebird Three words: Wheel of Time.
People generally seem to agree that C# class names should be PascalCase.
Except for, y'know, the class you'll probably use most often: string.
Capitalization in C# / Unity is an infuriating minefield.
Microsoft and Unity offer slightly different standards and then don't consistently follow them.
There is no entry for "capitalization" in the index for the 1000-page C# 10 in a Nutshell. There is some advice under "identifiers", but it differs from what is given by the previous two sources.
Many sources want to capitalize private and public fields differently. Why would you do that?!
Unity adds spaces and changes the capitalization when displaying class and field names.
If you refactor a name, Unity bloats your code with a FormerlySerializedAs attribute.
#2781 The Six Platonic Solids
@xkcd Obviously the secret sixth Platonic solid is the d10.
CS professor, game designer, and fire dancer ordinaire.