Types of programming languages Flashcards
(31 cards)
what is a programming paradigm?
It is a style of programming
Some languages only support one type of paradigm (eg. Haskell, small Basic) but some support more than one (eg. Python, Java, C#)
What are the 4 programming paradigms? (and give an example)
- procedural programming - eg. Python, Basic, C#
- object oriented - eg. Python, Java, VisualBasic.NET
- declarative programming - eg. SQL, Prolog
- Functional programming - eg. Haskell, Javascript, Logo
what is procedural programming?
- consists of a series of instructions that tell the computer what to do with the inputs in what order to solve the problem
- languages using this paradigm have built in data types (eg. integer, floating point numbers etc) + data structures such as arrays + records
- programmers can also define their own abstract data types eg. queue, stack, tree, hash table, etc
what is structured programming?
- a type of procedural programming
- uses sequence, selection, iteration + recursion instead of goto techniques
- uses modular techniques - splits large programs into manageable chuncks
what is declarative programming?
- you write statements that describe the problem to be solved
- language implementation decided the best way to solve the problem
- doesnt execute in the same order as the statements
what is logic programming?
- a form of declarative programming
- a paradigm that expresses the logic of a computation without expressing its control flow
- programs consist of logical statements
- eg. prolog
what is functional programming?
- functions are used as the building blocks of a program
- statements are written as a series of functions which accept input data as arguments + return an output
when might a declarative programming language be used?
- in expert systems (eg. medecine)
- embodies fasts and rules about a particular field of knowledge - medical diagnosis, oil exploration, tax regs
- natural language processing (normal human language) - text to speech, spell checking
what is backtracking?
- usually done during recursion
- if a dead end is found go back to the previous choice that was made
- this is repeated until the thing needed is found/all possible paths are exhausted
what is an abstract data type?
queue, stack, tree, graph, hash table, etc.
what is object oriented programming?
- more abstract thinking - think about the objects that will complete the tasks, not the data structures + algorithms
- makes it possible to abstract details of implementation away from the programmer
- makes reusable code
- programs are easy to maintain
- programs are made of objects with attributes (data about the object) + methods (operations on the data)
what is a class?
the description of what the data looks like (the state) and what the data can do (the behavior) - kinda like a blueprint for the object- defines attributes + methods
what is an object?
a specific instance created based on the blueprint (class) that has its own unique data values
what is instantiation?
the process of creating an object of a class - memory is allocated for its attributes + initial values are set
what is a constructor?
a method that creates an instance of a class. in pseudocode:instance = new class(parameters)
what does it mean if an attribute is private?
users cannot directly access or change them - they can only be changed through methods (functions or procedures)
what is recursion?
- it is a programming construct where a subroutine call itself during execution until the stopping condition is met
- produces the same results as iteration but using fewer lines of code
- can be inefficient with memory and cause a stack overflow (the stack runs out of memory)
- difficult to trace, esp with more function calls
what are local variables and why are they good?
- variables that can be accessed only within the block of code in which they were defined
- eg. if defined in a subroutine can only be accessed in the subroutine
- good because it makes sure subroutines are self contained - variables can’t be affected by code elsewhere
what is a global variable and why are they good?
- variables that can be accessed across the whole program
- any variables declared in the main body of the program are global variables
- useful if a value needs to be used in multiple parts of the program
- not great because they can be accidentally overwritten
- also use more memory than local variables because they are terminated at the end of the program rather than the end of the subroutine
what is encapsulation?
when attributes and methods are bundled together under a single unit - eg. a class
good because it protects attributes being accessed directly
code for different classes can be produced independently of each other
what is a setter?
a method that sets the value of a particular attribute
what is a getter?
a method that retrieves the value of a given attribute
what is the difference between a function and a procedure?
- function: returns a value
- procedure: doesnt return a value, just completes a task
what is inheritance?
- a relationship among classes where a subclass shares all the attributes + methods from a parent class/superclass
- good because it saves time redefining shared attributes + methods