ComputerScientist
174 subscribers
14 photos
3 files
206 links
▜ The Inventor

Stuff that inspire you to create.

See also: ▙ @LitMind
Download Telegram
#Programming_paradigms : Declarative versus Imperative

#Declarative
All about relations.

Does not state the order in which operations execute.

Focuses on what the program should accomplish without specifying how the program should achieve the result.
Expresses the logic of a computation without describing its control flow.

Common declarative languages include those of database query languages (e.g. #SQL, #XQuery), regular expressions (#Regex), logic programming, functional programming, and configuration management systems.

e.g. #Haskell, #Kanren (a dialect of #Scheme), #Prolog, #Wolfram_Language

#Imperative
Uses statements that change a program's state.
1. they state the order in which operations occur, with constructs that explicitly control that order

Allows side effects, in which state can be modified within one unit of code, and then read inside a different unit of code.

Imperative programming focuses on describing how a program operates.
an imperative program consists of commands for the computer to perform.
Many imperative programming languages (such as #Fortran, #BASIC, and #C) are abstractions of assembly language.
ComputerScientist
#Programming_paradigms : Declarative versus Imperative #Declarative All about relations. Does not state the order in which operations execute. Focuses on what the program should accomplish without specifying how the program should achieve the result. Expresses…
#Programming_paradigms
Expression versus Statement
An expression is a unit of #declarative programming.
A statement is a unit of #imperative programming.
An expression is evaluated whereas a statement is executed.

Expressions
A combination of values, variables and functions that return a value and have no side effects.

Expressions can contain functions and functions may have side effects. A side effect is a change to the abstract state of the running program that does not depend on the function input.

Functional programs do not have assignment statements therefore the value of a variable never changes once defined. An expression is said to be referentially transparent if it can be replaced with its corresponding value without changing the program's behavior. Evaluating a referentially transparent function gives the same value for same arguments. Such functions are called pure functions. Referentially transparent expressions allow #memoization.

Statements
Do not return results and are executed solely for their side effects.

Simple statements:
• assertion
• assignment
• goto
• return
• call

Compound statements: (may contain statements as components)
• block
• choice
• iteration
Dataflow programming
Traditionally, a program is modelled as a series of operations happening in a specific order; this may be referred to as sequential, procedural, control flow, (indicating that the program chooses a specific path), or #imperative programming. The program focuses on commands, in line with the von Neumann vision of sequential programming, where data is normally "at rest".

In contrast, dataflow programming emphasizes the movement of data and models programs as a series of connections. Explicitly defined inputs and outputs connect operations, which function like black boxes. An operation runs as soon as all of its inputs become valid. Thus, dataflow languages are inherently parallel and can work well in large, decentralized systems.
#language #D
D
- is a system programming language first appeared in 2001. Though it originated as a re-engineering of C++, D is a distinct language, having redesigned some core C++ features while also taking inspiration from other languages, notably Java, Python, Ruby, C#, and Eiffel.

D attempts to combine the performance and safety of compiled languages with the expressive power of modern dynamic languages. Idiomatic D code is commonly as fast as equivalent C++ code, while being shorter and memory-safe. Type inference, automatic memory management and syntactic sugar for common types allow faster development, while bounds checking, design by contract features and a concurrency-aware type system help reduce the occurrence of bugs.

Paradigms: #imperative, #object_oriented, #metaprogramming, #functional and #concurrent (actor model)


Comparison with C
Despite their difference, D has been constrained in its design by the rule that any code that is legal in both C and D should behave in the same way.


Comparison with C++
Things D gained before C++:
• closures
• anonymous functions
• compile time function execution

Things D adds:
• design by contract
• unit testing
• true modules
• garbage collection
• first class arrays
• associative arrays
• dynamic arrays
• array slicing
• nested functions
• lazy evaluation
• built-in support for documentation comments, allowing automatic documentation generation

Things D replaces:
• multiple inheritance is replaced by Java-style single inheritance with interfaces and mixins.
• template syntax is re-engineered

Things they have in common:
• D's declaration, statement and expression syntax closely matches that of C++.
• D retains C++'s ability to perform low-level coding and to add inline assembler. The inline assembler typifies the differences between D and application languages like Java and C#. An inline assembler lets programmers enter machine-specific assembly code within standard D code, a method often used by system programmers to access the low-level features of the processor needed to run programs that interface directly with the underlying hardware, such as operating systems and device drivers.

Docs: https://dlang.org/spec/spec.html
#language #R
R
- is a programming language and software environment for statistical computing and graphics. The language is widely used among statisticians and data miners for developing statistical software and data analysis. Polls, data mining surveys and studies of scholarly literature databases, show substantial increases in popularity in recent years.

Paradigms: #object_oriented, #imperative
First appeared: 1993
Influenced by: #Lisp, S, Scheme
Influenced: #Julia
#TIOBE rank: 18 (as of 2018)

Source code for the R software environment is written primarily in #C, #Fortran and R itself. The project was conceived in 1992, with an initial version released in 1995 and a stable beta version in 2000.

Syntax
• Assignment
The generally preferred assignment operator is an arrow made from two characters <-, although = can usually be used instead.

• Vectors
> x <- 1:6  # Create vector.
> y <- x^2 # Create vector by formula.
> print(y) # Print the vector’s contents.
[1] 1 4 9 16 25 36

• Functions
f <- function(x, y) {
z <- 3 * x + 4 * y
return(z)
}

Semantics
The scalar data type was never a data structure of R; instead, a scalar is represented as a vector with length one. Data structures include vectors, matrices, arrays, data frames (similar to tables in a relational database) and lists.

Features:
• supports matrix arithmetic
• supports regression analysis, time-series analysis, spatial analysis
• has generic functions (which act differently depending on the classes of arguments passed to them i.e. dispatch the function/method specific to that class of object; e.g. print)
• arrays are stored in column-major order


RStudio
The most commonly used graphical integrated development environment for R is RStudio. It is written in Java, C++ (the Qt framework for its GUI) and JavaScript. Work on RStudio started around December 2010, and the first public beta version was officially announced in February 2011. Version 1.0 was released on 1 November 2016.

www.rstudio.com