What is the alternative of 'And' in Portuguese for variable names and methods?

Asked

Viewed 346 times

15

One question that always bothers me when I’m in a Java project where we use Portuguese terms is dealing with method names or variables that represent, somehow, two things and I need to mention both in the method/variable name. In English, and in the same situation, the names get better.

An example, if I am in an English code and have a variable that contains the person’s name and surname, I can have:

firstAndLastName

Simple and easy to read, thanks to And. But in Portuguese our And is the E, which is very bad to read in the code in my opinion, because the uppercase letters end up stuck together:

primeiroESegundoNome

I don’t know about you, but this part ES gives me a lock on reading any code.

Usually, I end up using one of these alternatives:

primeiroSegundoNome
primeiroComSegundoNome

It solves some cases, it just gets weird in others, but in some it doesn’t solve. Example, if I have a method that checks if the dates exist and are equal, wanting to emphasize this situation, none of the forms below meets well:

hasDatasIguais
hasDatasComIguais
isDatasExistemIguais
isDatasExistemComIguais

In terms of name, it would be better hasDatasEDatasIguais, hasDatasESaoIguais*..., but we’re back to the initial problem.

Is this a problem that bothers you too? How do you act in similar cases?

* Here I mixed the English term has with Portuguese, but this is another subject

  • 9

    Boy, I thought only I suffered from it.

  • 2

    I was curious with the answers you will have to this question, very interesting!! Just one thing, (based on opinion)in the date method I use the Has, which in free translation would be "has existing date" rather than "is existing date"

  • @Barbetta, true. It could be hasDatasESaoIguais. I will correct.

  • 1

    @Dherik but the "E" is still very strange rsrs ;P

  • 4

    This is one of the reasons I use English in the name of variables.

  • 1

    This is because the language structures are in English. I find it much easier to read while not finished than while not finalizado, for example.

  • 3

    I prefer to use English in most cases already because of these occurrences, but can also manipulate a little Portuguese. primeiroMaisSegundoNome and existemDatasIdenticas , In the last 'exists' case it is not very important in my view, because if they are identical they automatically exist. Unless you are comparing an object. But still...

  • 1

    I wanted to see everything in English on domains that are very local, and on teams that don’t have a deep grasp of English on the subject, which is very common. Native language helps define what is mechanism and what is domain. Not everything needs to be read naturally. And if it’s all in English it’s not always intuitive, it often creates a greater cognitive load. Although really our language is not the most suitable.

  • @ramaral, I agree, but usually the business terms are in Portuguese, there ends up mixing English with Portuguese inevitably, which also gets strange rs.

  • 1

    I usually use business and domain terms in Portuguese, but I don’t translate code conventions, so I always end up with things like getCPF or setNotaFiscal - there are those who argue that it should be pegaCPF or obtemCPF, But in this particular case, many Apis like JSF always look for getter and Setter automatically and it’s not worth translating these methods. Already business operations (fazIsso, processaAquilo) I think it’s best to use the terms the business uses to make things easier. I don’t think there’s a golden rule for that, and it should be examined case by case.

  • The @lazyFox comment is exactly the solution I used!

  • @lazyFox, they may be equal but both null. Hence the emphasis on existe :). But it’s just a specific example of the problem with And.

  • 1

    Correct, but now it depends on your method of comparison and whether there is a need to consider null

  • Relacionados: https://answall.com/questions/301/devo-escrever-meu-programa-em-ingl%C3%Aas-ou-portugu%C3%Aas

  • 1

    I also suffer a lot from this doubt. I usually try to change names like "first and second names" to things like "full names". But good question +1

Show 10 more comments

1 answer

12


First option: accepts that it hurts less :) If you have a pattern when you hit your eye in two uppercase cases, then one more being E He’ll turn it on soon enough, after some training.

You can also use some bad variations

isDatasExistemTambemIguais //Fica longo, mas aceitável
isDatasExistemTbIguais  //Menos legível, mas nada crítico
isDatasExistemE_Iguais //Foge do padrão normalmente usado, mas resolve
isDatasExistemAndIguais //Esquisito, mas válido, há precedente
isDatasIguaisSeExistirem  //Questão se interpretação
isDatasExistentesMasIguais //Mais para ter opções

You can make other combinations from these.

But how the E can be implied in some situations is easier to rewrite, I would stay with

TemDatasIguais

I put in the Github for future reference.

If there is not one or more dates implies that they are not equal. Of course if they don’t all exist, we can say they’re the same, but in a way they’re not even compared.

If there really can be a situation that concatenation needs to be explicit there would have to use some other word, or accept the oddity that is Casing.

I would use Eh or É in place of is. At first I think Casing is less important, and the accent helps to differentiate. See: Is there a problem using Unicode characters for code identifiers?.

  • 5

    "Aceita que dói menos" - The accurate summary of my philosophy after losing all the battles to write code in English in college projects.

  • 3

    @Maniero, I liked the answer. My objection only goes to the use of eh. This always reminds me of the vocabulary "miguxês" :P. Accent in code I honestly never saw and whenever someone forgot one in the code this was "condemned" by others, but I never wondered if this is really a problem or not. I believe that due to possible differences in IDE configuration between devs, it is best to avoid.

Browser other questions tagged

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