Anni Maan Profile picture
Jan 23 24 tweets 7 min read
{1/24}

How to write a solidity code like a Professional?

This simplified style guide is intended to help Solidity programmers adhere to basic coding conventions. 🔥

Mega Thread 🧵

#100DaysOfCode #Solidity #web3 #blockchain #100Devs #techtwitter
{2/24}
Properly styled computer code is more easily read and understood by humans.

You may revisit the code you write later, or you may work on code with other people in the future. It’s important that your code is easily understood by yourself and others.
{3/24}
Consistency:

Code is read much more often than it is written. The guidelines provided here are intended to improve the readability of code and make it consistent across the wide spectrum of Solidity code.
{4/24}
Indentation:

Use 4 spaces per indentation level.

Tabs or Spaces:

Spaces are the preferred indentation method.
Mixing tabs and spaces should be avoided. Image
{5/24}

Within a contract surround function declarations with a single blank line.

Blank lines may be omitted between groups of related one-liners (such as stub functions for an abstract contract) Image
{6/24}

Maximum Line Length:

Keeping lines under the PEP 8 recommendation to a maximum of 79 (or 99) characters helps readers easily parse the code.

Wrapped lines should conform to the following guidelines.
{7/24}

1. The first argument should not be attached to the opening parenthesis.

2. One, and only one, indent should be used.

3. Each argument should fall on its own line.

4. The terminating element, ); , should be placed on the final line by itself. Image
{8/24}

Assignment Statements: Image
{9/24}

Event Definitions and Event Emitters: Image
{10/24}

Imports:

Import statements should always be placed at the top of the file. Image
11/24
Order of Functions
Ordering helps readers identify which functions they can call and find the constructor and fallback definitions easier.

Functions should be grouped according to their visibility and ordered:
constructor
fallback function
external
public
internal
private Image
{12/24}

Control Structures:

The braces denoting the body of a contract, library, functions, and structs should: 👇
{13/24}
- open on the same line as the declaration

- close on their own line at the same indentation level as the beginning of the declaration.

- The opening brace should be proceeded by a single space. Image
{14/24}

The same recommendations apply to the control structures if, else, while, and for.
{15/24}

Additionally, there should be a single space between the control structures if, while, and for and the parenthetic block representing the conditional, as well as a single space between the conditional parenthetic block and the opening brace.
{16/24}

Function Declaration:

For short function declarations, it is recommended for the opening brace of the function body to be kept on the same line as the function declaration.

The closing brace should be at the same indentation level as the function declaration. Image
{17/24}

You should explicitly label the visibility of all functions, including constructors. Image
{18/24}
The visibility modifier for a function should come before any custom modifiers. Image
{19/24}

In variable declarations, do not separate the keyword mapping from its type by a space.

Do not separate any nested mapping keyword from its type by whitespace. Image
{20/24}

Order of Layout:

Layout contract elements in the following order:

1. Pragma statements
2. Import statements
3. Interfaces
4. Libraries
5. Contracts
{21/24}
Inside each contract, library or interface, use the following order:

1. Type declarations
2. State variables
3. Events
4. Functions
{22/24}
Contract and Library Names:

Contracts and libraries should be named using the CapWords style.

Examples: SimpleToken, SmartBank, CertificateHashRepository, Player, Congress, Owned.

Contract and library names should also match their filenames.
{23/24}

If a contract file includes multiple contracts and/or libraries, then the filename should match the core contract.

This is not recommended, however, if it can be avoided. Image
{24/24}

Phew, that was a lot to consume. Let me know in the comment section below what were you doing wrong?

✅Follow for more content on Web3
✅Retweet the first tweet for better reach

Cheers🥂

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with Anni Maan

Anni Maan Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @Anni_Maan

Mar 29
The blockchain-based economy is no longer a dream, It may become reality soon!

Who wants to live on Satoshi Island? 🚀

A Thread 🧵 Image
The Vanuatu government announces its support for the Satoshi Island Community Project, a private crypto island where fiat isn't invited.

Satoshi Island is the megaproject crypto utopia in the South Pacific that recently disclosed to Cointelegraph its vision, progress.
Hot on the heels of news that they received 50,000 citizenship nonfungible token (NFT) applications, the prime minister of Vanuatu has given his blessing to “watching the development of Satoshi Island unfold.”
Read 6 tweets
Mar 25
Do you want to learn Solidity? 🚀

I have put together all the resources you need to start.

Thread 🧵
Read 13 tweets
Mar 24
COVID has changed my life in a positive way 🚀

I am working in an Investment as a Senior Mainframe developer.

Working from home gave me enough time to explore various tech stacks and I found my interest in Blockchain & WEB3.

Here is my story📒 👇
{2/13}
Being a Mainframe developer, I never thought, I would help people break into WEB3.

I joined Twitter last year in June 2021 asking for python resources.
{3/13}
In the last 8 months, I learned enough about Blockchain and WEB3.

I decided to create my own Blockchain from scratch for learning and learned a lot while working on this project.
Read 14 tweets
Mar 22
$2999 Worth Blockchain Courses for FREE 🚀

Both for JavaScript and Python developers

Blockchain & WEB 3.0 developers are highly paid across the globe.

✅Here is the complete UPDATED roadmap to becoming a Blockchain Developer.👇
Why Blockchain and Web3 developers are highly paid across the globe?

The reason is very simple, Huge demand and less supply.
If you want to work in WEB3 then learn javascript.

FREE javascript tutorial

scrimba.com
Read 16 tweets
Mar 9
All the resources you need to start with Blockchain and WEB3 🚀

Thread 🧵
Before starting with WEB3 you should really understand how Blockchain works and this quick course will help you.

codiesalert.com/courses/best-b…
If you want to learn how to create your own Blockchain from scratch, this course is for you.

codiesalert.com/courses/advanc…
Read 5 tweets
Mar 3
How does Blockchain work? 🤔

The best possible explanation you can imagine 🚀

You will feel comfortable enough to talk about Blockchain after watching these videos 👇

🧵Thread
Read 16 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Don't want to be a Premium member but still want to support us?

Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal

Or Donate anonymously using crypto!

Ethereum

0xfe58350B80634f60Fa6Dc149a72b4DFbc17D341E copy

Bitcoin

3ATGMxNzCUFzxpMCHL5sWSt4DVtS8UqXpi copy

Thank you for your support!

Follow Us on Twitter!

:(