Skip to content

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

Merged
merged 1 commit into from
Mar 1, 2018

Conversation

kunicmarko20
Copy link
Contributor

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.

file_get_contents(__DIR__.'/src/Matthias/config/config.yml')
);
$config2 = Yaml::parse(
$configExtra = Yaml::parse(
Copy link
Contributor

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();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why that change?

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor Author

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?

Copy link
Contributor

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

@@ -41,7 +41,7 @@ your autoloader to load the Routing component::

$context = new RequestContext('/');
Copy link
Contributor

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

Copy link
Contributor Author

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();
Copy link
Contributor Author

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?

Copy link
Member

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

Copy link
Contributor

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().

Copy link
Member

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.)


$firewall = new Firewall($map, $dispatcher);
$firewall = new Firewall($map, $eventDispatcher);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$map => $firewallMap

@@ -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);
Copy link
Contributor Author

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?

Copy link
Member

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.

Copy link
Member

@javiereguiluz javiereguiluz left a 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 😓

@@ -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();
Copy link
Member

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.

Copy link
Contributor Author

@kunicmarko20 kunicmarko20 Feb 27, 2018

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();
Copy link
Member

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.

Copy link
Contributor Author

@kunicmarko20 kunicmarko20 Feb 27, 2018

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)

Copy link
Contributor

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(...);
Copy link
Member

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?

Copy link
Contributor Author

@kunicmarko20 kunicmarko20 Feb 27, 2018

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();
Copy link
Member

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.

Copy link
Contributor

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());
Copy link
Member

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.

Copy link
Contributor Author

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;
Copy link
Member

@javiereguiluz javiereguiluz Feb 27, 2018

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?

Copy link
Contributor Author

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);
Copy link
Member

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.

Copy link
Contributor Author

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?

@@ -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();
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, will be reverted.

@kunicmarko20
Copy link
Contributor Author

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.

@javiereguiluz
Copy link
Member

@kunicmarko20 sorry but that can't happen because only the Doc Team members have permission to merge.

@@ -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);
Copy link
Contributor

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

Copy link
Contributor Author

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?

Copy link
Contributor

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

@kunicmarko20 kunicmarko20 force-pushed the improve_naming branch 2 times, most recently from 7d1d5db to 14bb7b3 Compare February 27, 2018 18:52
@kunicmarko20
Copy link
Contributor Author

Some of the names have been updated according to comments, some are still waiting for a reply.

$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');
Copy link
Contributor

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

Copy link
Contributor Author

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.

Copy link
Contributor

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

Copy link
Contributor

@theofidry theofidry left a 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

@@ -534,7 +534,7 @@ tree with ``append()``::

public function addParametersNode()
{
$builder = new TreeBuilder();
$treeBuilder = new TreeBuilder();
$node = $builder->root('parameters');
Copy link
Contributor

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

Copy link
Contributor Author

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();
Copy link
Contributor

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();
Copy link
Contributor

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 :)

@@ -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)
Copy link
Contributor

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

Copy link
Contributor Author

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?

Copy link
Contributor

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();
Copy link
Contributor

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

Copy link
Contributor Author

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

Copy link
Contributor

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 :/

Copy link
Contributor

@adielcristo adielcristo Feb 27, 2018

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.

@kunicmarko20 kunicmarko20 force-pushed the improve_naming branch 2 times, most recently from 32ad701 to a6d8ad1 Compare February 27, 2018 21:08
@kunicmarko20
Copy link
Contributor Author

I renamed all $container to $containerBuilder where we have a new instance of ContainerBuilder the only place I left it as $container is in the examples that show the real code e.g. the Dependency Injection Extension

@javiereguiluz
Copy link
Member

@kunicmarko20 please tell me when you think this is ready so I can better prepare for merging this. Thanks!

@kunicmarko20
Copy link
Contributor Author

kunicmarko20 commented Feb 28, 2018

@javiereguiluz if there is nothing else that needs to be changed on my side, it is ready.

@javiereguiluz
Copy link
Member

Let's merge this. Wish me luck!

@javiereguiluz javiereguiluz added this to the 2.7 milestone Mar 1, 2018
@javiereguiluz javiereguiluz merged commit 219b7f8 into symfony:2.7 Mar 1, 2018
javiereguiluz added a commit that referenced this pull request Mar 1, 2018
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 kunicmarko20 deleted the improve_naming branch March 1, 2018 14:58
@javiereguiluz
Copy link
Member

@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 form/data_transformers.rst because there were some changes related to ObjectManager that I don't know if I merged them correctly.

@kunicmarko20
Copy link
Contributor Author

kunicmarko20 commented Mar 1, 2018

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?

@javiereguiluz
Copy link
Member

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 😓

@kunicmarko20
Copy link
Contributor Author

Ok, sorry for making you do this but it is worth it! 😄

javiereguiluz added a commit that referenced this pull request Mar 12, 2018
This PR was merged into the 2.8 branch.

Discussion
----------

Improve naming in documentation

Continuing the #9354, this time on branch 2.8, there weren't a lot of things that needed a change I guess the initial PR got almost everything 😄

Commits
-------

87d9046 improve naming
javiereguiluz added a commit that referenced this pull request Mar 13, 2018
This PR was merged into the 3.4 branch.

Discussion
----------

Improve naming in documentation

Continuing #9354, this time on branch 3.4.

Commits
-------

51ddf41 improve naming
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants