Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which coding style is more common?

In no way shape or form am i advertising/promoting my programming style, but as far as 'multiple variable declarations' are concerned, which case is more acceptable professionally and commonly:

case 1:

private $databaseURL   = "localhost"  ;
private $databaseUName = "root"       ;
private $databasePWord = ""           ;
private $databaseName  = "AirAlliance";

case 2:

private $databaseURL = "localhost";
private $databaseUName = "root";
private $databasePWord = "";
private $databaseName = "AirAlliance";

The reason i like case 1 is because i can skim though it and see that all is correct way faster than case 2. Also i can visually get familiar with variable names witch makes it faster to work with them l latter on the program.

like image 321
Babiker Avatar asked May 20 '26 14:05

Babiker


2 Answers

Whichever style the project is already using, so you don't end up spending all day fixing every file you touch.

like image 121
Joe Koberg Avatar answered May 23 '26 15:05

Joe Koberg


case 1.5:

private $databaseURL   = "localhost";
private $databaseUName = "root";
private $databasePWord = "";
private $databaseName  = "AirAlliance";

I don't think aligning the semicolons makes it any more readable, it just makes it annoying to change the value of one of the strings and then have to add or delete spaces to line up the semicolons all over again.

In this case, it looks like the variable names are unlikely to change, so it should be OK to line up the equals signs. If it were possible that the variable names would change, however, I would go with case 2 because (again) it would be annoying to have to line everything up again. (Imagine the work involved in simply adding a new variable called $databaseLongVariableName.)

like image 43
Paige Ruten Avatar answered May 23 '26 15:05

Paige Ruten