Skip to content
This repository has been archived by the owner on Sep 9, 2019. It is now read-only.

Application::t() is too long #4

Closed
gagatust opened this issue Jul 23, 2018 · 11 comments
Closed

Application::t() is too long #4

gagatust opened this issue Jul 23, 2018 · 11 comments

Comments

@gagatust
Copy link
Contributor

See https://github.com/yiisoft/core/commit/c6e0e031d419881d1c02d4894155e94516da1a26
Application::t() is too long than Yii::t().This method is often used. What about App::t()?

@hiqsol
Copy link
Member

hiqsol commented Jul 23, 2018

Please note it's not static.
To be used: $this->app->t(...)
And Yii::t() is not removed.

@gagatust
Copy link
Contributor Author

gagatust commented Jul 23, 2018

Which is better to use $this->app->t() or Yii::t() and why?

@SilverFire
Copy link
Member

The main point is "destatification" inside the framework core. While static methods can serve as good shortcuts for faster code composing, they encourage developers to rely on global application state, that is usually not a good thing. You don't like to use $_GLOBALS variable, right?

There are some posts [1], [2] that explain problem a bit wider.

@gagatust
Copy link
Contributor Author

Do you plan to remove Yii::t()?

@hiqsol
Copy link
Member

hiqsol commented Jul 23, 2018

Not now. And only after having very good alternative(s).

@hiqsol
Copy link
Member

hiqsol commented Jul 23, 2018

At the moment we are only trying to clean up the framework core.

@tecnoterabyte
Copy link
Contributor

Excelent "destatification" helpers also.

@sdlins
Copy link
Contributor

sdlins commented Aug 1, 2018

Hi guys!

About the "destatification", as I was reading the pointed articles, I tended to discord of them. I think it could be just "over-engineering" to simple situations. When I got to the end of the article, many comments came with strong variated contrary arguments (like this).

I think the "Yeah, it is" could be lost if Yii3 "dificult" some simple things. And helpers are this: simple things. They have no state. They dont change states. They are simple functions.

It would be great to hear really "strong" arguments to remove (or substitute) static helpers, because I read the pointed articles and I could not find them (nor the most of the commenters). Hope to hear you here... thank you.

@gagatust
Copy link
Contributor Author

gagatust commented Aug 2, 2018

@slinstj I think the problem is that Yii::t() is not pure function. Yii:t() behavior depends on settings. We can change the settings at any time and change the behavior.

@hiqsol
Copy link
Member

hiqsol commented Aug 2, 2018

@slinstj
First of all Yii::t() is not about to be removed.
But things are being cleaned up.

$this->app->t() will be used in the framework where possible.
And we recommend to use it this way.

It is more "clean" because Yii::t() is not actually simple static stateless function, it just hides from you that some global Application and I18N objects are used behind the scene.
Getting $this->app with constructor DI and then calling $this->app->t() makes everything explicit hopefully without making troubles. But you are free to choose :)

I'm trying to bring modern approaches and more "clean" OOP while keeping "Yes, it is" style and soul.

P.S.
Finishing Yii 3.0 changes description. It will be available soon.

@sdlins
Copy link
Contributor

sdlins commented Aug 8, 2018

Thank you @gagatust and @hiqsol.

I meant in my comment (maybe I had not been clear) was about remove "all" utilities/helpers for the sake of "destatification". This is what I think that would be "over-engineering". But in the answers I see this doesn't seem to be the intention. 👍

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants