Programming Languages Concepts: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
 
(82 intermediate revisions by the same user not shown)
Line 1: Line 1:
=External=
* [https://www.tiobe.com/tiobe-index/ TIOBE Index]
* http://pypl.github.io/PYPL.html
=Internal=
* [[Software Engineering]]
* [[Software_Development#Programming|Software Development]]
* [[People]]
* [[Python]]
=Programming Language Categories=
* Machine languages. These languages are directly executed on the CPU. The instructions refer simple operations and registers.
* Assembly languages. An assembly languages is almost one-to-one mapping to the equivalent machine language. It uses English mnemonics.
* High-level language: C, C++, Java, Python, Go. The come with higher level abstractions like types, variables, etc.
=Compilation vs. Interpretation=
In compiled languages, the translation between high-level language to machine code is done only once. It does not occur while you're running the code, it's being done before running the code, and at execution time, the machine code generated in advance it is executed directly.
A compiler does the transaction between the high-level language into machine code. An interpreted language translates high-level instructions into machine language every time the code is executed, while the code is being executed.
<span id='Interpreter'></span>Interpreted languages require an '''interpreter'''. Interpreters come with a few advantages: they manage the memory automatically, by performing garbage collection, they infer variable types, etc. [[Python]] has an interpreter, that provides the runtime for Python programs.
Java is both compiled and interpreted. Java high-level language is compiled into bytecode, and the bytecode is interpreted to machine language every time it runs in the JVM.
The compiled code is generally faster than the interpreted code because you need to do the translation every time you run interpreted code.
=Variables, Parameters, Arguments=
{{Internal|Variables,_Parameters,_Arguments|Variables, Parameters, Arguments}}
=Statement=
=Expression=
=Typing=
=Typing=


==Type==
==Type==


A type determines the set of values and operations specific to values of that type, and the way the instances of the type are stored in memory - the size of the values.
A type determines the set of values and operations specific to values of that type, and the way the instances of the type are stored in memory - the size of the values. [[#Expression|Expressions]] of a certain type (variables, functions) take their values from the type's set of values.
 
==The Primitive vs. Non-Primitive Nature of Types==
<font color=darkkhaki>This conversation started in the [[Go_Language#The_Primitive_vs._Non-Primitive_Nature_of_Types|Go Language]] page. Next time it's needed to be applied to a different language, hoist it here.
{{Internal|Go_Language#The_Primitive_vs._Non-Primitive_Nature_of_Types|Go Language &#124; The Primitive vs. Non-Primitive Nature of Types}}
</font>


==Static Typing vs Dynamic Typing==
==Static Typing vs Dynamic Typing==
Line 9: Line 47:
* Wikipedia Type System https://en.wikipedia.org/wiki/Type_system
* Wikipedia Type System https://en.wikipedia.org/wiki/Type_system


For a statically typed system, the variables always have a specific type, and that type cannot be changed.
<span id='Static_Typing'></span>For a '''statically typed''' system, the variables and expressions always have a specific type, and that type cannot be changed. This is where "static" comes from: a variable will always have the same type. The type is known at compile-time. The compiler uses this information to catch some classes of errors at compile time and produce low-level machine language that typically runs faster. C, C++, Java and [[Go_Language#The_Type_System|Go]] are statically typed languages, and much of the code written in such language is used to declare types.


Dynamically typed languages are convenient, because there are no intermediate steps between writing the code and executing it. However certain types of errors cannot be caught until the program executes. For statically typed languages, many of these errors are caught at the compilation phase. On the downside, static languages usually comes with a great deal of ceremony around everything that happens in the program (heavy syntax, type annotations, complex type hierarchies).
<span id='Dynamic_Typing'></span>'''Dynamically typed''' languages are convenient, because there are no intermediate steps between writing the code and executing it. A dynamically typed language, also called a scripting language, do not forces the programmer to declare the type of a variable before using them. Dynamic languages are not compiled, but interpreted. However certain types of errors cannot be caught until the program executes. For statically typed languages, many of these errors are caught at the compilation phase. On the downside, static languages usually comes with a great deal of ceremony around everything that happens in the program (heavy syntax, type annotations, complex type hierarchies). [[Python_Language#Type|Python]] is a [[Python_Language#Python_is_Dynamically_Typed |dynamically typed language]].


==Strong Typing vs Loose Typing==
==Strong Typing vs Loose Typing==


* Wikipedia Strong and Weak Typing https://en.wikipedia.org/wiki/Strong_and_weak_typing
* Wikipedia Strong and Weak Typing https://en.wikipedia.org/wiki/Strong_and_weak_typing
<span id='Strong_Typing'></span>In a '''strong typed''' language the type of an instance does not change, even if the value is mutable. Every object has a specific type, or class. Implicit conversions will occur only in certain permitted circumstances, like converting an int to float when it is divided with a float, but not as a general rule.
In a '''weakly typed''' language, an object of a certain type might get implicitly converted (or cast) to an object of a different type.
Python is a [[Python_Language#Python_is_Dynamically_Typed |strongly typed language]]. [[Go_Language#Type|Go]] is also a strongly typed language.


==Type Safety==
==Type Safety==


{{External|https://en.wikipedia.org/wiki/Type_safety}}
{{External|https://en.wikipedia.org/wiki/Type_safety}}
Type safety is the extent to which a programming language discourages or prevents type errors. Type enforcement can be static, exercised at compile-time, or dynamic, associated type information with values and detecting type errors at run-time, or both. Java and C# are examples of type-safe languages.


==Type Systems==
==Type Systems==
* The [[Python_Language#Type|Python Type System]]
* The [[Go_Language#Type|Go Type System]]
* The [[JavaScript Concepts - The Type System|JavaScript Type System]]


<blockquote style="background-color: #f9f9f9; border: solid thin lightgrey;">
=Scoping=
:[[Go Concepts - The Type System|The Go Type System]]
 
:[[JavaScript Concepts - The Type System|The JavaScript Type System]]
Static and dynamic scoping: https://www.geeksforgeeks.org/static-and-dynamic-scoping/
</blockquote>


=Duck Typing=
=Duck Typing=
* https://en.wikipedia.org/wiki/Duck_typing
* https://en.wikipedia.org/wiki/Duck_typing


=Polymorphism=
Go has [[Go_Interfaces#Duck_Typing|duck typing]].


Polymorphism is a feature of a programming language allowing to write code that behaves differently depending on the runtime state at a specific moment in time. The contract of the behavior is defined by an ''interface'', while the implementation of the interface can vary. In Java, different classes may implement an interface, and instances of those classes can be used interchangeably as that interface. In Go, different concrete types implement an interface.


<blockquote style="background-color: #f9f9f9; border: solid thin lightgrey;">
Is duck tying a good thing? ''<span id="duck_typing_does_not_help_readability">Is this a good thing? As far as I can tell, I can't say whether a specific type implements an interface, short of browsing all methods in the package, looking for receivers of that specific type. The compiler does that easily, but I don't. This does not help code readability.</span>''
:[[Go Interfaces|Interfaces in Go]]
</blockquote>


=Metaprogramming=
=Metaprogramming=
Line 43: Line 88:
Metaprogramming is writing code that manipulates other code, or even itself.
Metaprogramming is writing code that manipulates other code, or even itself.


=Functional Programming=
=Object-Oriented Programming=
 
{{Internal|Object-Oriented Programming#Overview|Object-Oriented Programming}}
 
=<span id='Closures'></span>Functional Programming=
 
{{Internal|Functional Programming|Functional Programming}}
 
=<span id='Concurrent_Programming'></span>Concurrent (Parallel) Programming=
 
{{Internal|Concurrent (Parallel) Programming#Overview|Concurrent (Parallel) Programming}}
 
=Formal Languages and Translators=
 
{{Internal|Formal Languages and Translators|Formal Languages and Translators}}


Closures and recursion are at the base of the ''functional programming'' paradigm.
=Number Representation in Computers=


==Closures==
{{Internal|Number Representation in Computers|Number Redpresentation in Computers}}


<blockquote style="background-color: #f9f9f9; border: solid thin lightgrey;">
=Domain Specific Languages (DSL)=
:[[Closures]]
{{Internal|Domain Specific Languages|Domain Specific Languages}}
</blockquote>
=Reflection and Metaprogramming=
{{Internal|Reflection_and_Metaprogramming#Overview|Reflection and Metaprogramming}}

Latest revision as of 21:35, 13 August 2024

External

Internal

Programming Language Categories

  • Machine languages. These languages are directly executed on the CPU. The instructions refer simple operations and registers.
  • Assembly languages. An assembly languages is almost one-to-one mapping to the equivalent machine language. It uses English mnemonics.
  • High-level language: C, C++, Java, Python, Go. The come with higher level abstractions like types, variables, etc.

Compilation vs. Interpretation

In compiled languages, the translation between high-level language to machine code is done only once. It does not occur while you're running the code, it's being done before running the code, and at execution time, the machine code generated in advance it is executed directly.

A compiler does the transaction between the high-level language into machine code. An interpreted language translates high-level instructions into machine language every time the code is executed, while the code is being executed.

Interpreted languages require an interpreter. Interpreters come with a few advantages: they manage the memory automatically, by performing garbage collection, they infer variable types, etc. Python has an interpreter, that provides the runtime for Python programs.

Java is both compiled and interpreted. Java high-level language is compiled into bytecode, and the bytecode is interpreted to machine language every time it runs in the JVM.

The compiled code is generally faster than the interpreted code because you need to do the translation every time you run interpreted code.

Variables, Parameters, Arguments

Variables, Parameters, Arguments

Statement

Expression

Typing

Type

A type determines the set of values and operations specific to values of that type, and the way the instances of the type are stored in memory - the size of the values. Expressions of a certain type (variables, functions) take their values from the type's set of values.

The Primitive vs. Non-Primitive Nature of Types

This conversation started in the Go Language page. Next time it's needed to be applied to a different language, hoist it here.

Go Language | The Primitive vs. Non-Primitive Nature of Types

Static Typing vs Dynamic Typing

For a statically typed system, the variables and expressions always have a specific type, and that type cannot be changed. This is where "static" comes from: a variable will always have the same type. The type is known at compile-time. The compiler uses this information to catch some classes of errors at compile time and produce low-level machine language that typically runs faster. C, C++, Java and Go are statically typed languages, and much of the code written in such language is used to declare types.

Dynamically typed languages are convenient, because there are no intermediate steps between writing the code and executing it. A dynamically typed language, also called a scripting language, do not forces the programmer to declare the type of a variable before using them. Dynamic languages are not compiled, but interpreted. However certain types of errors cannot be caught until the program executes. For statically typed languages, many of these errors are caught at the compilation phase. On the downside, static languages usually comes with a great deal of ceremony around everything that happens in the program (heavy syntax, type annotations, complex type hierarchies). Python is a dynamically typed language.

Strong Typing vs Loose Typing

In a strong typed language the type of an instance does not change, even if the value is mutable. Every object has a specific type, or class. Implicit conversions will occur only in certain permitted circumstances, like converting an int to float when it is divided with a float, but not as a general rule.

In a weakly typed language, an object of a certain type might get implicitly converted (or cast) to an object of a different type.

Python is a strongly typed language. Go is also a strongly typed language.

Type Safety

https://en.wikipedia.org/wiki/Type_safety

Type safety is the extent to which a programming language discourages or prevents type errors. Type enforcement can be static, exercised at compile-time, or dynamic, associated type information with values and detecting type errors at run-time, or both. Java and C# are examples of type-safe languages.

Type Systems

Scoping

Static and dynamic scoping: https://www.geeksforgeeks.org/static-and-dynamic-scoping/

Duck Typing

Go has duck typing.


Is duck tying a good thing? Is this a good thing? As far as I can tell, I can't say whether a specific type implements an interface, short of browsing all methods in the package, looking for receivers of that specific type. The compiler does that easily, but I don't. This does not help code readability.

Metaprogramming

Metaprogramming is writing code that manipulates other code, or even itself.

Object-Oriented Programming

Object-Oriented Programming

Functional Programming

Functional Programming

Concurrent (Parallel) Programming

Concurrent (Parallel) Programming

Formal Languages and Translators

Formal Languages and Translators

Number Representation in Computers

Number Redpresentation in Computers

Domain Specific Languages (DSL)

Domain Specific Languages

Reflection and Metaprogramming

Reflection and Metaprogramming