avatarMassùod Hemmat

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>

7 Essential Writing Lessons from Stephen King’s Million-copy Bestseller

These points might change your mind about writing.

Photo Credit: Wikimedia Commons

Renowned author Stephen King has published “at least 90 novels, more than 200 short stories,” and a few non-fiction books — “selling 350 million copies.

In his million-copy bestseller “On Writing: A Memoir of the Craft,” King provides valuable lessons for aspiring writers. I found the following seven essential lessons which might help you become a good writer.

1. Don’t worry about “grammatical correctness”

Myth: My grammar has to be perfect.

“Language does not always have to wear a tie and lace-up shoes.” -Stephen King

Whether you write fiction, or non-fiction, an academic paper, or a business letter, a journalistic piece, or an informal memo, you should not underestimate the importance of grammar. Poor grammar can change the meaning of a sentence — it’s also bad for your reputation. Although grammar is essential, getting obsessed with perfect grammar isn’t.

If you don’t write for fear of “grammatical correctness,” it might undermine your confidence to become an aspiring or a good writer. Instead, focus on simple sentences, as King writes: “…all those simple sentences worked for Hemingway [] Even when he was drunk…” Hemingway won Pulitzer Prize for Fiction and Noble Prize in 1953 and 1954, respectively.

Grammar shouldn’t hinder your passion for writing, but do not confuse it with punctuation. Bill Murphy Jr., Inc’s contributing editor, writes about crucial punctuation mistakes:

2. Don’t try to sound more knowledgeable than you are

Myth: If I use big words, people might think I am knowledgeable.

“One of the really bad things you can do to your writing is to dress up the vocabulary, looking for long words because you’re maybe a little bit ashamed of your short ones. This is like dressing up a household pet in evening clothes.” -Stephen King

If you use big words to sound more knowledgeable, stop it now — especially after you come across those words when you prepare for the SAT, MAT, GRE, GMAT, TOEFL, and IELTS tests or any other standardized ones. If you come across those big words in that last novel you read or that “jargon” business book you order for $2 or that scientific paper you read online, you shouldn’t use them in your next writing. It’s better to have simplicity in writing, mainly when it is for a general audience. It might be okay for a specific audience, though.

Let’s have a look at these two examples to help you understand this.

a) At no time, set out to sound more erudite than you eminently are.

b) Don’t try to sound more knowledgeable than you really are.

Which one is easier to understand for a typical reader? You decide!

Your ego as a writer is not as important as the readers’ ego. As Negin Safdari writes in her piece: “Good writers write for their ego, great writers write for yours.”

Photo Credit: Hannah Olinger on Unsplash

3. Three things are bad for your writing: Adverbs, the Passive voice, & long paragraphs

Myth: a) Adverbs add power to the sentence. b) We have to use active and passive voices equally. c) A longer paragraph means I can get into the tiny details.

“The road to hell is paved with Adverbs.” -Stephen King

“Easy books contain lots of short paragraphs …” -Stephen King

“Two pages of the passive voice — just about any business document ever written,… make me want to scream.” -Stephen King

I remember writing my first essay back in 2009 — thinking it might be “a piece of gold” as I put much effort into it. I got this piece of advice from my instructor: “Your writing is not bad, but it’s flowery, and the paragraphs are so long.” I couldn’t change that style of writing in a matter of weeks or months — until I read King’s book.

Let’s have a look at these sentences:

a) I was advised by my instructor that adverbs are not necessarily needed in my writing — as they are actually very bad for the quality of my writing.

b) My instructor told me not to use many adverbs.

See how I changed the passive voice to active, shortened the sentence, and omitted the adverbs. King suggests that we need to use fewer adverbs, write passive free, and be concise.

The passive voice is not terrible for writing. It “is not grammatically incorrect, and you are not ‘wrong’ if you use it.” It’s just that the active voice delivers the message much better.

If you want to identify any parts of speech in your writing, use this website:

