C# Summaries

Hey guys, this isn’t exactly Unity related, heck Unity Script might can do this, no idea.

But I’m curious as to know how the initial C# “///” knows sort of what to put in a summary.

Take for example I have a Method called DefendAlly(){} Alright, well if I put /// above the method,it will give an initial description of “Defends the Ally” How does it know what Defend or even Ally means?

Another example if I make a method called “Load(){}” It will put “Load this instance.”

I’m just kinda curious as to how it sort of knows what I’m trying to do in most cases to where I don’t even have to always type something in.

It’s not C# per se. It’s the editor (Mono or VS). It scans down and takes a best guess, splitting words on capital letters, parsing the parameter list, etc., and in general trying to fill out as much as it can to make our lives easier when documenting code.

2 Likes

Ahh that’s pretty nifty… Yeah I didn’t think it was C# per se either, figured it had something to do with the IDE’s… I’m guessing this is where the camelCase stuff started to become used? I always just did that because it was how I was brought up to coding, but perhaps it has a more underlying reason, such as stuff like this.

camelCase and PascalCase predate fancy editors, but it does make the job a lot easier for those fancy editors.

2 Likes

Ah okay, yeah I was brought up on it was just easier to organize things on a human level like that to better identify variables, etc.

Always do variables with camelCase and Methods, etc in PascalCase.
I’ve also seen some people put a “_” at the start of a variable, no idea why, guess for better organization for them.

Typically, that indicates the variable is global.

Some people do that to distinguish private variables from public variables (and some use “m_”), although many style guides argue that all variables should be private, and only properties should be public. No sense for a religious war, though, as long as you pick one way and stick with it.

7 Likes

@cdarklock : Ahh okay, yeah the people I’ve seen do it just did it for no reason other than to do it LOL.

@TonyLi : Eh yeah I’ll stick to what I do haha. Not trying to change the subject to ways we code now lol.
I was just curious is all, well - now I know lol.

@TonyLi made a good point - in the OOP world, global variables effectively don’t exist anymore, so it would make sense to use it as a private/public distinction. But most teams I’ve worked on had coding standards geared to C++ and not to C#, and if you try to tell a C++ programmer not to use globals he’ll probably slap you.

2 Likes

I thought Global’s were bad practice in general? Why would someone want to do stuff in bad practice LOL.
I mean there’s a time and place for them (In C#) at least. But I rarely if ever use them for anything.

Much easier to just use public/private, etc.

In general, yes. But public data members of static classes are effectively globals; so long as the class is in scope, everyone can see them and everyone can change them. This has all the same drawbacks and problems as a global, so we’ve gotten ridiculous about it and now you have to do this.

public static class MyStuff
{
    private int howMuchStuff = 4;
    public static int HowMuchStuff
    {
        get { return howMuchStuff; }
        put { howMuchStuff = value; }
    }
}

Then you say things like “if(MyStuff.HowMuchStuff > 12) MyStuff.HowMuchStuff = 0;” whereas in the olden days of C++ we would have just said “int HowMuchStuff = 4;” and then “if(HowMuchStuff > 12) HowMuchStuff = 0;” without running any added risk.

Today, we do what amounts to the same thing, but we write a lot more code to make it happen. And C++ programmers tend to think this is silly.

Ahh yeah I totally get what ya mean.

While I definitely agree globals aren’t a good practice as a rule of thumb, sometimes I find them easier to use. For example, my game pre-calculates several hundred sets of position and rotation data (it’s a circular galaxy map so there’s lots of polar coord transformations to do, etc). That data will never change and there’s no need to serialize it, so I just stash it into a static class where it’s easy to use. Nothing has to create it or keep a reference to it. It’s just always there.

It’s kind of an edge case, and there are folks who would get all worked up about it anyway, but those people aren’t writing my game. :slight_smile: (Actually, with as busy as I’ve been lately, I’m not writing my game either, lol.)

2 Likes

Yeah I only ever use them in extreme cases, or if I’m making a single player BS game I’ll just make the health a static just so it’s easier to mess with later. When there’s only one health (my health) there’s not much that can really go wrong. So yeah in some cases, I do use them, just haven’t made a game like that in awhile.

What kind of game are you making?

An awful lot of people get very worked up about the idea that you don’t agree with their arbitrary requirements. When I work for you and this is against your coding standards, then you can complain. But if you’re not paying someone, you don’t get to tell them how to code.

3 Likes

I’ve started using singletons and static variables a lot more lately. I don’t really see why anyone would hate them, but then again people get worked up about all sorts of things. It’s usually pretty obvious when you’re treating a static variable as a dynamic one. The way I see it, the more data can be made global (in the sense that they actually are global data and not simply masquerading as such) the better. It makes my whole game easier to deal with.

1 Like

Oh I can agree on that my self… I just don’t have many uses for them at the current moment… I find it much easier to use non-statics for MP games. That way it’s cleaner and easier to distinguish who is who… To be totally honest though, never even thought about trying a static inside an MP game… Multiple players having health, whether they are turned on or off, might cause errors.

Well in a ‘who is who’ situation, it’s clearly not a global data point by nature. But if you can ensure that something has a static nature then doing it that way is worth it in my opinion. For example in my game the player ship is referenced as a static singleton variable across all of my code. Why? because there’s only one player ship at any given time, and even if the player would change ships dynamically, it doesn’t change this fact (and having multitudes of references to update actually increases the risk of bugs).

Even if I referenced the player ship on a ‘manager’ object, and accessed it through a non-static reference to that object, that’s pretty much the same thing anyway, plus code baggage related to getting and storing the manager in a lot of scripts.

1 Like

I implemented my localisation code in a static class, because it makes absolutely no sense for any part of the game to be using a different localisation than any other part. When you set the language for the game, it’s set for everything everywhere all at once. That’s a global. It makes no sense for it to be anything but a global. I wrap it up in all the fancy C# stuff to make it play nice with managed code, but technically anything anywhere in the game might conceivably change the display language by calling SetLanguage(“farsi”) anytime at all.

The only thing that prevents this is that I am not a lunatic, I do not have anyone else on my team, and even if I did the project is in source control so I could go “wtf” and go find the 馬鹿 who checked in that change.

4 Likes

Yeah, you have to depend on a minimum of common sense from someone swimming around in a codebase.

In any case, I think something that a lot of people don’t consider is that it’s probably easier to debug someone messing with a global variable than it is to debug someone messing with a particular instance of it, if you use some common sense and use get/set or similar.