What are the reasons to choose between camelCase and Pascalcase in method names?

Asked

Viewed 5,166 times

17

First, I’m not interested in what you like best or what you use in your language, I want to know the motivation to choose one or the other pattern in a hypothetical language.

Second, this is a bit of coding style, which you should actually follow the pattern that the language has adopted, but mostly about why a language would adopt it like that. It’s not about an existing language, I’ll quote them to illustrate what I want.

A very typical example is that Java has adopted camelCase and C# has adopted Pascalcase. I have one bias Today for Pascalcase, I’m not sure why but once I saw Pascalcase it made a lot of sense to me, even having adopted camelCase before in other languages. But only C# kind of adopted him. I look at that and I feel that it’s more standardized, it looks like something in the structure of the code and differentiates it from the variable that’s part of the algorithm.

Half that everyone adopted the Pascalcase for names of types and even namespaces. In C# it does not differentiate anything for the method, but they are different contexts, the IDE puts proper color. Java, JS, and others preferred to make it clear that it is a method in a different way, while confusing it with variable names, except for the parentheses that is almost always used, but not in all cases. In the beginning Java never had this confusion, today it has, JS had to confuse, but it was not a well thought out language (PHP has a little of the two things, not confused at the beginning and was not well thought out, it does not always respect it). C# was born knowing that this could be confusing.

I like the idea of camelCase, but it looks ugly (it’s very subjective). I consider it an aspect of the programmer’s UX and so considering the design of language, because choosing the standard style does not cease to be part of this discipline, so wanted understand the motivation of each one’s use.

  • 4

    I know a language that would be sad because you didn’t consider snake_case in the question.

  • But you can talk about it :) This I hate with all my might and I already know why :P

  • is a question that evokes many opinions, because if language as an example C# provides you with a style (it is indicated by the IDE but nothing that cannot be disabled) and you do not want to follow this style, you have no obligation and can be chosen your way, the important thing is if it started in a way that always does the same way.

  • @Virgilionovic the question is not about that, it is about the plausible and reasoned justification of decision to choose one style or another, so it has no opinion, it is why to do one or the other. https://pt.meta.stackoverflow.com/q/486/101

  • 1

    @Virgilionovic Note that the question is not "what style should I use", but rather "what parameters are considered that lead a language to adopt a certain style". The answer does not depend on the opinion of those who are asking or answering.

  • @Maniero é sobre a justificativa plausível e fundamentada de decisão de escolher um ou outro estilo the style is general (for all the programming you do) or the style is through languages (it seems broad and the inquiry why cited in the question languages)?

  • To give examples of differences existing today and show that there are basically two main choices. The question is about any language, not one or a few specific ones, actually it’s about a possible future hypothetical language, taking Anderson’s comment, is about the parameters to consider to choose a style or another if you are to create a language and establish in its basic API and style guide. The question is about design of language and not about existing ones. It’s about motivation to give better experience of the programmer when going to encode.

  • It’s an intriguing question. I know a person who hates each other with all his might and always tends to use snake_case or kebab-case (I saw this name in the OS now little) - as it is used in Lisp and derivatives - under the premise that it is the reading becomes much simpler and "natural".

  • @LINQ The answer does not need is stuck only on these two, who knows even speaking otherwise can indicate a way (as long as it is not just the person talking because they like it)

  • related https://github.com/ktaranov/naming-convention/blob/master/C%23%20Coding%20Standards%20and%20Naming%20Conventions.Md and https://docs.microsoft.com/en-us/previous-versions/netdot/networkframe-1.1/xzf533w0(v=vs.71) explain why there are some questions

  • @Virgilionovic did not find anything that explained the decision. Say it is to be consistent with the . NET does not help at all, because the question is precisely why it is adopted like this, not which convention someone adopted. Anyway the question is not about what C# adopted, but why a language should adopt one form or another. It may be that coincidentally C# or other language has made a decision based on some criterion and it serves as a good explanation, but it is not the focus of the question understand anything if a specific language, this is collateral. Thanks for the links.

  • So your question won’t get a dignified answer, since whoever created it makes it hard for us to talk to him to ask because it was made like this.These links are referenced from the official website and independent of anything has no disclosure of why but, has some points so "related" and not as main reason, but, I already have the conclusion that this question unfortunately will not bring the answers, no use asking such a broad question, it should be divided into languages (that would be a lot) each one follows a philosophy and even seen culture in many links

  • If the person understands about design language will have. Again, the question is not about the decision someone made, but about why to make that decision, regardless of whether someone made the decision in a certain way. Even if no one has taken it, you can take it now, as long as you have a plausible explanation, as long as you expose each person’s advantages and disadvantages, you have information that shows a reason, as Ugo did, although not completely. You have the fixed idea that I want to know every language, that’s not what I asked for.

  • I understood after the penultimate comment that you want the reasons, the whys. For me your question is good, but, is broad has to take into account many aspects.

  • 1

    I will also highlight the approach of Go, which makes public the members who start with capitalized character. It is not specific to the PascalCase, but ends up being the convention adopted. The camelCase, consequently, they remain private. Despite this, I find it curious the question not to have included the snake_case, which ends up being adopted by languages like Rust. I personally find the snake_case the easiest to read, although it contains more characters consumed, making it difficult to frame on smaller monitors. I think in the end it’s a mere matter of the designer’s opinion.

