General Programming Concepts Flashcards

1
Q

What is a compiler vs interpreter and what are the pros and cons of each type of language and some examples?

A
  • Interpreted/compiled is not a property of the language but a property of the implementation.
  • Source Code is the human readable program code.
  • Compiler and Interpreter are two different ways to translate a program from programming or scripting language to machine language.
  • Computer only understands 0’s and 1’s in binary, called the machine code.
  • Compilers take an entire program and converts it into object code which is typically stored in a file. The object code is also referred as binary code and can be directly executed by the machine after compilation.
  • An interpreter, on the other hand, translates code one line at a time and executes it immediately.

Pros and Cons:
* Compiled languages tend to be faster and more efficient to execute than interpreted languages12.
* Compiled languages are less resource intensive.
* They also give the developer more control over hardware aspects, like memory management and CPU usage1.
* Interpreted languages are generally slower than compiled languages because they have to be translated at runtime3.
* However, interpreted languages are platform agnostic2 which means that they can run on any platform without requiring recompilation2.
* Interpreted languages tend to be more flexible and often offer features like dynamic typing and smaller file sizes.

Examples
* C# is compiled, so is Java and many OOP languages.
* PHP is an interpreted language. The binary that lets you interpret PHP is compiled, but what you write is interpreted.
* A compiled code can be executed directly by the computer’s CPU. That is, the executable code is specified in the CPU’s native language.

The code of interpreted languages must be translated at run-time from any format to CPU machine instructions. This translation is done by an interpreter.

It would not be proper to say that a language is interpreted or compiled, because interpretation and compilation are both properties of the implementation of that particular language and not a property of the language as such. So, any language can be compiled or interpreted — it just depends on what the particular implementation that you are using does.

The most widely used PHP implementation is powered by the Zend Engine and is known simply as PHP. The Zend Engine compiles PHP source into a format that it can execute, thus the Zend engine works as an interpreter.

Example is that Javascript can be compiled or interpreted..

Practically (read: using a somewhat popular and mature implementation), Python is compiled. Not compiled to machine code ahead of time (i.e. “compiled” by the restricted and wrong, but alas common definition), “only” compiled to bytecode, but it’s still compilation with at least some of the benefits

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

What does non-blocking IO mean?

A

Non-blocking I/O operations allow a single process to serve multiple requests at the same time. Instead of the process being blocked and waiting for I/O operations to complete, the I/O operations are delegated to the system, so that the process can execute the next piece of code

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

What is event driven programming?

A
  • In computer programming, event-driven programming is a programming paradigm in which the flow of the program is determined by events such as user actions (mouse clicks, key presses), sensor outputs, or message passing from other programs or threads.
  • Event-driven programming is the dominant paradigm used in graphical user interfaces and other applications (e.g., JavaScript web applications) that are centered on performing certain actions in response to user input
  • The opposite of event-driven programming would be programming that is written to act regardless of user input1. For example, display apps such as those for weather updates or sports scores may feature less of the event-driven programming that is inherent in other kinds of programs1.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Define declaring and initializing variables with an example in python.

A

The short answer is:
Declaring a variable means stating its name and data type. e.g: String NameOfString

Initializing means assigning a value to a variable. e.g:
NameOfString = “SomeNameValue”

The background is:

Generally in programming declaring a variable means defining its type, and optionally, setting an initial value (initializing the variable). Variables do not have to be initialized (assigned a value) when they are declared, but it is often useful.

Python is a bit different.

Unlike in the C programming language, in Python a variable is not bound to a certain object. Rather, variables in Python work as pointers to objects. This means they’re not restricted to a specific type and can be assigned dynamically. For instance, you can assign a value of one data type to a variable, and to another data type directly afterward:

x = 5
x = "five"

This would throw an error in a statically typed language like C or Java. In those languages, a variable’s type has to be specified before it may be assigned to a value. This process is called variable declaration. But in Python, we don’t declare variables, we simply assign them. In short, we can think of a variable in Python as a name for an object.

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

What is meant by a statically typed language vs a dynamically typed language? which is Python?

