Transcript from the "Variables & Types" Lesson
>> In terms of variables and types, so how to declare a variable, there are two ways. If you know the type or if you wanna explicitly use the type, you use the type name as a prefix. So you say int data, similar to C, or Java. Okay, you start with a type and then the name.
[00:01:29] Then we have immutable variables. In this case instead of bar, we use final or we apply final to the type. And final is a variable that cannot be changed after it's set for the first time. That's an immutable variable, okay, make sense? Fine, and then we have constants that are using the const keyword, and we are going to use const a lot in flutter.
[00:02:18] That actually they are more like immutable variables. So first, what's the difference between an immutable variable and a constant? Does anyone know?
>> On any sides like a generic programming. Typically we have a difference between an immutable variable and a constant.
>> Const would be at compile time so it's set and it's more performant because it's already defined.
[00:03:03] An immutable variable, it's actually a variable, so it's actually a place in memory while our app is running, but after it was set, it cannot be changed. But I don't need to have a value at compile time for immutable variable, that's the difference. And for the constant, I actually need to have a value at compile time, okay, make sense?
[00:03:28] Types, here, we have a mix between using lowercase and uppercase, but everything is an object. So don't get confused here with languages like Java, for example in Java, you have int and you also have integer with capital I. This is Java, okay? And this is a basic data type and this is an object, but actually here int is an object, everything is an object in Dart.
[00:03:57] And we have some basic type with lowercase, they use lowercase, because they say that when you're coming from Java or from C, you're more used to use int with lowercase i. So we have int, double, bool, dynamic, that's anything. And we also have num, say num, that's a number that you don't define the type of the number, okay?
[00:05:14] You will see that today, most of the design guidelines for Flutter are actually suggesting double quotes, just to pick one, okay, the same as in HTML. So in HTML you can use single quotes today if you want to, but it's kind of typical to see HTML with single quotes for attributes.
[00:05:34] Well same here, you can create multiline, literal strings with triple, double quotes. So if I have a long description, you can use triple, double quotes and then you end up somewhere and then everything is part of the string. This is similar to other languages such as Kotlin or Swift, they have the same multiline experience.
>> So type keywords are capitalized like string?
>> So the answer is not always, because int is not with capital i, double is not with capital i. Let's say, and again, I know what you're thinking, that's because it's not an object. No, that's not true, it's an object, everything is an object in Dart.
[00:07:19] But they made the choice when they created the language to use lowercase on the basic types, integers, doubles. And why not the string? Because in Java, the string is a class and its capital S, so they tend to try to bring Java developers into Dart. So that's why a string is capital S.
[00:07:42] If you're creating your own types, the guideline is to start with capital letters, okay? But let's say that you will see lowercase types only on these basic ones, bool, dabble, int, dynamic, boid as well, we haven't seen it yet and that's all. For the other types, they will be title case, so capitalized, but have in mind everything is an object anyway.
>> Now when you see a simple objects, they're still full objects?
>> They are still objects, full objects, so an int is an object, it's an object, there is a class behind. It's actually an object so that integer value has methods and properties like any other object. It's based on a class, it's not like an int in C or an int in Java, where it's not actually an object, here everything is an object.
[00:08:39] You can actually even get inside how Ctrl+click, or Cmd+click on a Mac, you can actually get into the int. And you can see it's a class extending from num, from number, so it's a class. Because it's a class, it can contain methods constructors, and everything that we know on OOP.