Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Anders Bjerner 487 posts 2990 karma points MVP 8x admin c-trib
    Apr 16, 2016 @ 21:47
    Anders Bjerner
    0

    Definition of camel casing?

    I'll admit - this isn't exactly Umbraco-related, but questions without an exact answer (I want to hear peoples opinions) are frowned upon over at StackOverflow, so here goes:

    As a developer, what do you understand by the term camel case?

    From what I can tell, the broadest definition of camel case is, that if you refer to it as just camel case, it is assumed to start with a lower case letter - eg. nameOfMyMethod (which can be explicitly be referred to a lower camel casing). On the other hand, if the name would start with an upper case letter - eg NameOfMyMethod it would be called Pascal case (or upper camel case explicitly).

    So if I were to create a method that would convert a string to upper camel case, would the best name be ToPascalCase or ToUpperCamelCase. Similar, for a method for converting a string to lower camel case, would the best name be ToCamelCase or ToLowerCamelCase?

    Hope this makes sense ;)

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Apr 16, 2016 @ 22:40
    Chriztian Steinmeier
    5

    Hi Anders,

    I have the same understanding as you - and I'd call them toCamelCase() and ToPascalCase() just to mess with people :-)

    Nah - just kidding ;) but I wouldn't use Upper/Lower in the names...

    EDIT: So just to be perfectly clear:

    In JavaScript, I'd call them toCamelCase() and toPascalCase(), while in C# they would be ToCamelCase() and ToPascalCase().

    /Chriztian

  • Nicholas Westby 2054 posts 7103 karma points c-trib
    Apr 17, 2016 @ 02:43
    Nicholas Westby
    0

    I would call it ToCamelCase and it would accept one optional boolean parameter that is defaulted to false. If set to true, it would capitalize the first letter. So:

    public static string ToCamelCase(this string str, bool capitalizeFirst = false) { /* ... */ }
    
  • Dan Diplo 1554 posts 6205 karma points MVP 6x c-trib
    Apr 17, 2016 @ 18:57
    Dan Diplo
    1

    Note that Umbraco has a lot of built-in string extensions in the Umbraco.Core namespace , such as ToCleanString(), that do something very similar. So don't reinvent the wheel! :)

  • Lars-Erik Aabech 349 posts 1100 karma points MVP 8x c-trib
    Apr 19, 2016 @ 10:05
    Lars-Erik Aabech
    100

    It has an exact answer. It has been around for decades.
    PascalCase and camelCase. Period.
    The "sometimes known as" argument is irrelevant.
    UpperCamelCase doesn't have it's own page on Wikipedia, it's redirected to CamelCase. So there!

    This post is cleared as 100% objective scientific researched empiric proof.

  • Lars-Erik Aabech 349 posts 1100 karma points MVP 8x c-trib
    Apr 19, 2016 @ 10:16
    Lars-Erik Aabech
    1

    For lack of better knowledge, I imagine that a person who insists on calling it UpperCamelCasing is the same kind of person who insist that using the waterfall method and Visual Basic with WebForms is a good idea.

    Might be wrong, though. :)

  • Anders Bjerner 487 posts 2990 karma points MVP 8x admin c-trib
    Apr 19, 2016 @ 10:41
    Anders Bjerner
    1

    Thanks a lot for the answers.

    I think I'll go with ToCamelCase and ToPascalCase then.

    @Dan Diplo this isn't for an Umbraco package, so I need to implement my own. I already have the code, but just needed to figure how to name my methods.

    @Lars-Erik Aabech That was how I understood it as well, but not all people know this. My goal was to find method names that developers are most likely to understand. But it seems that may still be ToCamelCase and ToPascalCase :D

  • Bjarne Fyrstenborg 1284 posts 4038 karma points MVP 8x c-trib
    Apr 19, 2016 @ 10:52
    Bjarne Fyrstenborg
    0

    I also think ToCamelCase() and ToPascalCase() in C# and toCamelCase() and toPascalCase() in javascript is clear enough.

    For my package Color Palettes I also added a camelCase filter: https://github.com/bjarnef/color-palettes/blob/master/ColorPalettes/ColorPalettes/ColorPalettes/filters/camelcase.js

    Update

    I meant of course PascalCase not UpperCase.

    /Bjarne

  • Lars-Erik Aabech 349 posts 1100 karma points MVP 8x c-trib
    Apr 19, 2016 @ 10:53
    Lars-Erik Aabech
    0

    UPPERCASE is not the same as PascalCase.

  • Bjarne Fyrstenborg 1284 posts 4038 karma points MVP 8x c-trib
    Apr 19, 2016 @ 11:04
    Bjarne Fyrstenborg
    0

    Sorry, it was PascalCase I meant :)

  • Lars-Erik Aabech 349 posts 1100 karma points MVP 8x c-trib
    Apr 19, 2016 @ 11:08
    Lars-Erik Aabech
    0

    :)

    The new screaming code style...

    if (MYVARIABLE) {  
        MYINSTANCE.DOVERYEXPLICITSTUFF();  
    }
    

    Reminds me of BASIC on an Apple II or Commodore 64.

Please Sign in or register to post replies

Write your reply to:

Draft