avatarAldric Chen

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

3786

Abstract

arison operators, and bitwise operators on this type too.</p><p id="c4da">It’s important to note that there is another type, called <code>bytes</code> which is different from the above in that it is a dynamically sized array, and not a value type but a reference type. It is basically shorthand for <code>byte[]</code>.</p><p id="ad39">When you can limit the length of your data to a predefined amount of bytes, it is always good practice to use some of <code>bytes1</code> to <code>bytes32</code> because it is much cheaper.</p><h2 id="0118">Enums</h2><p id="aea7"><b>Enums</b> in Solidity are a way to create user-defined types. Enums are explicitly convertible to integer types, but not implicitly. Enum values are numbered in the order they are defined, starting from 0.</p><p id="ed00">Enums are not part of the ABI (Application Binary Interface — more on this in a later lesson, but it’s basically how you encode Solidity code for the Ethereum Virtual Machine, and how you get data back). This means that if your function returns an <code>enum</code> for example, it will be automatically converted to a <code>uint8</code> behind the scenes. The integer returned is just large enough to hold all enum values. With more values, the size gets increased too (<code>uint16</code> and up).</p><p id="cdb6">The below code, taken from the <a href="https://docs.soliditylang.org/en/v0.4.24/index.html">Solidity docs</a>, defines an enum with four possible values, creates a variable of that enum named <code>choice</code> and a constant called <code>defaultChoice</code>that will hold a default value.</p><div id="cf29"><pre><span class="hljs-keyword">enum</span> <span class="hljs-title class_">ActionChoices</span> { GoLeft, GoRight, GoStraight, SitStill } ActionChoices choice; ActionChoices <span class="hljs-type">constant</span> <span class="hljs-variable">defaultChoice</span> <span class="hljs-operator">=</span> ActionChoices.GoStraight;</pre></div><p id="66a9">Now we can define some functions to interact with our <code>enum</code>.</p><div id="c0bb"><pre><span class="hljs-title function_"><span class="hljs-keyword">function</span> <span class="hljs-title">setGoStraight</span></span>() <span class="hljs-keyword">public</span> { choice = ActionChoices.GoStraight; }

<span class="hljs-title function_"><span class="hljs-keyword">function</span> <span class="hljs-title">setChoice</span></span>(ActionChoices <span class="hljs-keyword">new</span><span class="hljs-type">Choice</span>) <span class="hljs-keyword">public</span> { choice = <span class="hljs-keyword">new</span><span class="hljs-type">Choice</span>; }</pre></div><p id="6bc2">The first one simply sets the <code>choice</code> to <code>GoStraight</code> while the second one sets it to the choice that the caller passes into the function. As we can see after deployment, the <code>setChoice</code> function expects a <code>uint8</code> value, which corresponds to the <code>enum</code> value declared at that number.</p><figure id="e997"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*1pKNPVy4UUBCSLi2-SIckg.png"><figcaption>Testing enums in Remix</figcaption></figure><p id="7917">If we want to get the value of <code>choice</code> and <code>defaultChoice</code>, we can define the following functions:</p><div id="1f02"><pre><span class="hljs-keyword">function</span> <span class="hljs-title">getChoice</span>() public view returns (ActionChoices) { <span class="hljs-keyword">return</span> <span class="hljs-type">choice</span>; }</pre></div><div id="43e7"><pre><span class="hljs-function">function <span class="hljs-title">getDefaultChoice</span>() <span class="hljs-keyword">public</span> pure <span class="hljs-title">returns</span> (<span class="hljs-params"><span class=

Options

