[TYPO3-core] Suggestion about use statement

Stephan Schuler Stephan.Schuler at netlogix.de
Fri Feb 7 10:48:35 CET 2014


Hey there.


I pretty much dislike the "use" thing, so I'd rather remove it at all instead of introduce it everywhere.


In TYPO3 situations, you very often go like this:
> /** @var $foo \Foo\Bar\Domain\Service\SomService */
> $foo = $this->objectManager->get('Foo\\Bar\\Domain\\Service\\SomService');

So when adding a "use" here, you would now change it to this one:
> /** @var $foo SomeService */
> $foo = $this->objectManager->get('Foo\\Bar\\Domain\\Service\\SomService');

Well, that looks even more ugly imho.


And on top of that: There's a reason why we call a thing not just File or \File but \TYPO3\CMS\Extbase\Domain\Model\File.
It's not to have a complete description of something right inside of its class name. I's to have a chance to identify different things that both are "Files" in some ways. Current example is FAL. When dealing with FAL, you pretty often need to decide if it's a \TYPO3\CMS\Extbase\Domain\Model\File or a \TYPO3\CMS\Core\Resource\File -- and both have no common parent at all.

So what to do in those situations? Would you use "use" like that:
> use TYPO3\CMS\Extbase\Domain\Model;
> use TYPO3\CMS\Core\Resource;
> $foo = new Model\File;
> $bar = new Resource\File;

Besides the fact that it's unlikely to create two of those different files in a short distance (first: There is an API for that in the first place, second: You likely wouldn't create new ones like that, third: You would objectManager instead of new, but I would keep the quoted example code short), situations like that in general occur every now and then: Two classes with a common class name but different namespaces to be used in the very same file.

Ok, you could "rename" classes when calling "use". But that's not a good idea, too, because then you need to remember if the class is called File or ExtbaseFile or ModelFile in every single class.


I think using "use" doesn't give any benefit.

You want to know which classes you use in a file? For what? As an indicator for code quality? Hudson shouldn't count "use" but real class names if it's down to that.
Code can be understood better? When writing e.g. doc comments for properties or method arguments, I usually have more characters per line inside of my human readable sentences as the actual class names have. So I wouldn't call it an improvement.


If you decide to change that and introduce heavy usage of "use", I will get used to that. But I really would like to not need to.


Regards,


Stephan Schuler
Web-Entwickler

Telefon: +49 (911) 539909 - 0
E-Mail: Stephan.Schuler at netlogix.de
Website: media.netlogix.de



--------------------
Geben Sie Cyber-Kriminellen keine Chance
Lückenloser Schutz mit Security-Lösungen von Sophos: Erfahren Sie, wie Sie Ihr Unternehmen wirksam schützen und gewinnen Sie einen Boomball Pro Mini-Lautsprecher:
https://www.cyber-gesindel-a.de/netlogix
--------------------



--
netlogix GmbH & Co. KG
IT-Services | IT-Training | Media
Neuwieder Straße 10 | 90411 Nürnberg
Telefon: +49 (911) 539909 - 0 | Fax: +49 (911) 539909 - 99
E-Mail: info at netlogix.de | Internet: http://www.netlogix.de

netlogix GmbH & Co. KG ist eingetragen am Amtsgericht Nürnberg (HRA 13338)
Persönlich haftende Gesellschafterin: netlogix Verwaltungs GmbH (HRB 20634)
Umsatzsteuer-Identifikationsnummer: DE 233472254
Geschäftsführer: Stefan Buchta, Matthias Schmidt



-----Ursprüngliche Nachricht-----
Von: typo3-team-core-bounces at lists.typo3.org [mailto:typo3-team-core-bounces at lists.typo3.org] Im Auftrag von Philipp Gampe
Gesendet: Freitag, 7. Februar 2014 00:49
An: typo3-team-core at lists.typo3.org
Betreff: Re: [TYPO3-core] Suggestion about use statement

Hi Markus,

Markus Klein wrote:

> Therefore I propose to use the 'use' EVERYWHERE and ALWAYS in ALL
> branches.
>
> e.g. 'use' a class already when it's first used
>
> This has the following benefits for us:
> - One can see all used classes being used in one file already at the
> top of the file - No troubles on backports anymore, because we have it
> in all branches - Much shorter and thereby readable code
> - PHPStorm and other IDEs automatically take care of the 'use'
> statement when using a class

+1 I would have asked the very same in the next active contributor meetup.

Most classes only use very few other classes. IMHO, a large number of use statements shows a design flaw in the following code. The class is concerned with too much.

I would also prefer the nice summery of class usage that is generated with the use statements. It would be far more consistent than the current sometimes and sometimes not.

Best regards
--
Philipp Gampe – PGP-Key 0AD96065 – TYPO3 UG Bonn/Köln Documentation – Active contributor TYPO3 CMS
TYPO3 .... inspiring people to share!

_______________________________________________
Before posting to this list, please have a look to the posting rules on the following websites:

http://typo3.org/teams/core/core-mailinglist-rules/
http://typo3.org/development/bug-fixing/diff-and-patch/
_______________________________________________
TYPO3-team-core mailing list
TYPO3-team-core at lists.typo3.org
http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-team-core


More information about the TYPO3-team-core mailing list