-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Improve naming in documentation #9354
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
components/config/definition.rst
Outdated
file_get_contents(__DIR__.'/src/Matthias/config/config.yml') | ||
); | ||
$config2 = Yaml::parse( | ||
$configExtra = Yaml::parse( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about $extraConfig
?
@@ -493,14 +493,14 @@ for these resources and use them as metadata for the cache:: | |||
$containerConfigCache = new ConfigCache($file, $isDebug); | |||
|
|||
if (!$containerConfigCache->isFresh()) { | |||
$containerBuilder = new ContainerBuilder(); | |||
$container = new ContainerBuilder(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why that change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Becuase almost whole docs use $container
and even https://github.com/symfony/dependency-injection/blob/master/Extension/Extension.php#L80 it is named as $container
, no need to mix it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I disagree here. This is one of those cases where variable naming is extremely important. A container builder is not a container, so the variable name is wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So then $container
in Extension is wrong also?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, it should be $containerBuilder
as well
components/routing.rst
Outdated
@@ -41,7 +41,7 @@ your autoloader to load the Routing component:: | |||
|
|||
$context = new RequestContext('/'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here would be $requestContext too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I started renaming context
to requestContext
but then I saw context
is used everywhere, not sure if I should rename all or revert this one.
@@ -287,10 +287,10 @@ do the following: | |||
// app/config/routing.php | |||
use Symfony\Component\Routing\RouteCollection; | |||
|
|||
$collection = new RouteCollection(); | |||
$collection->addCollection($loader->import("@AcmeHelloBundle/Resources/config/routing.php")); | |||
$routes = new RouteCollection(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some of the docs use $routes
and some use $collection
for RouteCollection
, I thought that $routes
sounded better but maybe $routeCollection
is the best option? Any suggestion on this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like $routes
more than $collection
and $routeCollection
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although I like $routes more, in the examples below the calls to $route->addCollection()
and $route->setHost()
make more sense as $routeCollection->addCollection()
and $routeCollection->setHost()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I disagree :) $routes->addCollection()
is easy to understand to me (just add a collection of routes to the existing routes) whereas $routeCollection->addCollection()
is complicated (I'm replacing the existing collection? I'm merging two collections or creating a new collection? Is the result a route collection or a collection of route collections? etc.)
components/security/firewall.rst
Outdated
|
||
$firewall = new Firewall($map, $dispatcher); | ||
$firewall = new Firewall($map, $eventDispatcher); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$map
=> $firewallMap
console/style.rst
Outdated
@@ -67,8 +67,8 @@ title of the command:: | |||
|
|||
protected function execute(InputInterface $input, OutputInterface $output) | |||
{ | |||
$io = new SymfonyStyle($input, $output); | |||
$io->title('Lorem Ipsum Dolor Sit Amet'); | |||
$inputOutput = new SymfonyStyle($input, $output); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not really like this one but it is better than $io
, maybe $symfonyStyle
if that makes sense?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's better to keep $io
because we use it everywhere in the docs, the code, the Symfony Demo app, etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In other circumstances we'd say "closing because this is a merging nightmare". But I'm a big fan of good variable names, so I'll make the tedious merging and suffer the consequences 😓
components/console/events.rst
Outdated
@@ -14,10 +14,10 @@ the wheel, it uses the Symfony EventDispatcher component to do the work:: | |||
use Symfony\Component\Console\Application; | |||
use Symfony\Component\EventDispatcher\EventDispatcher; | |||
|
|||
$dispatcher = new EventDispatcher(); | |||
$eventDispatcher = new EventDispatcher(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure about this one because in Symfony there's only one thing that can be a dispatcher: an event dispatcher.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't sure about this one but then I saw there are some places that it was already named $eventDispatcher
$em = $this->getDoctrine()->getManager(); | ||
$em->persist($post); | ||
$em->flush(); | ||
$entityManager = $this->getDoctrine()->getManager(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure about this one because $em
is pretty well known in the Symfony community and the alternative ($entityManager) is super long.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is one of the reasons I started this PR 😄 I think this should be renamed and we should not continue to suggest abbreviations. (Also I found places where it already was $entityManager
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@javiereguiluz I've personally never been a big fan of $em
and I also think most people that are familiar with $em
won't get lost by having $entityManager
instead
@@ -36,8 +36,8 @@ in the object using the constructor:: | |||
use Symfony\Component\ExpressionLanguage\ExpressionLanguage; | |||
use Acme\ExpressionLanguage\ParserCache\MyDatabaseParserCache; | |||
|
|||
$cache = new MyDatabaseParserCache(...); | |||
$language = new ExpressionLanguage($cache); | |||
$databaseCacheParser = new MyDatabaseParserCache(...); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This name looks wrong: it's not "a parser of db caches" but "a cache of db parser", right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hm, I think you are right when I look at it one more time, maybe $databaseParserCache
?
@@ -66,11 +66,11 @@ The main class of the component is | |||
|
|||
use Symfony\Component\ExpressionLanguage\ExpressionLanguage; | |||
|
|||
$language = new ExpressionLanguage(); | |||
$expressionLanguage = new ExpressionLanguage(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like either the original $language nor the new $expressionLanguage. Neither of them tells me what is this. But I guess the new name is better than the old one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At least we are calling an apple an apple here :)
@@ -45,8 +45,8 @@ Example usage:: | |||
use Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage; | |||
use Symfony\Component\HttpFoundation\Session\Storage\Handler\NativeFileSessionHandler; | |||
|
|||
$storage = new NativeSessionStorage(array(), new NativeFileSessionHandler()); | |||
$session = new Session($storage); | |||
$nativeSessionStorage = new NativeSessionStorage(array(), new NativeFileSessionHandler()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would rename it to $sessionStorage
because "native" or not is just an implementation detail that can change at any moment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree.
@@ -121,10 +121,10 @@ on a "remember-me" cookie, or even authenticated anonymously? | |||
use Symfony\Component\Security\Core\Authentication\Token\AnonymousToken; | |||
use Symfony\Component\Security\Core\Authentication\Token\RememberMeToken; | |||
|
|||
$anonymousClass = AnonymousToken::class; | |||
$rememberMeClass = RememberMeToken::class; | |||
$anonymousToken = AnonymousToken::class; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These should be $anonymousTokenClass
and $rememberMeTokenClass
because they are classes, not tokens. Or better yet: why don't we remove these useless variables and moved their values to the class constructor?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought about that but the point of PR is better naming? I saw some places where I could just move the values but I did not know if it would be appropriate for this PR?
@@ -46,10 +46,10 @@ create the catalog that will be returned:: | |||
} | |||
} | |||
|
|||
$catalogue = new MessageCatalogue($locale); | |||
$catalogue->add($messages, $domain); | |||
$messageCatalogue = new MessageCatalogue($locale); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just wondering: if later we replace $catalogue by $translations ... maybe here we can replace $messageCatalogue by $translation? Maybe is not a good idea.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure really, the other place was importing the translations I thought that it was appropriate to rename it like that and here we are working with $messageCatalogue
, I can change it but I am not sure?
console/command_in_controller.rst
Outdated
@@ -50,11 +50,11 @@ Run this command from inside your controller via:: | |||
)); | |||
|
|||
// You can use NullOutput() if you don't need the output | |||
$output = new BufferedOutput(); | |||
$application->run($input, $output); | |||
$bufferedOutput = new BufferedOutput(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I disagree with this renaming. The fact that the output is buffered is just an implementation detail that can change at any time. The important thing is that this is a console output, so $output
looks OK to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree, will be reverted.
Is there any chance that I can help with merging when the time comes? I wouldn't mind doing it and I really want to see this one get merged. |
@kunicmarko20 sorry but that can't happen because only the Doc Team members have permission to merge. |
console/style.rst
Outdated
@@ -67,8 +67,8 @@ title of the command:: | |||
|
|||
protected function execute(InputInterface $input, OutputInterface $output) | |||
{ | |||
$io = new SymfonyStyle($input, $output); | |||
$io->title('Lorem Ipsum Dolor Sit Amet'); | |||
$inputOutput = new SymfonyStyle($input, $output); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$ioHelper would be more descriptive
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like it, but Javier said:
I think it's better to keep $io because we use it everywhere in the docs, the code, the Symfony Demo app, etc
tbh I did not find $io
anywhere else, I will check again tonight. @javiereguiluz what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Frankly it's one of the rare cases where I prefer the short name because it's such a common name even outside of Symfony. $inputOutput
is very verbose and a bit confusing with $intput
, $output
next to it. I could settle with $ioHelper
though
7d1d5db
to
14bb7b3
Compare
Some of the names have been updated according to comments, some are still waiting for a reply. |
bundles/configuration.rst
Outdated
$def = $container->getDefinition('acme.social.twitter_client'); | ||
$def->replaceArgument(0, $config['twitter']['client_id']); | ||
$def->replaceArgument(1, $config['twitter']['client_secret']); | ||
$twitterClient = $container->getDefinition('acme.social.twitter_client'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$twitterClientDefinition
. I remember getting confused the first time I came across definitions because of a similar naming as it was named as if it was the service but was not the service
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would rather revert it to $definition
I saw some places where that name is used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
true, unless there is multiple ones you might not care about a better naming
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Big 👍 it's a nice work! I think those kind of naming is very important for new comers especially and quite a few terms there were source of confusion
components/config/definition.rst
Outdated
@@ -534,7 +534,7 @@ tree with ``append()``:: | |||
|
|||
public function addParametersNode() | |||
{ | |||
$builder = new TreeBuilder(); | |||
$treeBuilder = new TreeBuilder(); | |||
$node = $builder->root('parameters'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing renaming here as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice catch.
@@ -493,14 +493,14 @@ for these resources and use them as metadata for the cache:: | |||
$containerConfigCache = new ConfigCache($file, $isDebug); | |||
|
|||
if (!$containerConfigCache->isFresh()) { | |||
$containerBuilder = new ContainerBuilder(); | |||
$container = new ContainerBuilder(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, it should be $containerBuilder
as well
@@ -66,11 +66,11 @@ The main class of the component is | |||
|
|||
use Symfony\Component\ExpressionLanguage\ExpressionLanguage; | |||
|
|||
$language = new ExpressionLanguage(); | |||
$expressionLanguage = new ExpressionLanguage(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At least we are calling an apple an apple here :)
components/finder.rst
Outdated
@@ -176,12 +176,12 @@ Sort the result by name or by type (directories first, then files):: | |||
|
|||
You can also define your own sorting algorithm with ``sort()`` method:: | |||
|
|||
$sort = function (\SplFileInfo $a, \SplFileInfo $b) | |||
$sortFunction = function (\SplFileInfo $a, \SplFileInfo $b) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not a big fan of this one. $sort
describes that it is, I don't think you need the type in the name. When you have $x = ['name 1', 'name 2']
an appropriate name for $x
would be $names
not $stringNames
unless special circumstances where the type marks the difference
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, what about maybe moving it directly into ->sort()
instead of assigning it to a variable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would personally do it directly yeah unless there is more of such functions and ends up making it hard to read. Otherwise I think the naming ($sort
) is perfectly correct. I'll leave @javiereguiluz make the call there :)
$sc = new DependencyInjection\ContainerBuilder(); | ||
$sc->register('context', Routing\RequestContext::class); | ||
$sc->register('matcher', Routing\Matcher\UrlMatcher::class) | ||
$container = new DependencyInjection\ContainerBuilder(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$containerBuilder
. I would review the usage of $container
elsewhere as ContainerBuilder
is very different from $container
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree but then we come back here https://github.com/symfony/dependency-injection/blob/master/Extension/Extension.php#L80 where the type is ContainerBuilder
and name is container
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO that should be changed and it's very confusing :/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a little confused. I thought that ContainerBuilder (besides the misleading name) would be a Container too, as it extends from Container.
32ad701
to
a6d8ad1
Compare
I renamed all |
a6d8ad1
to
219b7f8
Compare
@kunicmarko20 please tell me when you think this is ready so I can better prepare for merging this. Thanks! |
@javiereguiluz if there is nothing else that needs to be changed on my side, it is ready. |
Let's merge this. Wish me luck! |
This PR was merged into the 2.7 branch. Discussion ---------- Improve naming in documentation As the title says, I am trying to improve the naming of variables and some functions in the documentation. This started as just removing the abbreviations but while I needed to go through all files I tried to improve naming of everything that made sense to me. Commits ------- 219b7f8 improve naming
@kunicmarko20 the merge has been completed up to master branch. the idea would be to now do the same for 2.8 branch, then I merge up. Then for 3.4 branch and merge up, 4.0 and merge up and finally, master. But I understand if you are tired :) By the way, when you get to 3.4 please double check |
Thank you for doing this. So I would need to do the same check for those 3 branches but create PR after the merge of previous? 2.8 -> 3.4 -> 4.0? |
That's correct. If you can, the next step would be to fix 2.8 variable names (in reality, you are only fixing the wrongly variable names that didn't exist in 2.7) and then I'll merge things up again. Later, we repeat for 3.4, 4.0 and master 😓 |
Ok, sorry for making you do this but it is worth it! 😄 |
As the title says, I am trying to improve the naming of variables and some functions in the documentation. This started as just removing the abbreviations but while I needed to go through all files I tried to improve naming of everything that made sense to me.