"hljs-built_in">uint</span></span>)</span> { <span class="hljs-keyword">return</span> <span class="hljs-built_in">uint</span>(defaultChoice); }</pre></div><p id="c2f2">As we can see if we try this out in Remix, the first function returns a <code>uint8</code> while the second returns a <code>uint256</code>.</p><figure id="e514"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*jmaOFb9GhXz7FWC4ONMa_A.png"><figcaption>Testing enums in Remix</figcaption></figure><h2 id="3c7c">Fixed point numbers</h2><p id="2ecc"><b>Fixed point numbers </b>represent fractional numbers by storing a fixed number of digits of their fractional part. No matter how large or small the fractional part is, it will always use the same number of bits.</p><p id="cdcd" type="7">Fixed point numbers are not fully supported by Solidity yet. They can be declared, but cannot be assigned to or from.</p><p id="f872">We can differentiate between signed fixed point numbers, declared with the <code>fixed</code> keyword, and unsigned fixed point numbers, declared with the <code>ufixed</code> keyword.</p><p id="3c1c">It can also be declared as <code>fixedMxN</code> or <code>ufixedMxN</code> where <code>M</code> represents the number of bits the type takes, and <code>N</code> represents the number of decimal points. <code>M</code> has to be divisible by 8 and a number between 8 and 256. <code>N</code> has to be a number between 0 and 80.</p><p id="96e1">They function with the following operators:</p><ul><li>Comparisons: <code><=</code>, <code><</code>, <code>==</code>, <code>!=</code>, <code>>=</code>, <code>></code> (evaluate to <code>bool</code>)</li><li>Arithmetic operators: <code>+</code>, <code>-</code>, unary <code>-</code>, unary <code>+</code>, <code>*</code>, <code>/</code>, <code>%</code> (remainder)</li></ul><h2 id="09b7">Conclusion</h2><p id="bd3a">In this lesson, we looked at what value types are available in Solidity and how each one works.</p><p id="28de">Thank you for staying with us till the end. If you enjoyed reading this piece please keep in touch and follow Solidify to keep up with our lessons on Solidity. In the upcoming articles, we will deep dive into the intricacies of the language, progressing from beginner to advanced level.</p><p id="067c">If you are new to Solidity, check out the previous lessons about setting up a local development environment and writing your first smart contract.</p><div id="6b76" class="link-block"> <a href="https://readmedium.com/how-to-setup-your-local-solidity-development-environment-c4c8195810f3"> <div> <div> <h2>How to Setup Your Local Solidity Development Environment</h2> <div><h3>Get started with smart contract development</h3></div> <div><p>medium.com</p></div> </div> <div> <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/1*HHko-o9m1sVngmTeRVYgKA.jpeg)"></div> </div> </div> </a> </div><div id="3ad1" class="link-block"> <a href="https://readmedium.com/lesson-1-your-first-solidity-smart-contract-1ba7e641f9a3"> <div> <div> <h2>Lesson 1: Your First Solidity Smart Contract</h2> <div><h3>In the previous lesson, we looked at how to set up your local Solidity development environment. Here we will continue…</h3></div> <div><p>medium.com</p></div> </div> <div> <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/1*7r7HSYkbn73NrmR_skvh5w.jpeg)"></div> </div> </div> </a> </div></article></body>

How The World Got Destroyed By A Winning Tortoise.

The Tortoise. The Hare. A World Destroyed.

Photo by Chan Swan on Unsplash

I don’t like this story after reading it for the first time. Mind you, that was during my toddler years. Somehow, many things felt wrong. Then, I couldn’t point my fingers to those spots. Heck, I don’t even understand what it means to point at something.

I had a truckload of questions that couldn’t be articulated because of my light-weight vocabulary bank. Thinking back, I think I got severely suffocated. I might have thrown that book on the floor. Maybe my Mum was upset with me. My Aunt could be proud of me. My Dad could be wondering if the Tortoise or the Hare offended me.

As Fate would have it, this story was brought up during a Livestream that I co-founded. A fellow co-founder asked me for my opinion on this story. A deep-frozen memory etched at a corner of my mind thawed almost immediately. I went on to express my doubts and disdain for 6 minutes.

However, it didn’t feel as if I have completed my thought processes during the live show. I wanted to understand what is wrong with me. Maybe I needed to understand if there is anything wrong with the story. The children’s book has been left collecting dust on the floor for decades. It is time to pick it up again.

This time, with a discerning eye.

I read it once. I didn’t understand the story. I read it twice. I read from behind. I read the book blurb. I read online reviews. I just didn’t understand what that story serves to deliver. These are my questions: -

  • Why is there a race between a Hare and Tortoise?
  • What is the impact on the World when the unexpected happens?
  • Did anyone in the Forest sense anything wrong?

I found no answers so I decided to create mine. It is time to make it a real story. A real story of the Tortoise and the Hare. A classic re-written.

It was a hot day in Central Square in the Forest. Summer has arrived and temperatures have been steadily increasing into the 30 Degrees Celsius range within days of summer. Every Forest Citizen was out and queuing to buy their favourite ice-cream. Mrs. Parrot’s Ice-Cream parlor has been greeted with snake-line queues every morning.

Of course, when the waiting lines got longer, waiting times got longer, days got hotter — Impatience started to rear its ugly head. This could be seen in Mr. Hare’s behaviour.

