programming Flashcards

how do I make the computer do stuff?

1
Q

where do you program?

A

find an interpreter (or a compiler*) e.g. the javascript console in your web-browser (probably not available on a phone or ipad) or various websites:
{
most_languages: https://repl.it/,
ruby : https://repl.it/repls/PrevailingTechnoPagerecognition,
python: http://www.skulpt.org/,

}
*Note: when you’re ready to work with a compiled language you will no longer need these flashcards :)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

what are the main parts of most programming-language(s)?

A

variables, statements (e.g. variable-assignment, variable-access, boolean-logic, conditionals, function-calls), function-definitions, and control-flow-blocks

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

what is a variable?

A
it's like a "box" that holds a value, e.g.
var a = "some value"; // javascript
or
a = "some value" # ruby or python
or
c := "some value" // go-lang
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

how do you tell a computer to print to the screen?

A

puts “hello world!” # Ruby (possibly also python)
print “hello world!”; # Python (also Ruby)
print(“hello world!”); // go-lang, ruby, ??
echo “hello world!” # bash scripting
console.log(“hello world!”); // javascript – to the console, not the screen
alert(“hello world!”); // javascript – popup a modal on the screen

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

how might you read input from the users of your program?

A
typically paired with writing a question to the screen:
print "Enter name: "; name = gets.chomp!; puts "your name is #{name}" # Ruby
var name = prompt("Enter name: "); alert("Your name is " + name); // javascript
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

how do you organize code?

A

in a word: by placing code into well-named functions

e.g. 

var message, name;
name = prompt(“what’s your name?”);
message = “hello, “ + name + “!”;
alert(message);
~~~
```

becomes:
~~~
alert(messageFor(userName()));

function messageFor(getUsername) {
   return "hello, " + username + "!";
}
function getUserName() {
  return prompt("what's your name?");
}

```

why is this better? Because in the final example, someone can read the one “main” line of code and understand what your code is doing, without having to care how those functions are implemented.

whereas in the other example, someone would have to read (and understand) every line of code in order to understand what the code is doing. Which gets very tiring when the code is 10’s of 1000’s of lines long (like in a real program)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

what are some key basics you should learn when you approach any new programming language?

A

what data-types are available?

how to assign a variable & read its value?

how-to define and call a function?

how does control-flow work
i.e. are commands synchronous?; what operations exist: , % (modular arithmetic); what loops? while-loops, for-loops; does it support recursion?

how to read and write from the screen?

how to read and write from a file?

how to read & write from the internet (i.e. socket reads & writes)?

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

how do you create a program (in javascript & html) to simulate rolling dice?

A

https://www.youtube.com/watch?v=vjPIDX-itvc&t=443s

How well did you know this?
1
Not at all
2
3
4
5
Perfectly