This is likely a high point of contention - some people really enjoy a multi-word name for a function that basically describes the implementation in the method name (believe it or not, I've worked with some code with 40+ character names - I feel this is too lengthy).

Sample of a hard to read naming style (lets pick on PHP for a bit, as they've been pretty heavy into the Java-like naming conventions lately with Symfony etc.).

<?php // Assumes UserRepository is defined elsewhere. class UserService { protected $ userRepository ; public function __construct ( UserRepository $ userRepository ) { $ this -> userRepository = $ userRepository ; } public function getAllUsers () { $ users = $ this -> userRepository -> getAllUsers () ; return $ users ; } public function getUserByUserId ( int $ userId ) { $ users = $ this -> userRepository -> getUserByUserId ( $ userId ) ; return $ users ; } } // Now, calling into this would tend to look similar to this // in a controller method or something (or dependency injected via your // framework of choice). class UserController { public function getAllUsers () { $ userRepository = new UserRepository () ; $ userService = new UserService ( $ userRepository ) ; return $ userService -> getAllUsers () ; } public function getUserByUserId ( int $ userId ) { $ userRepository = new UserRepository () ; $ userService = new UserService ( $ userRepository ) ; return $ userService -> getUserByUserId ( $ userId ) ; } }

This isn't bad, in fact, I intentionally chose what looks like reasonable run of the mill enterprise code.

Yet, do you notice any fluff or value-less words here (words that, if when removed, do not alter what is being shown or communicated in anyway)?

Context is important, and if we really start thinking about the UserRepository, should it ever be returning any data that is not a user? ( hint _: probably not, it could go in a FooRepository if so).

Does saying:

$ userRepository -> getUserByUserId ( $ userId ) ;

offer any more clarity to the reader than simply saying:

$ repo -> getById ( $ id ) ;

In the scope of usage (UserService) the one and only repository is the user repository. The surrounding scope (UserService) has set the context for the code within ("user"), so any further mentions of "user" underneath this scope are fluff words (they do not add further refinement or clarity to what the reader is looking at).

What if we try again, while removing that fluff word (and shortening repository to repo)?

<?php // Assumes UserRepository is defined elsewhere. class UserService { protected $ repo ; public function __construct ( UserRepository $ repo ) { $ this -> repo = $ repo ; } public function getAll () { $ users = $ this -> repo -> getAll () ; return $ users ; } public function getById ( int $ id ) { $ users = $ this -> repo -> getById ( $ id ) ; return $ users ; } } // Now, calling into this would tend to look similar to this // in a controller method or something (or dependency injected via your // framework of choice). class UserController { public function getAll () { $ repo = new UserRepository () ; $ service = new UserService ( $ repo ) ; return $ service -> getAll () ; } public function getById ( int $ id ) { $ repo = new UserRepository () ; $ service = new UserService ( $ repo ) ; return $ service -> getById ( $ id ) ; } }

I think this second attempt just became more readable by quite a bit. Still, we can look into some common patterns used for naming methods/functions:

Prefix Meaning Sample get Retrieve something and give it back getAll() set Modify something that exists setName('Frank') make Create something (aka constructor) FooFactory::make() do Run some side effects doInit() persist Save something persistUser($user)

Anyways, you get the idea.

You can also (hopefully) see that many of our Repository calls are all describing the same default action ("get").

Calling a function and retrieving some value (I/O) tends to be the default operation of almost all function calls in all languages.

This lends itself well to omitting the "get" prefix entirely.

What would our class look like if we re-wrote it without the "get" prefix peppered all over the place?

<?php // Assumes UserRepository is defined elsewhere. class UserService { protected $ repo ; public function __construct ( UserRepository $ repo ) { $ this -> repo = $ repo ; } public function all () { $ users = $ this -> repo -> all () ; return $ users ; } public function byId ( int $ id ) { $ users = $ this -> repo -> byId ( $ id ) ; return $ users ; } } // Now, calling into this would tend to look similar to this // in a controller method or something (or dependency injected via your // framework of choice). class UserController { public function all () { $ repo = new UserRepository () ; $ service = new UserService ( $ repo ) ; return $ service -> all () ; } public function byId ( int $ id ) { $ repo = new UserRepository () ; $ service = new UserService ( $ repo ) ; return $ service -> byId ( $ id ) ; } }

If you read through the last sample, is it still "self documenting"? It surely is not being opaque about what is going on in either method as it trickles down from a controller, to a service, to a repository.