“Mr. Tortoise! You are too slow! Can’t you move faster? You are delaying everyone queueing behind you!”. It was a hot day. It was so scorching hot that almost everyone’s temper got shorter as the Sun is working harder than before. The rising temperatures are chewing away everybody’s patience. This is especially so for those who don’t have any. Like Mr. Hare.

“Hurry up, Mr. TORTOISE!”

Mr. Tortoise is known for his patience and wisdom. Today, the heat got into him. He lost to Gaia. He broke his patience bank and erupted back. “ENOUGH! Do you think you are very fast? What is the big deal? I will beat you in your own game if I want to!”

Mr. Hare was surprised but not for long. He retorted. “Oh yeah? Let’s do it tomorrow!”

“So be it. And you better shut your mouth after the race!”.

Mr. Tortoise then stormed away as quickly as he could. With his rapidly melting triple chocolate cone.

The race proceeded and the results shock the entire forest.

“Gosh, we have a new speed master!” said Beaver the elder.

“This is unimaginable!” Ms. Lemur proclaimed.

While the entire forest celebrated Mr. Tortoise’s win, one of them was doubtful.

“Mr. Hare lost? Something is amiss.”

Mr. Cheetah was calm. He wanted to speak to Mr. Hare but his friend was nowhere to be found. Perhaps he needed time and space to reflect. He might need to calm down. Not too long later Mr. Cheetah heard an announcement by the Forest Head, Mr. Elephant.

“We have a new Forest Messenger from today! From today on, Mr. Tortoise will be responsible to inform us of any upcoming natural or man-made disasters. Congratulations, Mr. Tortoise!”

Mr. Cheetah watched in silence as Mr. Tortoise received the Messenger badge from the Forest Head. His head held high. He basked himself into the cheers of the Forest. Everyone was happy that the impossible could happen. Just not the worldly-wise Mr. Cheetah.

“Something bad is about to happen. This is wrong. So wrong. I have to find Mr. Hare quickly.”

And so Mr. Cheetah left the Central Square in search of his running mate. One week later, a forest fire broke out at the Forest’s Far East. The Skunk standing guard at the surveillance tower caught sight of the dense smoke and received news of heavy winds for that day.

“This is bad news!”, he screamed as he let off a series of stomach gas. He abandoned the surveillance tower and sped to Mr. Tortoise’s abode at West Pond, just 2 miles where the tower was. He wet his pants as he tried to reach Mr. Tortoise.

“WHERE IS HE!?”

Mr. Skunk has been knocking on the door for an hour.

Finally, there was a response.

“ …. Yes …. “

“Mr. Tortoise! There is a fire in the Far East and is moving at an accelerating speed towards Central Square. You have to rush there and inform everyone now!!”

“But … but … it takes me 2 days to get to Central Square from here …!”

“Sir! You are our speed master and only hope! You have to run now!! Do what you do best!”

The Skunk expired after relaying his message. He ran his best marathon ever in his lifetime.

[This is my tribute to Phidippides]

Mr. Tortoise knew this was a matter of Life and Death. He set off for Central Square almost immediately. He moved as quickly as he possibly could. As he edged towards Central Square, he saw fellow animals running towards him. Scalded and ruffled.

Photo by Cedric Fox on Unsplash

“Where are you, Mr. Tortoise? Many need help behind us. We managed to escape because we are those who can run fast”, said Ms. Bunny.

“PLEASE HURRY!!”, Ms. Bunny shouted at the top of her lungs as the sound of forest fire consuming the woods was covering all possible voices.

“WHY DIDN’T YOU COME TO INFORM US, MR. TORTOISE? WHERE WERE YOU?!”, screamed Mrs. Zebra as she continued running with her kids behind her.

“Oh no. Oh no. WHAT HAVE I DONE? WHAT HAVE I DONE? My friends, please wait for me!”

As if it wasn’t meant to be, a stampede in front became visible to Mr. Tortoise. It became clear to Mr. Tortoise that Mr. Ox’s entire family was ahead. It was also clear to him that he has no chance of running ahead of them when they are charging at full force. Mr. Tortoise stepped aside. As the stampede pass him by, Mr. Tortoise could hear angry comments made on the fly.

Mrs. Ox: Why didn’t the Forest Messenger come to inform us? Mr. Hare never failed us!

Mr. Ox: Times have changed. We have a new Forest Messenger now.

Mrs. Ox: Regardless, they should have performed their duties!

Mr. Ox: Our family comes first. Quit whining and get our calves to run faster.