A Screenshot of the Website (the tool is also available in German, French, and Spanish)

4. Read more than you write; Write more than you read

— Myth: Good reading is not a prerequisite for good writing or vice versa.

“If you want to be a writer, you must do two things above all others: read a lot and write a lot.” -Stephen King

I read a lot — not only to get to know things but also to improve my writing skills. That’s how King’s advice on reading and writing helped me. One comes across the various forms of writing through reading. If your business writing is above-average, it doesn’t mean you are good at other forms of writing, namely creative, academic, or journalistic. You not only need to think outside the box of “writing has only one form” but also get rid of that box. Make it a habit to read from crosscutting sources to get to know multiple forms and styles of writing.

If you think you have to read more to learn or write better, you also need to write more to write better. Sounds puzzling? — but you need to write more to make use of those readings. It’s like you learn in theory but never apply it in real life.

If you don’t write, you never know what needs to improve. For this reason, reading and writing are equally important — but some might argue that reading comes first. You have to read first to be able to write, as “Good writers make Good readers.”

For me, writing is like slow-thinking, and reading is like fast-thinking. I learn more about writing from writing than from reading.

Photo Credit: Anete Lūsiņa on Unsplash

5. Edit and rewrite

— Myth: If I can write it in a single sitting, why should I edit or even rewrite it?

“To write is human, to edit is divine.” -Stephen King

If you procrastinate until the deadline, or if you think writing is about write-it-all-in-one-sitting just like this jargon word — you are NOT RIGHT.

Writing is not about one-sitting. Things before and after writing are essential. You might be in the kitchen washing the dishes and remember a shred of supporting evidence for your topic sentence or a neat example for your article. That’s when you need to jot down the idea. Otherwise, you will not have it when you sit and write.

I had to rewrite this article. I edited the sentences many times, including this one. I didn’t want to sound like a person who writes a book on “How to Earn Money,” but at the end of the day, he or she doesn’t have the money to publish it.

Photo by Thought Catalog on Unsplash

6. Appreciate or ignore criticisms, and avoid self-doubt

— Myth: I don’t want anyone to criticize my writing.

“I’m convinced that fear is at the root of most bad writing.” -Stephen King

Writing is a complicated work of art. Just as an artist paints like no other artist, a writer also writes like no other writer. The same way our thumbprints do not match, our writing styles also do not match. If you just wrote your first essay, your fifth article, your seventh story, your third book, or your second volume, don’t let critics stop you — keep going. Seek perfection, but who has attained it yet?

Follow the basic writing rules and view criticism as a way to improve your advanced writing skills. Any form of criticism from others often leads to self-doubt. It’s self-doubt that makes us stop doing things.

Not only yourself but also others will doubt you. Don’t compare your chapter 3 with someone else’s chapter 5, or your page 62 to someone else’s page 301.

Photo Credit: Lilian Dibbern on Unsplash

7. Write only about things you know

— Myth: I can write about anything as my writing is above average or excellent.

“Write what you know.” -Stephen King

Consider this: Can a Software Engineer with no prior knowledge or experience of astronomy write about it at all? Yes, of course — but he or she shouldn’t do it. He or she can write about hundreds of things in software engineering and related fields.

You might broaden your knowledge by reading more — not by writing about the things you never heard of or had any prior expertise. We should not underestimate the role of passion, but it doesn’t play any part if you are not knowledgeable about what you write. How is that plausible to write on something you have no clue?

Make sure you have some expertise in playing the piano if you want to write on “How to Play Piano?” Your writing skills might be excellent, but that doesn’t add value to the readers who might want to learn to play the piano — especially when you want them to learn based on your writing.

A good writer is knowledgeable and passionate about what he or she writes — and might also have above-average writing skills.

If you haven't read King’s On Writing yet, read it. Maybe you uncover several other lessons that might help you and other writers.

Photo Credit: Joe Pescoran on Unsplash
Writing
Self Improvement
Advice
Books
Articles
Recommended from ReadMedium