Inputs, outputs, and debugging Flashcards
DOM
Document object model
Document.Object.Model represents (3)
Document Object Model
Document - web page - index.html
Object - pieces or individual tags/elements - H1 tag, etc.
Model - agreed upon set of terms
batch program
- a program that is designed to start from finish to end as soon as possible, and potentially produce and output
- example: anti-virus scanner
- most programs nowadays are not designed to start and finish as soon as possible. they allow you to interact with them through a graphical user interface.
persistence
saving the state of the program
what kind of persistence (saving ability) exists in javascript?
None! At least not at the basic level!
It doesn’t exist due to security concerns. But other programming languages such as java or objective C which runs natively on your OS will allow you to save files onto your hard drive.
example of a few different javascript events
1) unload
2) onclick
3) onmouseover
4) noblur
5) onfocus
what takes longer, writing code or debugging code?
debugging
errors in code (2)
1) syntax error
2) logic error
error in code
syntax error
- something is wrong with the ACTUAL format of the code
- forgot a semi colon, wrong number of braces, brackets, etc…
syntax error
- compiled vs. interpreted language
- in compiled languages, syntax errors are normally found while writing the code
- with interpreted code, you sometimes just have to run code before you know if there’s a syntax terror
error in code
*logic error
- correct in syntax but there’s a flaw in the logic
- problem with arithmetic
- infinite loop
best way to fix an error in code:
reproduce the same error
find out when the error occurs and how it occurred
trace
- finding out where the code when wrong by leaving messages in your code or functions.
trace messaging is sometimes called…
logging to the console
In object oriented programming, these “objects”….
communicate with one another
Class
The blueprint, the description, and the definition
If you wrote “classes” for a restaurant-review website, some classes would be (9)
- restaurant
- review
- user
- textbox
- button
- window
- date
- timezone
- Videoplayer
Of course, there’s more.
An attribute (english word) is akin to a . . . (computing word)
property
A behaviour (english word) is akin to . . . (computing word)
a method, a function
a property or a method?
*name
property
a property or a method?
*sleep
method
a property or a method?
*speak
method
a property or a method?
*gender
property
a property or a method?
*run
method
a property or a method?
*age
method
a property or a method?
*gender
property
a property or a method?
*jump
method
a property or a method?
*height
property
a property or a method?
*weight
property
A class is a/an __________ as the object is the thing
idea
A class is an idea and the object, is the _________
thing
encapsulation
the idea the classes and objects are self contained entities, and that we box them up together to produce our end product
var isValid = true;
is of type
boolean
primitives
primitives store a value
object or primitive?
*var myArray = [1, 2, 3, 4, 5];
object
object or primitive?
*var myNumber = 123;
primitive
object or primitive?
*var isValid = true;
primitive
object or primitive?
*var myRe = /hello/;
object
object or primitive?
*date
object
create today’s date in javascript
var today = new Date( );
create halloween date
var halloweenDate = new Date(2016, 1, 1)
classes in javascript (4)
1) array
2) RegExp (regular expression)
3) Date
4) Math
javascript classes are …. compared to other languages
limited
of the main languages, which one is the “purest” object oriented language?
ruby
basic pseudo code for memory management in object oriented programming (4)
1) allocate memory (choose memory you want to use)
2) create object
3) use object
4) free memory
memory leak
- when you don’t “free memory” after use
- causes programs to become slow
dangling pointer
- when you “free memory”, but have a variable pointed at a specific piece of memory
- you then try to use that variable but the variable doesn’t exist because you “freed memory”.
- causes programs to crash
reference counting
- used be Objective-C and C++ for memory management
- allows us to keep a counter of what memory is being used
garbage collection
- the system itself keeps track of how the much memory the application is using
- it is called garbage collection because the “freeing of memory” happens all at once, not slowly. You actually don’t have control of WHEN garbage is collected.
in Scripting language, memory management is…
automatic
problem with automatic memory management
- can be slow
bubble sort
- considered a slow method to sort numbers
in terms of programming (sorting for example), you have to decide between (3)
1) ease of use
2) speed
3) elegance (easy to understand)
multi-tasking
running many programs at once
multi-threading
doing multiple things in one program
multithreading challenges
1) competition for RAM or other resources
2) Restriction on updating UI
3) language support
4) Web Work – future feature for Javascript through an update in HTML5