-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #48 from Graur/44
added new blog post about $ object
- Loading branch information
Showing
1 changed file
with
88 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
--- | ||
layout: post | ||
date: 2023-11-15 | ||
title: "$ Object" | ||
author: graur | ||
--- | ||
|
||
In the world of EO programming, the `$` object acting as a syntax sugar that refers to the current abstract object it is used in. | ||
This seemingly simple yet powerful feature provides programmers with an elegant way to manipulate and access objects within their code, | ||
ultimately enhancing readability and ease of use. | ||
In this blog post, we will dive deep into the concept of the `$` object and shed light on its practical applications through illustrative examples. | ||
|
||
<!--more--> | ||
|
||
### Understanding the $ Object | ||
Upon encountering the `$` symbol in EO code, it is important to recognize its true significance. | ||
The `$` object essentially serves as a reference to the abstract object within which it is utilized. | ||
By leveraging this syntax sugar, developers can harness the power of the current object without explicitly referring to it by name. | ||
This concise and intuitive approach enhances code clarity and conciseness, leading to more efficient and maintainable codebases. | ||
|
||
### An Example | ||
Let's examine a code snippet to better understand how the `$` object functions within the EO programming language: | ||
|
||
``` | ||
[] > foo | ||
assert-that > @ | ||
2.plus 2 | ||
$.equal-to 4 | ||
``` | ||
|
||
In this example, we define an abstract object named `foo`. Within the `assert-that` scope, we pass as the parameter to it `2.plus 2` object | ||
and the second object's matcher, then verify whether it is equal to `4`, using the `$` object as a reference. | ||
Upon initial inspection, the code may seem a bit puzzling. However, we can break it down to reveal its true meaning: | ||
|
||
1. Firstly, `$` refers to nearest abstract object `foo`: | ||
``` | ||
[] > foo | ||
assert-that > @ | ||
2.plus 2 | ||
foo.equal-to 4 | ||
``` | ||
But `foo` object does not have `equal-to` object. So, EO compiler needs to find an object that has `equal-to` object. | ||
|
||
|
||
2. Secondly, EO compiler tries to get `foo.@` and take `equal-to` from there: | ||
``` | ||
[] > foo | ||
assert-that > @ | ||
2.plus 2 | ||
foo.@.equal-to 4 | ||
``` | ||
|
||
|
||
3. Finally, the compiler finds `equal-to` object in `assert-that` object and takes it from there: | ||
``` | ||
[] > foo | ||
assert-that > @ | ||
2.plus 2 | ||
assert-that.equal-to 4 | ||
``` | ||
By using `$` as a reference, we can directly access the `assert-that` object while within the `foo` scope. | ||
Here is the example of the `assert-that` object for better understanding: | ||
|
||
``` | ||
[actual matcher] > assert-that | ||
... | ||
[expected] > equal-to | ||
actual.eq expected > @ | ||
``` | ||
|
||
### Practical Applications of the $ Object | ||
Undoubtedly, the `$` object's syntax sugar provides programmers with a clean and expressive way to work with objects. | ||
The following scenarios highlight its practical applications: | ||
1. Chaining Methods: | ||
By utilizing the `$` object, we can succinctly chain methods together, simplifying complex operations. | ||
This leads to more readable and concise code, enhancing collaboration among team members and reducing the chances of introducing bugs. | ||
2. Context Independence: | ||
The `$` object allows developers to maintain the context of their code while reducing the need for lengthy and repetitive object references. | ||
It facilitates writing clean and modular code that is easier to understand and maintain. | ||
|
||
### Conclusion | ||
In conclusion, the `$` object serves as a vital syntax sugar in the EO programming language, offering developers an elegant way to refer to the current | ||
abstract object within their code. | ||
By leveraging this feature, programmers can enhance the readability and conciseness of their code, ultimately improving collaboration and productivity. | ||
Understanding the true meaning behind the `$` object allows developers to unlock its full potential and leverage it in various scenarios, | ||
from method chaining to context independence. | ||
|
||
So, embrace the `$` object and embrace the power of EO programming! |