Created
April 19, 2022 02:55
-
-
Save cconstable/9fb22b41e45efec3ca7228b64c837cc2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Hello Nicholas. | |
* Here are my thoughts on learning Flutter. | |
* | |
* Learning Dart and Flutter is going to be hard. | |
* | |
* We can't meaningfully learn by just consuming information. We must optimize for | |
* consuming the best information at the best time and in a format that we can | |
* absorb. In order to do this, we have to learn to ask good questions at | |
* appropriate times. In order to ask good questions, we need to be able to | |
* articulate what we want to know and, to do this, we must be intentional | |
* about expanding our language and strive to be as precise as possible. | |
* | |
* That said, I think learning Flutter will be an exercise in learning to ask | |
* the right questions... and constantly asking them. To keep morale high | |
* during this demoralizing endevour, we need to have a goal, you need to tell | |
* me what we are going to do next, and you need to feel like you've | |
* interalized some new ideas every time we meet. Purpose, autonomy, and | |
* mastery. | |
* | |
* Lastly, interrupt me. Let's break things. Ask "what happens if..." questions. | |
* Ask "how would you go about getting answers to this problem?" questions. I | |
* know the answers to literally everything Nicholas. | |
* | |
* Let's work up from first priciples. | |
* | |
* Keep a little accomplishments journal (just a text file thats open in VSCode) | |
* where you can write "learned about all the primitive types today" and maybe | |
* recap things you learned if you think you might forget. | |
* | |
* Lastly, lastly, I think you are going to do great. | |
*/ | |
/* | |
* Here is a quick Dart / Flutter primer from first principles | |
*/ | |
// ignore: this "main function" is required to run any dart code | |
void main() { | |
// Q: How do I show some text on the screen? | |
// A: Let's figure out to get "text" to begin with... | |
// Q: How do I store some text? | |
// A: Use a String | |
String someText = 'hello'; | |
// Q: What does this mean? | |
// A: It means we have a "variable" called "someText" that has a type of | |
// "String" and has it's "value" set to "hello". The "grammar" for this | |
// "statement" looks like this: | |
// | |
// <type> <variable-name> = <value>; | |
// | |
// The equal sign is called the "assignment" operator and it "assigns" | |
// a value to something. A "statement" is just a piece of code that "says" | |
// something... like declaring a variable or setting a value. | |
// Q: How do I put someone's name in that String? | |
someText = 'hello nick'; | |
// Q: That seems like cheating. What if I am getting the name from another | |
// part of the program and don't know what it is? Also, why doesn't line | |
// 59 start with "String" like it did above? | |
// A: The line doesn't start with "String" because the variable "someText" | |
// was already "declared" on line 45. We told Dart it exists by adding that | |
// "String" to the front of the line. Now Dart knows it's a string and we | |
// don't have to "redeclare" it. We can just set new values to it. | |
// | |
// To answer the first question: | |
String nameFromSomewhereElse = 'nick'; // pretend this came from somewhere else | |
someText = 'hello ' + nameFromSomewhereElse; | |
// Q: What is the "+" sign doing? | |
// A: It's "concatenating" the strings together into one string. | |
// Q: Can we show it on the screen now? | |
// A: Yes, but it will be easier to show it in the console first. | |
print(someText); | |
// A: "print" just prints some value to the console. It's for developers to | |
// look at... users don't see it. | |
// Q: What if I want to say hello to multiple people? | |
// A: Like this? | |
print(''); // print a blank line | |
someText = 'hello nick'; | |
print(someText); | |
someText = 'hello chief'; | |
print(someText); | |
someText = 'hello chief simp'; | |
print(someText); | |
print(''); // print a blank line | |
// Q: Can we make this better? | |
// A: Yes. Anytime we are doing the same work over and over we can take that | |
// work and turn it into a "function". Programmers like to name example functions | |
// "foo". This is a function called "foo" that prints "1234". | |
foo() { | |
print('1234'); | |
} | |
// A: "foo" is the name of the function, "()" means it has no "input", and the "{}" | |
// are where we write what we want the function to do. When we want the function | |
// to run or do it's thing, we "invoke" the function like this: | |
foo(); | |
// A: We can invoke a function as many times as we want. | |
foo(); | |
foo(); | |
foo(); | |
// A: We can "pass parameters" to functions too. Parameters are the "input" to the | |
// function. To make a parameter you put it in the parenthesis and write it's | |
// "type" and then what you wanto to call it. In this case we have function | |
// called "sayHello" that we can give a "String" as input and inside the function, | |
// we can reference that input as "name". | |
sayHello(String name) { | |
print('hello ' + name); | |
} | |
// A: Now we can say hello much more efficiently. | |
print(''); // print a blank line | |
sayHello('nick'); | |
sayHello('chief'); | |
sayHello('chief simp'); | |
print(''); // print a blank line | |
// Q: It looks like everything is just functions. | |
// A: Basically, yea. Programming really just boils down to creating functions, | |
// organizing them, and then calling them with data. | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment