laravel / ideas

Issues board used for Laravel internals discussions.
938 stars 28 forks source link

[Question] Why does artisan not have a make:facade command? #977

Open toto-jy opened 6 years ago

toto-jy commented 6 years ago

I'm trying to create a facade, and the internet appears to be full of conflicting guides. The Laravel documentation seems to prefer explaining internals rather than just giving a worked example from scratch.

It would greatly help people new to Laravel if they could simply type php artisan make:facade ExampleFacade and get everything they need right there — it seems a odd omission considering the number of other generators in Artisan.

Would it be possible for a facade generator to be added to Artisan?

626Pilot commented 6 years ago

That is a very good question. Give us make:facade.

m1guelpf commented 6 years ago

If I remember correctly, Taylor said there were too many generators, and that he wanted to do something about it, so adding another one isn't probably the best idea.

toto-jy commented 6 years ago

Isn't the point of generators to make things easy for someone using Laravel to develop software, though? The docs on creating a facade aren't clear enough for a developer new to Laravel to get a working facade, and searching the Internet produces a load of stuff that doesn't work, either because it's out-of-date or just doesn't explain things fully.

Someone in those circumstances wants to get boilerplate code that Just Works in place, not spend several days searching while their boss repeatedly yells "why isn't it working yet?" from behind them.

If there isn't going to be a generator, could the docs at least be improved so that there is a step-by-step guide to adding a new facade?

626Pilot commented 6 years ago

I'm guessing that Taylor's concern is that the Artisan command list is already very long, which makes it more difficult to scan than it would be otherwise. This is perfectly valid, as are arguments to the contrary. Therefore, let's step through the implications of not adding a 'make:facade' command.

Pro: Refrains from adding ~500 milliseconds to the amount of time it takes to read the already-long list of Artisan commands. (Assuming that people are scanning by category, and then alphabetically.)

Con: Compels new users to spend at least an hour (3,600,000 milliseconds) figuring out how to do the same thing.

I agree with the above comment. A lot of things about Laravel are inscrutable to people who don't already understand them. That's not just the case with facades, mind. It isn't as bad as some other projects (e.g. Chef), but there are nevertheless many cases in which the solutions found online are out-of-date, incomplete, or just don't work at all. There are video tutorials, but these are often the worst-case scenario as they involve a great deal of scanning to get to what you're looking for. (And, your boss might want to know why you're "watching YouTube instead of working." That means you have to explain things.)

An incredible amount of time and energy is spent on producing code and architecture that minimizes duplication of effort. Leaving that command out of Artisan demands duplication of effort. Truly, this question is raised: Is it better that one developer spend time adding this to Artisan, or that thousands of developers do identical research? Which is the astronomically more efficient of these two outcomes?

drbyte commented 6 years ago

The arguments "for" it are all reasonable. And particularly beneficial for newcomers or people just starting to use the facade feature more purposefully.

That said, I understand the reluctance to increase the already-too-long list of artisan commands.

However ...

There's nothing stopping someone from:

Each of these will get visibility and ranking, and readership, by virtue of their existence. And helps solve the problem.

But I do wonder if a mere generator is really enough? There's more to facades than just generating a file that brokers their use. Improving the docs, and publishing a blog article about "the many ways, and best practices for, using facades" would both be the most useful IMO.

michaeldyrynda commented 6 years ago

As @drbyte suggests above, creating a facade is more than just creating a file. You still have to bind the implementation the facade references to the container, which can't easily be done via a generator method.

In this particular instance, I don't think it makes sense to add a new make:facade command, but rather get the docs updated to more clearly explain how to create one.