A

Short Answer:

Static Type:

  • A language is statically typed if the type of a variable is known at compile time. For some languages this means that you as the programmer must specify what type each variable is;

Dynamic Type:

  • A language is dynamically typed if the type is associated with run-time values, and not named variables/fields/etc.
  • This means that you as a programmer can write a little quicker because you do not have to specify types every time (unless using a statically-typed language with type inference).

Context:

Statically typed languages

  • A language is statically typed if the type of a variable is known at compile time.
  • For some languages this means that you as the programmer must specify what type each variable is; other languages (e.g.: Java, C, C++) offer some form of type inference, the capability of the type system to deduce the type of a variable (e.g.: OCaml, Haskell, Scala, Kotlin).
  • The main advantage here is that all kinds of checking can be done by the compiler, and therefore a lot of trivial bugs are caught at a very early stage.

Examples: C, C++, Java, Rust, Go, Scala

Dynamically typed languages

  • A language is dynamically typed if the type is associated with run-time values, and not named variables/fields/etc.
  • This means that you as a programmer can write a little quicker because you do not have to specify types every time (unless using a statically-typed language with type inference).
  • Examples: Perl, Ruby, Python, PHP, JavaScript, Erlang
  • Most scripting languages have this feature as there is no compiler to do static type-checking anyway, but you may find yourself searching for a bug that is due to the interpreter misinterpreting the type of a variable.
  • Most dynamically typed languages do allow you to provide type information, but do not require it.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is a CDN

A

Content Delivery Network - A content delivery network (CDN) is a group of geographically distributed servers that speed up the delivery of web content by bringing it closer to where users are. Data centers across the globe use caching, a process that temporarily stores copies of files, so that you can access internet content from a web-enabled device or browser more quickly through a server near you. CDNs cache content like web pages, images, and video in proxy servers near to your physical location. This allows you to do things like watch a movie, download software, check your bank balance, post on social media, or make purchases, without having to wait for content to load.

AWS Cloudfront is a CDN.

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

What is an interpreted programming language?

A

An interpreted programming language is a programming language that is generally interpreted without compiling a program into machine instructions. In this type of language, the implementations perform instructions directly and easily without compiling a program into machine-language instructions1.

Some examples of interpreted languages include Python, BASIC, JavaScript, Perl12.

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

What are the different types of programming languages?

A

High-level programming languages: These are languages that are closer to human language and are easier to read and write than low-level languages. Examples include Java, Haskell, Prolog, and FORTRAN1.

Mid-level programming languages: These languages are a combination of high-level and low-level languages. They provide more control over the hardware than high-level languages but are easier to use than low-level languages. Examples include C and Assembly1.

Low-level programming languages: These languages are closer to machine language and are harder to read and write than high-level languages. Examples include Assembly and Machine code1.

Procedural programming languages: These languages follow a sequence of statements or commands in order to achieve a desired output. Examples include C and C++2.

Functional programming languages: These languages focus on the execution of functions rather than statements or commands. Examples include Haskell and Lisp2.

Object-oriented programming languages: These languages focus on objects that contain data and methods that operate on that data. Examples include Java and Python2.

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

What are the different types of High Level Programming Languages and their main characteristics?

A

Procedural-Oriented Programming Language

  • Basic, Fortran, C, Pascal, and COBOL.
  • The main goal of Procedural-Oriented Programming is to solve a problem. So, data is the second priority.
  • In POP, a program is divided into small modules called functions1. Each function performs a specific task and returns a value to the calling function.
  • Procedural programming can be used to create compilers, operating systems, kernels, etc., code system software for devices and embedded systems, and code server-side applications as a web developer.

Object-Oriented Programming Language

  • Make use of Classes and Objects for creating a program.
  • Most realistic programming approach for solving Real-World problems.
  • Some of the basic concepts of Object-Oriented Programming are Object, Class, Inheritance, Abstraction, Polymorphism, and Encapsulation.
  • Java, Python, C++, C#, JavaScript, and PHP.

