Coffeehouse Thread

8 posts

Just a thought: EnsureBlah isn't an appropriate naming scheme when the thing can't be ensured

Back to Forum: Coffeehouse
  • User profile image
    Sathyaish Chakravarthy

    I find the name EnsureSuccessStatusCode and the naming scheme it uses utterly confusing.

    I would get frighteningly confused everytime I encountered this line when I was learning to use the HttpClient class, until I read its meaning in the MSDN. It left me wondering how a client could ensure that it received a 200 status code.

    I think a more appropriate name for it should have been ThrowExceptionIfNotSuccessStatusCode or just ThrowIfNotSuccessStatusCode.

  • User profile image
    wkempf

    I think most native English speakers understand that name immediately, and I think it's much better than Throw* style names. I have more problems with CheckAccess and VerifyAccess. Check and Verify are synonyms, so tell me which one of those throws and which returns a Boolean without looking it up in the MSDN.

    "There are only two hard things in computer science: cache invalidation, naming things and off by one errors."

  • User profile image
    Sathyaish Chakravarthy

    > so tell me which one of those throws and which returns a Boolean without looking it up in the MSDN

    That's a tough answer to guess. I would guess that the check one doesn't throw any exception because it is only meant to check and report; and verify seems a bit assertive. But then if the answer turned out to be the opposite, I might find that I find no difficulty convincing myself of it.

    What's naming things off and on by one?

    I think threading is difficult, too. There's too much to learn there.

  • User profile image
    Sven Groot

    I think the idea between the EnsureX naming is that it implies that "if this function returns successfully, you can be sure that X is true". What it does if it isn't true isn't explicit in the name, but that it throws an exception isn't a huge leap to make from there.

  • User profile image
    Sathyaish Chakravarthy

    Sure, it doesn't give me diarrhea. It's alright. Just saying it would have been nicer if we (I and Ms. EnsureX) would have met having known each other slightly better.

    Anyway, now that I know her, I'll remember to be more careful.

  • User profile image
    wkempf

    , Sathyaish Chakravarthy wrote

    > so tell me which one of those throws and which returns a Boolean without looking it up in the MSDN

    That's a tough answer to guess. I would guess that the check one doesn't throw any exception because it is only meant to check and report; and verify seems a bit assertive. But then if the answer turned out to be the opposite, I might find that I find no difficulty convincing myself of it.

    What's naming things off and on by one?

    I think threading is difficult, too. There's too much to learn there.

    I think you read that wrong. It's a famous quote. I'll write it different to clarify.

    There are only two hard things in computer science:

    1. cache invalidation

    2. naming things

    3. off by one errors

     

  • User profile image
    ScanIAm

    I LOL'd

  • User profile image
    Sathyaish Chakravarthy

    , wkempf wrote

    *snip*

    I think you read that wrong. It's a famous quote. I'll write it different to clarify.

    There are only two hard things in computer science:

    1. cache invalidation

    2. naming things

    3. off by one errors

     

    Eureka! Splendid.

     

Comments closed

Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation, please create a new thread in our Forums, or Contact Us and let us know.