V
V
Victoria Erofeeva2020-05-16 20:02:23
PHP
Victoria Erofeeva, 2020-05-16 20:02:23

What is the best code format to use for working with Git?

Tell me which code format is better to use for working with Git, with tabs or spaces?

For the PSR-2 format, Code MUST use 4 spaces, and MUST NOT use tabs for indentation. https://github.com/getjump/fig-standards/blob/mast...

But it seemed to me that git is better with tabs, correct me if I'm wrong.
Below is an example of code, tell me how true it is in terms of the writing format.

{
private $first_name;
private $last_name;
private $age;
  
public function __construct($first_name, $last_name, $age)
{
    $this->first_name = $first_name;
    $this->last_name = $last_name;
    $this->age = $age;
}
 
public function getFirstName()
{
    return $this->first_name;
}
 
public function getLastName()
{
    return $this->last_name;
}
 
  public function getAge()
  {
    return $this->age;
  }
}

$objEmployee = new Employee('Bob', 'Smith', 30);
 echo $objEmployee->getFirstName(); // print 'Bob'
echo $objEmployee->getLastName(); // prints 'Smith'
echo $objEmployee->getAge(); // prints '30'<code lang="php">
</code>

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Anton Shamanov, 2020-05-16
@SilenceOfWinter

git don't care

V
Vladimir, 2020-05-16
@Casufi

For git it doesn't matter if it's tabs or spaces

A
Andrey Sobolev, 2020-05-17
@Sobolev5

If we are talking about team development, then it is better to agree on tabs and spaces. Better yet, use the same editor for everyone.
We had a bad experience of using Pspad, Atom and VsCode by different developers within the same project.
Git periodically refused to accept minor edits and put a conflict on the entire file.
Therefore, if you are planning team work, then you also need to decide on the editor that all your developers will use. It's in your best interest.
If you plan to develop "alone", then there is no difference at all. Write how you want and what you want.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question