Functional Programming Language

  • Functional Programming is a style of programming, where functions are treated and used just like variables. Therefore, Functional Programming Language is also known as the First-Class Function.
  • In Functional Programming, the data is immutable, which means that once the data is created, it cannot be changed and we have to create a separate variable instead of changing the old one.
  • Another goal of Functional Programming is to keep the Data separate from the Function.
  • Examples of Functional Programming Language: Haskell, Scala, Python, Clojure, and Swift.
  • It is a declarative type of programming style3. Its main focus is on “what to solve” in contrast to an imperative style where the main focus
  • Python is usually coded in an imperative way but can use the declarative style if necessary1. Functional languages are declarative languages, they tell the computer what result they want. This is usually contrasted with imperative languages that tell the computer what steps to take to solve a problem1. Python is a general-purpose language, meaning it can be used to create a variety of different programs and isn’t specialized for any specific problems2. is “how to solve”.

Problem-Oriented Programming Language

Scripting Programming Language

  • Scripting Language is the Programing Language which is used for performing automation or repetitive task with the help of scripts.
  • Unlike, other Programming Languages, Scripting Languages are Run-Time Programming Languages.
  • Examples of Scripting Programming Language: Bash, JavaScript, Shell, Python, and Perl.

Artificial Intelligence Programming Language

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

What is a declaritive programming style?

A

Declarative programming is a programming paradigm that expresses the logic of a computation without describing its control flow. In contrast, imperative programming is a programming paradigm that uses statements that change a program’s state1.

In other words, declarative programming describes what you want the program to achieve rather than how it should run2. It focuses on what you want to do rather than how you want to do it3. This makes it easier to reason about and understand the code4.

Imperative programming, on the other hand, focuses on how you want to do something. It uses statements that change a program’s state1. This makes it easier to write code that performs specific tasks and is often used for low-level programming2.

Declarative programming languages include HTML, SQL, CSS and XML1. Other examples include a mix of functional and logic programming languages such as Prolog, Haskell, Miranda, XQuery and Lisp1.

In declarative programming, you define what you want to accomplish without describing how to do it2. This makes it easier to reason about and understand the code3.

I hope this helps! Let me know if you have any other questions.

Imperative programming consists of sets of detailed instructions that are given to the computer to execute in a given order1. It focuses on describing how a program operates, step by step1. Examples of imperative programming languages include C, C++, Java and Fortran23.

Declarative programming is used when you want to say what you want, while imperative programming is used when you want to say how to get what you want1.

Declarative programming is like asking your friend to fix your car, while imperative programming is like fixing it yourself2.

In contrast with imperative programming, declarative programming describes what you want the program to achieve rather than how it should run3.

Declarative programming allows us to write more readable code that reflects what exactly we want to see4. Combined with good variable names, it can be a powerful tool4.

Imperative programming may not offer as much flexibility from a coding standpoint, but it’s great for closed-loop processes and offers a straightforward way to customize code and functions5.

Some programming languages can be both imperative and declarative1. For example, Python can be used in both declarative and imperative programming1. Over the years, some other imperative languages have also received updates allowing them to support declarative-style programming1. These include JavaScript, C++, and C#1.

# Declarative
small_nums = [x for x in range (20) if x < 5]

Imperative
small_nums = []
for i in range (20):
    if i < 5:
        small_nums.append (i)
				
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Give an example of a programming language that has many different characteristics.

A

Python is an

  • interpreted,
  • high-level programming language
  • with dynamic semantics1.
  • multi-paradigm supports object-oriented programming and structured programming2.
  • Its high-level built-in data structures, combined with dynamic typing and dynamic binding
  • it also supports imperative and declarative styles of programming
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is a structured programming language and compare it to OOP?

A

In summary, structured programming is a precursor to OOP, focusing on readable code and reusable components. OOP, on the other hand, revolves around objects, combining both data and behavior. Each paradigm has its strengths and use cases, and the choice depends on the specific requirements of the project

