DEV Community

Cover image for Our way: Naming
Robson Tenório
Robson Tenório

Posted on

Our way: Naming

👉 Go to Summary

There is no wrong or right way, there is our way.

-- Someone

.
.
.

Naming is hard #1

WTF!?


$value = $this->getLoggedUser();

// ... after 50 lines of code you forget what `$value` is.

Enter fullscreen mode Exit fullscreen mode

Nice!

$user = $this->getLoggedUser();

// Ok, got it. It is `$user`
Enter fullscreen mode Exit fullscreen mode

.
.
.

Naming is hard #2

WTF!?

$user1 = User::where('name', 'Mary')->first();
$user2 = User::where('name', 'Joe')->first();

// 50 lines of code here ...

if ($user1->age > $user2->age) {

    // WTF are $user1 and $user2 ?
}


Enter fullscreen mode Exit fullscreen mode

Nice!

$mary = User::where('name', 'Mary')->first();
$joe = User::where('name', 'Joe')->first();

... // 50 lines of code here

if ($mary->age > $joe->age) {

    // Ok, Mary is older than Joe
}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)