Show 10 more comments

1 answer

14

First a little history

This answer is based on this excellent article by Celso Kitamura https://celsokitamura.com.br/pascal-case-e-camel-case/

In 1813 Jacob Berzelius, a chemist, suggested a convention to formalize the way of writing chemical formulas. He proposed to indicate each chemical element by a one or two-letter symbol, the first in uppercase. See Example below:

inserir a descrição da imagem aqui

In the example of the formula NaCl we would have SódioCloro = Sodium chloride, Even at that time there was no single concept for writing chemical formulas, and this proposal was adopted to normalize writing, and eventually became the rule. It was something that facilitated the life of the user, as it generates fewer errors and is easy to understand and use when writing formulas and elements.

This is the convention adopted in the periodic table, which was later applied in other media such as programming.

inserir a descrição da imagem aqui

The cardinal points in turn use another convention for example.

inserir a descrição da imagem aqui

Even between the 70s and 80s there was not quite a pattern, for N reasons, I will try to address them at another time. But what we saw was the Camel Case or Pascal Case being culturally adopted, and even though it’s not the rule they’re encouraged.

In the case of . NET, Microsoft recommends:

  • Use Pascal Case for all public membership names, types and namespace consisting of several words.
    Propertydescriptor
    Htmltag
  • Use Camel Case for parameter names.
    propertyDescriptor
    htmlTag

Here’s a list of Naming_Convention of various languages, to reflect on what they have in common, pros and cons, etc. (C and C++, Java, Javascript, . NET, PHP, Python, Ruby, etc.): https://en.wikipedia.org/wiki/Naming_convention_(Programming)

  • Provide additional information (ie metadata) on the use for which an identifier is placed;
  • Help formalize expectations and promote consistency within a development team;
  • Allow the use of automated refactoring or search and replace tools with minimal error potential;
  • Increase clarity in cases of potential ambiguity;
  • To improve the aesthetic and professional appearance of the work product (for example, disapproving excessively long names, names - comical or "fluffy" or abbreviations);
  • To help prevent "naming collisions" that may occur when the work product of different organizations is combined (see also: namespaces);
  • Provide significant data to be used in project transfers that require sending the program’s source code and all relevant documentation;
  • To provide better understanding in case of code reuse after a long time interval.

A word is a key

inserir a descrição da imagem aqui

Notice how the height variation of the uppercase ascending line creates a visual Pattern, which can be used to easily recognize words. This variation in the frequency of letters helps the eye to recognize patterns and words faster. Already when everything is in HIGH BOX, the line does not vary, it is straight, and to recognize the word we need to really read more carefully.