Structured Programming:
* Definition: Structured programming is a programming paradigm that emphasizes dividing code into well-structured and separated modules or functions.
* Modules: Programs are divided into smaller programs or functions, making the code more organized and readable.
* Logic Flow: Structured programming follows a top-down approach, where the program execution starts from the main function and proceeds sequentially.
* Languages: Examples of structured programming languages include Pascal, ALGOL, C, and Modula-2.
* Focus: It focuses on functions and processes that work on data.
* Flexibility: Provides less flexibility and abstraction compared to OOP.
* Modification: Structured programs can be more difficult to modify and reuse code.

Object-Oriented Programming (OOP):
* Definition: OOP is a different approach that brings together data and functions into objects.
* Objects: Programs are divided into objects or entities, each containing both data (attributes) and code (methods).
* Real-Life Entities: OOP models real-life entities, focusing on who performs the task rather than just what needs to be done.
* Languages: Examples of OOP languages include Java, C#, and C++.
* Features: OOP supports encapsulation, abstraction, inheritance, and polymorphism.
* Security: It includes data hiding, making it more secure.
* Flexibility: Provides more flexibility and abstraction compared to structured programming.
* Modification: OOP programs are easier to modify and reuse code.

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

What is a typed programming language and how does it relate to static typing?

A
  • A typed programming language is a programming language that requires variables to be defined with a data type1. In other words, it is a language that requires all variables to have a specific type2. This allows for more efficient code and helps prevent errors1. There are two types of typed programming languages: statically typed and dynamically typed2.
  • An untyped programming language is a programming language that does not require variables to be defined with a data type1. In other words, it is a language that allows variables to have any type2. Examples of untyped programming languages include most assembly languages, BCPL, Tcl, and some varieties of Forth12.
  • A programming language is statically typed if the type of a variable is known at compile time1. A language is dynamically typed if the type of a variable is checked during run-time1.
  • In statically typed languages, variables must be declared with a data type when they are created2. In contrast, dynamically typed languages can infer or guess the type of data being used2.
  • Examples of statically typed languages include Java, C++, and C#2. Examples of dynamically typed languages include Python, Ruby, and JavaScript3.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is meant by typesafe?

A

Type safety in a programming language is an abstract construct that enables the language to avoid type errors1. Every programming language has an implicit level of type safety1. When we compile a program, the compiler will apply type safety construct to validate types, and it’ll throw an error if we try to assign the wrong type to a variable1.

The type safety feature ensures that any variable access only its authorized memory locations in a well-defined and permissible way1. In other words, the type safety feature ensures that the code doesn’t perform any invalid operation on the underlying object1.

Some common examples of statically-typed languages include Ada, C, C++, C#, JADE, Java, Fortran, Haskell, ML, Pascal, and Scala1. PHP is an example of a loosely typed language2.

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

difference between loosely typed and type unsafe programming languages

A

A loosely typed programming language is a programming language that does not require variable types to be defined before use. In other words, the type of a variable can be changed at runtime1. A type-unsafe programming language is a programming language that allows operations that violate the type system2.

Some examples of type-unsafe programming languages include C and C#1. Some examples of loosely-typed programming languages include Perl and JavaScript23.

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

What is VAR in C# considered statically typed?

A
  1. The technical term for var is “implicitly typed local variable declaration.”
  2. The variable itself is still statically typed (the type is determined when the code is compiled), and it is still strongly typed (the type cannot change once it has been declared)
17
Q

Differentiate the term typesafe and statically typed.

A

Type-safe and statically typed are two different concepts in programming languages. A type-safe language is one that ensures that operations performed on variables are valid and do not result in undefined behavior. In contrast, a statically typed language is one where the type of a variable is known at compile time. This means that the compiler can catch type errors before the program is run.

For example, C is statically typed but not type-safe, while Haskell is both statically typed and type-safe1. Lua and Python are dynamically typed and type-safe2.

18
Q

In short what is the difference between static/dynamic typing and strong/weak typing.

A

Static/Dynamic Typing is about when type information is acquired (Either at compile time or at runtime).

Strong/Weak Typing is about how strictly types are distinguished (e.g. whether the language tries to do an implicit conversion from strings to numbers).

19
Q
A