تماشای این درس نیاز به اشتراک حرفه‌ای دارد.

Why Magic Is Frowned0:00

Hey there, we explored some of the Laravel magic. Now let's talk about why magic is frowned upon in the software engineering community. And the main reason I would say is that it confuses those who haven't written the code. If you took on a project that was written a few years ago by some developer you don't know, you would wish the developer had followed a common set of principles and conventions so it's easier for you to navigate the codebase and understand how it works and what it does. But when a new developer looks at a Laravel codebase, they will get confused with all the magic. So they look at a method and they ask, where is this method coming from? I can't find it in the caller class.

Facades and Static Confusion0:44

So they look at a method and they ask, where is this method coming from? I can't find it in the caller class. What is this static class? Is it a facade? What's a facade? I don't understand what's a facade. Is it the facade pattern? I don't know. Why are we calling static methods on that facade? I can't find any of these static methods inside the class.

Eloquent Hidden Properties1:00

Why are we calling static methods on that facade? I can't find any of these static methods inside the class. And if, for example, someone is not familiar with Laravel's Eloquent models, they will wonder where the properties are coming from. Like, I see an Order class, but I can't find a vendorId attribute defined on that class. Where is it coming from? Then, they get that the properties are declared and assigned behind the scenes by reading from the database. Then, they find another property that doesn't match any of the database columns and is not defined on the class.

Accessors Add More Confusion1:29

Then, they find another property that doesn't match any of the database columns and is not defined on the class. What is it? They will wonder. Where is it coming from? And then, they realize it's a model accessor. All this confusion frustrates programmers, especially those with years of experience like senior programmers and staff engineers and principal engineers. These guys, they want to look at a code and instantly figure out what it does and be able to introduce changes as needed.

Magic Tradeoffs for Devs2:29

There is plenty of Laravel developers in the market who know about the magic and can easily navigate through the code page without confusion. I think many of us Laravel developers use the magic ourselves and have been doing that for years. So, it's nothing new for us. In my opinion, magic is a problem for a seasoned developer who is switching to Laravel. He hasn't used Laravel before. They will struggle for a bit before they can wrap their mind around the magic and can navigate it. That's the price to pay for enhanced developer experience.

دوست دارید گاهی خبرهای Laracasts را ایمیل کنیم؟