var UmaChaveUtil //(3 variações de Case)
var umaChaveUtil //(2 variações de Case)

A "key" with more variations of "secret" may be more useful and better for general recognition... (I’ll talk more about it below)


Beyond the conventions - Typographical and UX aspects

Regardless of the language other points should be taken into consideration. For example, what is the difficulty of writing Palavraslongasemcamelcase? What is the milkability of this? In a world of words it is easier to recognize UmaPalavra or umaPalavra. Scanning is very important when identifying specific words in the middle of others. And in this Nngroup article there are good clues to the practices you can adopt that will present a better UX https://www.nngroup.com/articles/glanceable-fonts/.

Independent of being adopted Camel or Pascal the system is case sensitive? Using these rules will result in more errors or fewer errors, is it easier to write or read? For a system that doesn’t exist yet, consider an A/B Test. Reserved words can follow a convention, whereas classes that are first names can have another one... So even a Qualitative Research can be interesting in this work, something that is very common to do in UX and Design Thinking.

4° Heuristic Law: Users should not ask themselves whether different words, situations or actions mean the same thing.

When talking about heuristics the main factor may be consistency, so having clear rules avoids errors and makes the user more comfortable. So when defining a rule, avoid letting things like this be valid, because in addition to not having coherence, it can be ambiguous and confuse the user.

Source: https://www.nngroup.com/articles/ten-usability-heuristics/

inserir a descrição da imagem aqui

Notice again the image above. Could the user understand "Calendar" differently than "calendar"? I can’t say, but it may be that people understand this differently, a calendar may be any calendar, the Calendar may be the Calendar App.

Visual prominence

inserir a descrição da imagem aqui

Note the image above, see as a title with Cases varied seems to stand out more than the other only with the initial letter capitalized.

Source: https://medium.com/@jsaito/making-a-case-for-Letter-case-19d09f653c98

A little opinion

inserir a descrição da imagem aqui

When you think of systems, the reserved words or standard words of the language, or that repeat themselves all the time and are equal to all, could be "more discreet", already the variáveis or classes (as in CSS), which are words that the user "invents" (and that each one can write in a way), you could define clear rules. For as are words designed by the user himself rules could be better than good practices. This would be a way to normalize writing independently of who writes. In CSS .classe is different from .Classe, but both work... Is that good or bad? Logically it depends, but if only one of the forms were allowed could be better for the user. The user likes to follow patterns, and the eye learns to find patterns... And Pascal Case can be an easier default for the user to identify non-original words in the language (words that are defined by other users). But as I said, more research and testing must be done.

Example table with clear rules:

inserir a descrição da imagem aqui

Gestalt

When it comes to "pattern recognition," remember that not everything we see we’re actually reading. One of the principles of Gestalt is the recognition of forms. The human eye and the brain always tend and recognize shapes and patterns. And this can be fundamental to the scanning of code. It’s like a ruse that can help you quickly recognize words in the middle of the text.

inserir a descrição da imagem aquiinserir a descrição da imagem aqui

As our brain uses visual reading parameters, when we see a compound of elements (be they objects, people, landscapes, animals or texts), the tendency is to group characteristics that are similar, so that their interpretation is as fast as possible.

Source: https://whitecom.com.br/8-principios-da-gestalt/

Wiki da Gestalt: https://en.wikipedia.org/wiki/Gestalt_psychology

Although it has been known for some time that the larger text is more readable, this study has shown that weight and process are also important. Lower-case letters required 26% more time to read accurately than upper-case letters, and condensed text required 11.2% more time than normal. There were also significant interaction effects between the case and the size, suggesting that the negative effects of lowercase letters are exacerbated with small font sizes.

inserir a descrição da imagem aqui

Formerly the Ides, Terminals and Prompts were not so customizable, they had a font-size as well as a font-family standard, and color. Everything was thought for the user to have a better experience. So the typographical choices are also linked to how you will write. It is already proven that long texts not all written in capital letters, just as more "condensed" sources are more difficult to read.

