

Explain Meta Programming Like I'm Five
source link: https://dev.to/codehakase/explain-meta-programming-like-im-five-j6c
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

What it is, it's benefits, where it comes to play.
Discussion (5)
In short, meta programming is writing code that writes code. Or, in other words, imagine a robot that can not only build other robots, but also rebuild and modify itself.
CollapseExpand
Bob is 5 years old. (developer)
Bob have to draw a sunny house. (new feature)
Now imagine that Bob write "Sunny house" on a drawing sheet (comment or whatever used for meta programming).
He push THE magical button of the pencil (compile code or interpret it).
TADA ! There's now a sunny house, despite he didn't draw it, he asked to his magic stick to make it and the sunny house is done (the feature).
Bob is now 25.
He have to create a new URL. The controller have to use /blog/blog_id url, be seen as "blog_list" and the blog_id MUST BE a digital, any digital. There must be an error if the page id don't meet the requirement.
Bob use Symfony, write an annotation of one line and the job is done.
(Symfony core processed to write the code.)
Here's a real example :class BlogController extends Controller
{
/**
* @Route("/blog/{page}", name="blog_list", requirements={"page"="\d+"})
*/
public function list($page)
{
// ...
}
}
Thanks for this example, super helpful
CollapseExpand
If programming were a story in a book, metaproprogramming would be a story in a book that tells you how to write stories. Or for the 5 year old that lives 10 years from now, metaprogramming is like a 3D printer that allows you to also 3D print other 3D printers.
Thanks for your response Alain!
Recommend
-
34
No Comments Introduction Ten years ago there was a major shift in the field of network appli...
-
11
Explain Service Principal Like I'm Five #explainlikeimfive
-
7
Explain a State Machine Like I'm Five #explainlikeimfive D...
-
19
-
9
Explain dependency injection like I'm five Sep 14, 2017 ・1 min read ...
-
13
Discussion (21) CollapseExpandDocker images: think of them as blueprints, for example a blueprint for creating a cow. Docker daemon: think of it as corral for letting the cows run wild. Docker swarm (an...
-
13
Discussion (19) CollapseExpand You have a agreement with your best friend that she'll help with your math homework when you're...
-
5
Explain Serverless Like I'm Five #explainlikeimfive Dec 17...
-
7
Explain React State & Props Like I'm Five Mar 22, 2020 ・1 min read ...
-
10
Discussion (13) CollapseExpandGreat question! This one really got me thinking, here it goes. For your upcoming birthday, you ask your parents to buy you a Lego 1989 Batmobile. The day finally arrives, and...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK