• Zatapatique (unregistered)

    if (((PVCheckBox)sender).Checked) { frist_ = true; }

  • (nodebb)

    Google Closure (RIP) suggested a trailing underscore for private variables: https://google.github.io/styleguide/jsguide.html#naming-method-names This was what we used till we finally got rid of it.

  • (nodebb)

    Why are they casting to CheckBox? I doubt that PVCheckBox is a supertype, so this doesn't make any sense.

  • Naomi (unregistered)

    Why are they casting to CheckBox? I doubt that PVCheckBox is a supertype, so this doesn't make any sense.

    My guess is that PVCheckBox extends CheckBox and the cast is superfluous.

  • TS (unregistered)

    So the requirement is: There are two check-boxes, and one or both must be checked. I'm not saying that requirement is wrong, but it's sufficiently unusual that I would want it confirmed.

    Also, using check-boxes for this requirement is horrible UI. Better to have radio buttons with Option One / Option Two / Both.

  • (nodebb) in reply to Naomi

    My guess is that PVCheckBox extends CheckBox and the cast is superfluous.

    sender is still of type object, so it must be cast to something that has a Checked property. The fact that they cast it to PVCheckBox in one place and CheckBox in another is probably just inconsistency. I certainly hope that the PVCheckBox interface doesn't have it's own Checked property that shadows CheckBox's Checked property.

  • (nodebb)

    Guess: This was originally a checkbox. Now it should be a radio but somebody demanded that the original be left alone.

  • (nodebb)

    Assuming there are only two check boxes, they just need onechecked_ = CheckBox_func.Checked || CheckBox_member.Checked.

    If there are other check boxes that may trigger this code, that's... a bigger WTF that doesn't, or at least shouldn't, make any sense.

    Not sure I have any problem with two checkboxes instead of radio buttons. Especially if a third option might be added later, and possibly then a fourth. You want 16 buttons to cover all possible combinations of four options?

  • Officer Johnny Holzkopf (unregistered)

    PVC heck Box.

  • Greg (unregistered) in reply to TS

    There may be a UI dependency: maybe if either of those 2 checkboxes is checked, some other part of the UI must be shown/hidden/enabled/disabled.

  • (nodebb)

    I think there's a bit of confusion going on in this article with mixing up snake case with Hungarian. All those examples are in fact not Hungarian at all, they are just using snake case.

    Now compared to other languages, .net had naming conventions from the very start which are actually pretty simple:

    • Types are always PascalCase.
    • Interfaces always have an 'I' prefix (following the Component Object Model standard).
    • Public/Protected/Internal/Internal Projected members are always PascalCase.
    • Methods/Properties are always PascalCase no matter the visibility.
    • Method arguments and local variables are always camelCase.
    • Private fields are camelCase with either "m_" (instance) or "s_" (static) prefix.

    Now the last part never got a huge amount of love and was shorten to a simple '_'. Obviously there would be a naming conflict when local variables have the same naming convention as do have field members, so in a good naming scheme they are different (in a verbose one you need an additional keyword, like this which is an option but bad practice).

    Obviously there's a number of times where those naming conventions were broken, famously in WinForms by MS themselves on launch for event handlers (snake case separated PascalCase). These days it's pretty common to do this for unit tests.

    And there we go, a quick tutorial how to name things in .net since it launched; would have MS decided on the underscore without the completely redundant static prefix then .net would have been the only language I know with a clear naming convention from the very start.

    Addendum 2024-01-05 04:25: BTW the example is an even handler, and it was used with a field instead of a property (as is generally considered best practice - that's a whole other topic). Additionally the private field is using snake_case for some reason and this results in this weird naming mishmash of awfulness.

  • (nodebb) in reply to Melissa U

    Even handlers always have their sender defined as object (it's an old outdated .net1 idea), so you have to upcast the sender to the appropriate type. Since CheckBox is standard WinForm control, I'm pretty sure that PVCheckBox is just a derived type which is pretty common in those old days when inheritance was heavily used over composition in those old presentation layers.

  • (nodebb)

    Assuming that there isn't a third checkbox, the entire method could have been

    onechecked_ = CheckBox_func.Checked || CheckBox_member.Checked;

    Although, if both are unchecked, and the user checks the member (or, "MEMBER") box, then the provided code would not have to check "CheckBox_func.Checked" first, whereas my one-liner does. I am sure this performance optimization will pay off soon.

  • Conradus (unregistered)

    I think I speak for everyone here when I say we'd just as soon not hear about your private member.

  • t (unregistered) in reply to TS

    Is it? Say you have to configure how the service sends you notifications. SMS, and mail for example.

    You have to check one at least. And I'd find it weird if you had the radios instead of two checkboxes for that personally

  • Argle (unregistered) in reply to Cidolfas

    All this about trailing underscores is suddenly relevant to me. A little over 20 years ago, I did on-site C++ training for a large engineering firm. They were wanting to transition from C and I was the training guy at the time. This week, I'm back to work for them as an engineer. As part of onboarding, I spent some quality time reading over their coding guidelines. I've never been the "trailing underline" sort of guy (in fact, I am the one who submitted the horror-show story of the UP, up, up, up, Up, etc. variables), but they are correct in reminding the world that leading underscores in C++ have a specific reason for existence, so use trailing for private values. However, I'm still not sure how I feel about this.

Leave a comment on “Just One Check”

Log In or post as a guest

Replying to comment #:

« Return to Article