inserir a descrição da imagem aqui

Note the shape of the "shapes" see how Uppercase is more difficult to identify the character, mainly because of the "lack" of contrast because it has no descendants (p) and ascending (d) in base-line and caps-line.

inserir a descrição da imagem aqui

See how a font with a small "X Height" is harder to tell the difference between Upper and Lower case (the first source has the X Height minor).

inserir a descrição da imagem aqui

Self-regulation

But when language is free what we see is the emergence of conventions, whether written or organized, as is the case with CSS and its nomenclature methodologies as OOCSS, SMACSS, BEM, DRY. Site with some examples and definitions https://tableless.com.br/oocss-smacss-bem-dry-css-afinal-como-escrever-css/ it is worth saying that for each of them there are pros and cons, but choosing a standard rules should be followed, even in a "language" that has no rules :)

inserir a descrição da imagem aqui inserir a descrição da imagem aqui

And in Mobile?

Have you ever wondered how tiring it can be to write in lower case letters on a mobile device? Especially with the spell checker trying to turn the camelCase every time? This is an environment that certainly would have to be studied to evaluate what would be easier and more productive for the user to work in. I didn’t think you were referring to the subject, but maybe the kebab-case (hyphenated words) are easier to type in cell phone.

inserir a descrição da imagem aqui

So all these choices can influence the UX and the choice of what to adopt...

Recommended book Design-Time Web Usability Evaluation with Guideliner: https://site-109191.mozfiles.com/files/109191/2228-7961-1-SM.pdf

OBS 1: The Nngroup article quoted above made with "loose" words and not in plain text. It does not specifically address Camel Case or Pascal Case, and even suggests further studies.

OBS 2: I didn’t talk about it, but think about which of the two styles would be more interesting for Dyslexis. Thinking about accessibility and inclusion would be nice to have more information and take into account how a person with dyslexia or ADHD interact with these types.

  • The introduction is very good because I did not know this, then on the documentation of . NET didn’t think it added anything relevant because it’s not the focus of the question, the most important part where talking about what matters is promising, I’m still digesting. It all makes sense, but note that there was a different choice for variables, methods, and types, just to say the items that I consider most important and your explanation does not consider these different, note that the question has to do with method (I understand a little better the choice for variable and type).

  • The issue of case sensitive then it doesn’t matter to the question, but let’s say it is. The idea of the A/B test is standard for UX and indeed should be made for choice, the question is precisely whether they did before I can take advantage or conclude something even empirically. I even imagine that everything was thought to use without IDE in a readable way. Pity that the final analysis is not about the two styles. I’m still evaluating more.

  • @Maniero without wanting to give rss excuses, but is that I have a very superficial knowledge of the abstractions of programming, as well as what would be methods, classes etc... I tried to contribute my knowledge of typography and UX. I think that when a language comes up (something rare), such as FW JS for example, hj authors have much more access to research and testing to evaluate what would be most appropriate. Imagine in a Mobile environment, how annoying it would be to alternate between the Upper and Lowers, and to make matters worse imagine the spell checker changing what you write...

  • @Maniero One of the most important Euristics is consistency. So the important thing is that it is not something "everyone does as they like", it would be more appropriate to maintain a standard. Now which pattern to choose you can decide by studying her persona, her environment and having empathy.

  • 1

    Worse than I think they don’t have :D Otherwise it would be easy to find something about it, I think they choose because they liked it so. The C# people must have a good reason, but I just assume. Because C# and . NET were born from a real Java implementation, for them to change everything must have a reason. I don’t even want to know their motive, I want to know their overall motive, which coincidentally could be theirs. The answer is good, instructive, I’m still not sure if she responds to what I want. About consistency I know, I’ve even written several times about it. And it’s not a question of which to choose, but why.

  • @Maniero this is a subject deeper than it seems, I hope that there are others willing to contribute and bring something that can be more "definitive" or more concrete at least []s

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.