Session 1 Intro and Data Types
Session 1 Intro and Data Types
Main topics:
• Intro to programming
• Intro to dart language
• Data types in Dart
Intro to programming
- What is Programming?
In a simple answer, “Programming is the act of instructing
computers to carry out tasks.” It is often referred to as coding.
So then, what is a computer program? A computer program is a
sequence of instructions that the computer executes.
Computer in the definition above is any device that is capable of
processing code. This could be smartphones, ATMs,
Conditioners, Traffic lights, Servers to name a few.
- So, the two important terms that we have used in the above
definition are:
• Sequence of instructions
• Computer Programming Language
Now, try to map the situation with a computer program. The above
sequence of instructions is actually a Human Program written in
English Language, which instructs on how to reach KFC from a
given starting point. This same sequence could have been given in
Spanish, German, Arabic, or any other human language, provided
the person seeking direction knows any of these languages.
Now, let's go back and try to understand a computer program,
which is a sequence of instructions written in a Computer
Language to perform a specified task by the computer. Following is
a simple program written in Dart programming Language --
The above computer program instructs the computer to print
"Hello,World!" on the computer screen.
A computer program is also called a computer software, which
can range from two lines to millions of lines of instructions.
Computer program instructions are also called program source
code and computer programming is also called program coding.
A computer without a computer program is just a dump box; it is
programs that make computers active.
- Algorithm
From programming point of view, an algorithm is a step-by-step
procedure to resolve any problem.
An algorithm is an effective method expressed as a finite set of
well-defined instructions.
Thus, a computer programmer lists down all the steps required to
resolve a problem before writing the actual code. Following is a
simple example of an algorithm to find out the largest number
from a given list of numbers
- In general, programming is nothing but a way to create
solutions to the problems we face in this world.
- What is Dart?
Dart is an open-source, general-purpose, object-oriented
programming language with C-style syntax developed by Google
in 2011. The purpose of Dart programming is to create a frontend
user interfaces for the web and mobile apps.
It is under active development, compiled to native machine code
for building mobile apps.
- Let’s dive in, after install dart on your machine refer to this
instructions, we can go through some fundamentals:
Ex:
Data Types
The Dart language supports the following types:
Map
The Dynamic Type
Dart is an optionally typed language. If the type of a variable is not explicitly
specified, the variable’s type is dynamic.
Variables
A variable is “a named space in the memory” that stores values. In other
words, it acts a container for values in a program. Variable names are
called identifiers. Following are the naming rules for an identifier:
• Identifiers cannot be keywords.
• Identifiers can contain alphabets and numbers.
• Identifiers cannot contain spaces and special characters, except the
underscore (_) and the dollar ($) sign.
• Variable names cannot begin with a number.
Type Syntax
A variable must be declared before it is used.
Dart uses the var keyword to achieve the same. The syntax for
declaring a variable is as given below:
var name = 'Abdallah';
All variables in dart store a reference to the value rather than containing
the value. The variable called name contains a reference to a String object
with a value of 'Abdallah'.
Dart supports type-checking by prefixing the variable name with the data
type. Type-checking ensures that a variable holds only data specific to
a data type.
The syntax for the same is given below:
String name = 'Abdallah';
int num = 10;
Consider the following example: