Newsletter Subject

SwiftUI: Declarative vs Imperative Programming

From

appcoda.com

Email Address

support@appcoda.com

Sent On

Thu, Oct 1, 2020 05:32 PM

Email Preheader Text

Hello, ​ This is one of the common questions about . Let me try to explain the difference betwe

Hello, ​ This is one of the common questions about [SwiftUI](=). Let me try to explain the difference between declarative and imperative programming in this email. ​ Like Java, C++, PHP, and C#, Swift is an imperative programming language since its release. SwiftUI, however, is proudly claimed as a declarative UI framework that lets developers create UI in a declarative way. What does the term “declarative” mean? How does it differ from imperative programming? Most importantly, how does this change affect the way you code? ​ If you go up to Wikipedia and search for the terms, you will find these definitions: In computer science, imperative programming is a programming paradigm that uses statements that change a program’s state. In much the same way that the imperative mood in natural languages expresses commands, an imperative program consists of commands for the computer to perform. In computer science, declarative programming is a programming paradigm—a style of building the structure and elements of computer programs—that expresses the logic of a computation without describing its control flow. ​ It’s pretty hard to understand the actual difference if you haven’t studied Computer Science. Let me explain the difference this way. ​ Instead of focusing on programming, let’s talk about cooking a pizza (or any dishes you like). Assuming you ask your helper to prepare a pizza, you can either do it imperatively or declaratively. To cook the pizza imperatively, you tell your helper each of the instructions clearly like a recipe: ​ - Heat the over to 550°F or higher for at least 30 minutes - Prepare one-pound of dough - Roll out the dough to make a 10-inch circle - Spoon the tomato sauce onto the center of the pizza and spread it out to the edges - Place the toppings (including onions, sliced mushrooms, pepperoni, cooked sausage, cooked bacon, diced peppers) and cheese - Bake the pizza for 5 minutes ​ On the other hand, if you cook it in a declarative way, you do not need to specify the step by step instructions but just describe how you would like the pizza cooked. Thick or thin crust? Pepperoni and bacon, or just a classic margherita with tomato sauce? 10-inch or 16-inch? The helper will figure out the rest and cook the pizza for you. ​ That’s the core difference between the term imperative and declarative. Now back to UI programming. Imperative UI programming requires developers to write detailed instructions to layout the UI and control its states. Conversely, declarative UI programming lets developers describe how the UI looks like and what you want to do when a state changes. ​ The declarative way of coding style would make the code more easier to read and understand. Most importantly, the SwiftUI framework allows you to write way less code to create a user interface. Say, for example, you are going to build a heart button in an app. This button should be positioned at the center of the screen and is able to detect touches. If a user taps the heart button, its color is changed from red to yellow. When a user taps and holds the heart, it scales up with an animation. ​ ​ ​ Take a look at the figure. That’s the code you need to implement the heart button. In around 20 lines of code, you create an interactive button with a scale animation. This is power of this declarative UI framework and SwiftUI. ​ If you are new to programming, you probably don’t need to care the difference because everything is new to you. However, if you have some experience in Object-oriented programming or developed with UIKit before, this paradigm shift affects how you think about building user interface. You may need to unlearn some old concepts and relearn the new ones. ​ In the next email, I will show you how to get started with SwiftUI if you still haven't tried it out. Should you have any questions, please hit Reply and write me back. ​ Regards, Simon ​ P.S. As a reminder, our special launch sale of our Mastering SwiftUI book ends on Oct 4. You can now use the discount code "swiftui2" at check to receive an extra discount. If you want to learn SwiftUI, [don't miss this opportunity to get the book](=). ​ ​ ​ ​ ​ ​ ​ ​[Unsubscribe]( | [Update your profile]( | Unit 1104, 11/F Crawford House, 70 Queen's Road Central, Hong Kong, n/a n/a

Marketing emails from appcoda.com

View More
Sent On

09/05/2024

Sent On

07/05/2024

Sent On

26/04/2024

Sent On

19/04/2024

Sent On

17/04/2024

Sent On

11/04/2024

Email Content Statistics

Subscribe Now

Subject Line Length

Data shows that subject lines with 6 to 10 words generated 21 percent higher open rate.

Subscribe Now

Average in this category

Subscribe Now

Number of Words

The more words in the content, the more time the user will need to spend reading. Get straight to the point with catchy short phrases and interesting photos and graphics.

Subscribe Now

Average in this category

Subscribe Now

Number of Images

More images or large images might cause the email to load slower. Aim for a balance of words and images.

Subscribe Now

Average in this category

Subscribe Now

Time to Read

Longer reading time requires more attention and patience from users. Aim for short phrases and catchy keywords.

Subscribe Now

Average in this category

Subscribe Now

Predicted open rate

Subscribe Now

Spam Score

Spam score is determined by a large number of checks performed on the content of the email. For the best delivery results, it is advised to lower your spam score as much as possible.

Subscribe Now

Flesch reading score

Flesch reading score measures how complex a text is. The lower the score, the more difficult the text is to read. The Flesch readability score uses the average length of your sentences (measured by the number of words) and the average number of syllables per word in an equation to calculate the reading ease. Text with a very high Flesch reading ease score (about 100) is straightforward and easy to read, with short sentences and no words of more than two syllables. Usually, a reading ease score of 60-70 is considered acceptable/normal for web copy.

Subscribe Now

Technologies

What powers this email? Every email we receive is parsed to determine the sending ESP and any additional email technologies used.

Subscribe Now

Email Size (not include images)

Font Used

No. Font Name
Subscribe Now

Copyright © 2019–2024 SimilarMail.