00:00:06.540
Hello everyone. My name is Enrique, and I work for a company called Salesforce. I'm a software engineer there.
00:00:10.080
My team is called Trailhead, and we are the learning platform for Salesforce. So, if you want to learn how to use Salesforce, you can just go to Trailhead and learn from there.
00:00:23.800
Today, I want to tell you a story. The story begins with 'Once upon a time, in a country far away, maybe called Rubynia, maybe not.' There was a king who really liked to look at the moon.
00:00:34.540
This country was a modern society where trains were really fast and arrived on time. Some people even claimed that there were magic trains because they were so quick. Elevators also ran on time. However, for all the automation and benefits it brought, there was a problem with the moon.
00:01:10.600
The moon, of course, was written in Ruby and ran from the cloud. The problem was that, sometimes, it was unpredictable. It would come up on the earth at times, and sometimes, you couldn't see it at all. Occasionally, it might rise in the West, and at other times, it would even hide behind the Sun.
00:01:23.729
One night, the king was trying to look at the moon, but after waiting and waiting, he couldn't see it. He was very sad and fell ill. The next morning, the royal doctor called all the king's family.
00:01:58.750
When the family arrived, the first one to show up was Elizabeth, who everyone calls Ellie. Elizabeth was a junior developer who was just starting to get into Ruby. She said, 'Hey uncle, I'm here! How can I help you?'
00:02:19.360
The king replied, 'Please help me fix the moon!' Ellie hesitated and said, 'But I'm just a junior developer. Can you ask anyone else?' The king insisted, 'Of course I can ask anyone. I'm the king! But I want you to fix it.'
00:02:50.620
So, Ellie went ahead and started fixing the moon. She created a plan for the solar system and began looking at the code. However, she couldn’t find a moon class or file for the moon, so she started amplifying her search.
00:03:12.030
Eventually, she found a demo file for the moon, where she could see the gem with the descriptions of the moon's properties. She started wondering how these properties became a class that interacts with the real world, so she examined where the gamma files were being used and came across the code for the star factory.
00:03:48.449
The code essentially organized the data from all the jumbo files for all the stars. After gathering all the stars, it would create one class per star. However, when she began to investigate and find the issue regarding the moon, she discovered a method called 'visibility_from_earth.' This method was a complicated calculation that essentially tells you where you should see the moon from Earth.
00:05:22.860
For simplification, the visibility_from_earth method was defined such that it calculated the earth's position multiplied by the moon's orbit. Now, she thought to find the real issue by searching for the orbit method for the moon.
00:06:04.470
However, she faced another problem: the method was defined dynamically, meaning there was no static orbit method for the moon. This led her to dive deeper into her investigation.
00:06:18.360
As she continued her exploration, she discovered a star finder that finds the Sun. To define the orbit of the moon, they needed to use the gravitational field of the Sun, incorporating escape velocity for the moon.
00:06:45.970
Despite her efforts, she couldn't figure out the underlying issue causing the moon's unpredictable behavior. Following the standard investigative practices, she looked at the code to identify the last person who interacted with it, which turned out to be the Metaprogramming Minister of Magic.
00:07:50.420
Ellie went into the office of the Minister, where multiple screens displayed code, graphs, and system performance. The Minister, being a wise developer, helped design the solar system and wrote code to test the train system, ensuring the trains ran on time.
00:08:23.450
She asked the Minister, 'Can we create a new class for the moon? I'm having trouble fixing it, and I'd like your advice.' The Minister replied, 'I don't think that's a good idea. Maybe just tweak a few parameters and see what happens.'
00:09:01.020
But Ellie insisted, 'The problem isn't in the parameters; I believe it's an issue with the actual method.' The Minister countered, 'The code has been running for a while without errors. If that were true, the king wouldn't be ill.' In the end, the Minister suggested Ellie consult with the Object Oriented General.
00:09:54.600
So, Ellie left the Minister's office and went into the office of the Object Oriented General. Her office was filled with computers, laptops, drones, and even a spaceship. The Object Oriented General was a very important developer in the kingdom, having designed the first automated system for jumping.
00:10:49.890
Ellie said, 'The king sent me, and I'm here to solve the problem with the moon.' As they started discussing the issue, Ellie explained her problems. The Object Oriented General shared the benefits of object-oriented programming, explaining how to translate the rules of the world into a computer using building blocks.
00:11:38.220
She suggested that they could create a very simple version of the moon class, focusing on the method visibility_from_earth and its interaction with orbit. Their goal was to create a simpler system that would allow them to track the moon's position. They discussed how to find the bug and check the Jama file for definitions of gravitational versus rotational forces.
00:12:51.030
They realized that not just the Sun, but also the Earth would affect the moon's behavior. The Object Oriented General emphasized that they needed to complete the class while also defining a method to calculate the orbit that considers both gravitational forces.
00:13:56.700
As they worked together, the General suggested they consult with the Royal Functional Mathematician to aid in calculating the moon's orbit, at which point Ellie made her way to the Mathematician's office, a pristine white room with one screen and a whiteboard.
00:15:14.430
The Mathematician welcomed her and showed her notes about the moon's orbit. Ellie shared her concerns about the moon’s visibility and the need for a method to explore the moon's changes over time. They realized they would need to consider time as a parameter in the equations they were calculating.
00:16:57.080
After a long investigation, they clarified that the moon didn't have static coordinates, but was in constant motion which they would handle with a mathematical function to approximate its behavior. They defined the orbit method to return a Proc that could accept time as a parameter.
00:18:00.200
Once they set the parameters for other celestial bodies affecting the moon, their code became easier to understand and modify. The Royal Functional Mathematician then told Ellie that her new task was to extract the orbit method into a separate class since other stars also had orbits.
00:19:10.460
Ellie realized that separating unique methods into their own classes was a crucial step. Consequently, she completed her work, ran the tests, and even received approval from the Metaprogramming Minister, ultimately deploying the code.
00:20:03.520
As she deployed the code, thoughts of metaprogramming came to mind. This approach would allow building abstractions and frameworks efficiently, leading to fewer problems when specializing or modifying existing objects.
00:20:42.290
Once completed, she rushed to see the king, who was standing at the window. He expressed his gratitude: 'Thank you for fixing the moon! You've brought order to the kingdom and happiness to my heart.' Yet, he pondered, 'Why must I wait 28 days to see the full moon?' That, my friends, is a story for another time.