Mr. Tortoise teared by the side of the road. There was nothing he could do except giving way to the stampede of the herd. He knew this wasn’t the time to incur the wrath of Mr. Ox. Mr. Tortoise wiped his tears as he inched forward in a hurry towards Central Square.

As he approached the Central Square, the forest fire has done its job and the entire Town has been blazed to the ground. Mr. Tortoise dropped to his knees.

“No, no. Please don’t do this to me!”

He walked around and teared as he found his friends, one by one, without any sign of life. And then … he saw Mr. Hare amongst the victims. He was protecting Mrs. Ostrich’s youngest girl with all his body. He was completely burned and has perished in the line of duty that wasn’t his.

“Mr. Hare. No, not you. Please!!”

Mr. Cheetah just rushed back from the nearest tribe. He came back to the village after seeking help from the nearest tribe. He was panting hard. He witnessed a devastated Mr. Tortoise who was at his personal peak just one week ago. Mr. Cheetah could see a despondent Mr. Tortoise through his casted shadows. Mr. Cheetah stepped ahead to comfort his friend.

“Mr. Tortoise, don’t be too upset. When the fire broke out in the Far East, Mr. Hare sensed that something was amiss through his instincts and ran to me for help. He then ran straight into the fire to inform every one who was in deep slumber and attempted to rescue as many as he could, as quickly as he could.”

Photo by Wolfgang Hasselmann on Unsplash

Mr. Tortoise broke down.

“Although Mr. Hare knew that he was no longer the Forest Messenger, he responded to the natural call of duty. He died where he should be. He used his natural running ability to save everyone. We should be proud of him.”

Mr. Tortoise cried.

“I am so dumb, so wrong. I lived in the delusion that I am the fastest runner. The forest perished because of me.”

[I wanted to write that he performed harakiri but I decided to spare him.]

Mr. Tortoise walked towards the breathless Mr. Hare.

“You are the Hero of the Forest. You truly deserve this.”

He removed the Forest Messenger badge and pinned it on Mr. Hare. It was too late. Mr. Hare was no longer alive to accept the offer.

Mr. Tortoise won the race. He lost the entire Forest.

Mr. Hare lost the race. He lost his life.

No one won anything.

It was a tragedy, the way Mr. Cheetah believed right after that fateful race when Mr. Tortoise shouldn’t have won.

A Personal Sharing and Takeaway.

This would be my updated version, an attempt to fill in the holes of the story. It could be an immature extension of the original, and I would say that the original version is incomplete as well. Now, with the above, I want to explore these questions.

  • What is the purpose of this story?
  • Are there any damaging ramifications from this story?

I will attempt to answer both questions in tandem. I think this is a story of encouragement especially in a World that is dominated by alpha-males. Or even extroverts. Therefore, it is important for those who are not to believe that they can contribute in their own unique ways. The World is big enough for all of us.

For many of us who believed in this story — The takeaway is almost universal. It has to do with many permutations of the same core message and that is: -

“Slow and Steady Wins the Race.”

But we have to understand the fundamental mechanics of life. In the context of a race — No one wins by being slow. A race is designed to reward those who worked hard accomplishing what is required in the shortest time possible.

That said, no one says we have to race or we should race when we don’t want to. That said — A race is a race. No Olympian Gold Medallist got crowned being the slowest or by being last in the league. The strongest message in this story is warped in my opinion and should be self-destructible within 5 minutes of consumption.

Then at this point — We have to reflect deeply on ourselves.

Who are those in power who could get the “Slow and Steady” to participate in a race?

And what is “the race” that is unavoidable in Life? In fact, so presumably undesirable yet unavoidable?

I leave these questions open for the readers. From my perspective, the answers to these questions became crystal clear when I looked at my parents. It became even clearer when my youngest cousin is studying hard for her life as she is constantly pressured by her parents to excel in school.

Is the Tortoise and the Hare just a story?

I doubt.

They are everywhere.

And this is my parting note. I am always skeptical when a particular character becomes God-Like. When someone becomes God, there will be a particular target within the story who will be demonised. We have to ask ourselves what the intention of the writer is.

For me, it is simple.

The Hare has been demonised. I want to make him a Hare again.

Cheers, Aldric

Related Stories from the Author.

About the Author:

As a Consultant by training, I believe in making the complex simple.

Because simplicity adds value.

Simplicity helps us gain clarity, and clarity helps us to grow.

And if we are not growing, then what’s the point of anything else?

This is more about me as a Content Contributor on Medium.

Do reach out and say hi on Linkedin!

Storytelling
Thinking
Self Improvement
Reflections
Life Lessons
Recommended from ReadMedium