What record looks more aesthetically pleasing if the goal is a beautiful code?

Such

$user = $this->userName . implode("-", $this->birthDate); 

Such

 $user = $this->userName; $user .= implode("-", $this->birthDate); 

Or so

 $user = $this->userName; $birth = implode("-", $this->birthDate); $user .= $birth; 

The example is written from the bald, so do not judge strictly. In fact, I’m wondering only one thing - is it permissible to push functions into concatenation, or is it clearer when only variables are "concatenated". I myself tend to the first option.

It is closed due to the fact that it is necessary to reformulate the question so that it is possible to give an objectively correct answer by the participants aleksandr barakin , D-side , user194374, Vartlok , fori1ton Apr 5 '16 at 14:19 .

The question gives rise to endless debates and discussions based not on knowledge, but on opinions. To get an answer, rephrase your question so that it can be given an unambiguously correct answer, or delete the question altogether. If the question can be reformulated according to the rules set out in the certificate , edit it .

  • one
    Do you only consider these options? there are a lot of others, including exotic ones) - BOPOH
  • No, not only. Any suit me. Just to be clear to those who will read this code)) - qtm

1 answer 1

Subjectively, I like the first option, since it has one line and it fits into 80 characters (that is, it satisfies the PSR-2 standard). The third option is not bad, you allocate $ birth into a separate variable, however, it seems to me that $ this-> birthDate in implode () and so gives enough information that this is about birth dates. Rejection or desire to remake none of the options did not cause.

  • 3
    So it seems to me that it makes no sense to produce lines where you can fit one in 80 characters. But there are situations when you need to pack more values ​​into a string than here. In such cases, it is better to use the third? - qtm
  • For more complex assembly lines, you can use $user = sprintf('%s %s', $this->userName, implode("-", $this->birthDate)); - Sergiks
  • It is possible and the second, usually resorted to the third option, when you have a complex business logic and intermediate results are not entirely obvious. In this case, you can enter a variable with a good name and save a lot of time parsing the code. - cheops
  • Well, since all three options have the right to life, then I am calm sprintf() Thank you for sprintf() . I have not come across it yet. I will try on occasion. - qtm