From 645c82ce5c4330686e94e1641c9de4c9cf5fd7e6 Mon Sep 17 00:00:00 2001 From: endormi <39559256+endormi@users.noreply.github.com> Date: Tue, 16 Feb 2021 19:17:40 +0200 Subject: [PATCH 1/4] (WIP) Add difference between dynamically and statically typed --- src/Markdowns/Catalog.js | 7 +++ ...etween-statically-and-dynamically-typed.md | 50 +++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 src/Markdowns/difference-between-statically-and-dynamically-typed.md diff --git a/src/Markdowns/Catalog.js b/src/Markdowns/Catalog.js index 5ea6c5b..29a9f8a 100644 --- a/src/Markdowns/Catalog.js +++ b/src/Markdowns/Catalog.js @@ -37,6 +37,13 @@ export const Catalog = { fileName: "10x-developer", author: "Natedeploys", }, + { + title: "The difference between statically and dynamically typed", + description: "The difference between statically and dynamically typed and also strongly typed and weakly typed", + category: "Crafstmanship", + fileName: "difference-between-statically-and-dynamically-typed", + author: "Endormi", + }, ], Node: [ { diff --git a/src/Markdowns/difference-between-statically-and-dynamically-typed.md b/src/Markdowns/difference-between-statically-and-dynamically-typed.md new file mode 100644 index 0000000..c7cb7f2 --- /dev/null +++ b/src/Markdowns/difference-between-statically-and-dynamically-typed.md @@ -0,0 +1,50 @@ +# The difference between statically and dynamically typed + +We will also be talking about the difference between strongly typed and weakly typed. + +## Statically Typed + +Statically typed languages do the type checking which is the process of verifying and enforcing the constraints of types at compile-time. +The process of verifying and enforcing the constraints of types meaning that variable types are static, so that once you declare a var to a type, you can't change it. +It's because statically typing is associated with the variable rather than the value. + +Examples of Statically typed languages: C, C++ and Java + +## Dynamically Typed + +Dynamically typed languages do the type checking at run-time which brings some performance cost. +In dynamically typed languages variables are dynamic, meaning you can change the value after you set the var to a type. + +Examples of Dynamically typed: Python, JavaScript, Ruby and scripting languages + +### Strongly typed + +Python is a language that is dynamically typed and strongly typed. + +Here is a quick example of strongly typing: + +```Python +a = 1 +b = "1" + +print(a + b) +``` + +This causes an concatenation error, because you can't add and an integer and string together. + +### Weakly typed + + A string containing only digits doesn't magically become a number, as may happen in weakly typed languages like JavaScript and Perl. Every change of type requires an explicit type conversion (aka casting). + +JavaScript is dynamically typed and weakly typed. + +Here is a quick example of weakly typing: + +```javascript +a = 1 +b = "1" + +console.log(a + b); +``` + +Doesn't cause an error and it actually gives 11. From 3bc0f7f4922fc3d14a1fc87b2f406c5af80c9317 Mon Sep 17 00:00:00 2001 From: endormi <39559256+endormi@users.noreply.github.com> Date: Wed, 17 Feb 2021 16:45:25 +0200 Subject: [PATCH 2/4] Update Catalog.js --- src/Markdowns/Catalog.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Markdowns/Catalog.js b/src/Markdowns/Catalog.js index 29a9f8a..1e400f3 100644 --- a/src/Markdowns/Catalog.js +++ b/src/Markdowns/Catalog.js @@ -19,28 +19,28 @@ export const Catalog = { { title: "Evolve your Developer Game", description: "Software Developer/Engineer: Starting out and Evolving", - category: "Crafstmanship", + category: "Craftsmanship", fileName: "evolve-developer", author: "Shreyas Balachandran", }, { title: "Code Craftsmanship", description: "Three simple rules to become a better code craftsman", - category: "Crafstmanship", + category: "Craftsmanship", fileName: "code-craftsmanship", author: "Natedeploys", }, { title: "10x Developers", description: "10x Developer attributes, road to success", - category: "Crafstmanship", + category: "Craftsmanship", fileName: "10x-developer", author: "Natedeploys", }, { title: "The difference between statically and dynamically typed", description: "The difference between statically and dynamically typed and also strongly typed and weakly typed", - category: "Crafstmanship", + category: "Craftsmanship", fileName: "difference-between-statically-and-dynamically-typed", author: "Endormi", }, From f2d81df03ed86192e06d50c8d10ca5c96431e3ff Mon Sep 17 00:00:00 2001 From: endormi <39559256+endormi@users.noreply.github.com> Date: Wed, 17 Feb 2021 17:02:03 +0200 Subject: [PATCH 3/4] Update strongly typed and weakly typed explanation --- ...etween-statically-and-dynamically-typed.md | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/Markdowns/difference-between-statically-and-dynamically-typed.md b/src/Markdowns/difference-between-statically-and-dynamically-typed.md index c7cb7f2..6a123ae 100644 --- a/src/Markdowns/difference-between-statically-and-dynamically-typed.md +++ b/src/Markdowns/difference-between-statically-and-dynamically-typed.md @@ -5,23 +5,23 @@ We will also be talking about the difference between strongly typed and weakly t ## Statically Typed Statically typed languages do the type checking which is the process of verifying and enforcing the constraints of types at compile-time. -The process of verifying and enforcing the constraints of types meaning that variable types are static, so that once you declare a var to a type, you can't change it. +The process of verifying and enforcing the constraints of types meaning that variable types are static, so that once you declare a variable to a type, you can't change it. It's because statically typing is associated with the variable rather than the value. -Examples of Statically typed languages: C, C++ and Java +Examples of Statically typed languages: C, C++ and Java. ## Dynamically Typed Dynamically typed languages do the type checking at run-time which brings some performance cost. -In dynamically typed languages variables are dynamic, meaning you can change the value after you set the var to a type. +In dynamically typed languages variables are dynamic, meaning you can change the value after you set the variable to a type. -Examples of Dynamically typed: Python, JavaScript, Ruby and scripting languages +Examples of Dynamically typed: Python, JavaScript, Ruby and scripting languages. ### Strongly typed Python is a language that is dynamically typed and strongly typed. -Here is a quick example of strongly typing: +Here is a quick example of strong typing: ```Python a = 1 @@ -30,15 +30,23 @@ b = "1" print(a + b) ``` -This causes an concatenation error, because you can't add and an integer and string together. +This causes an concatenation error, because you can't add an integer and string together. + +In strongly typed languages a string containing only digits doesn't magically become a number. + +A quick example on how to fix the concatenation error: + +```Python +print(a + int(b)) +``` ### Weakly typed - A string containing only digits doesn't magically become a number, as may happen in weakly typed languages like JavaScript and Perl. Every change of type requires an explicit type conversion (aka casting). +In weakly typed languages you don't need to specify types, but the result might not be what you wanted, see the example below. JavaScript is dynamically typed and weakly typed. -Here is a quick example of weakly typing: +Here is a quick example of weak typing: ```javascript a = 1 From 7f624defdf3faca26893a781cf2e8310725aec41 Mon Sep 17 00:00:00 2001 From: endormi <39559256+endormi@users.noreply.github.com> Date: Sun, 21 Mar 2021 11:38:09 +0200 Subject: [PATCH 4/4] Add examples --- src/Markdowns/Catalog.js | 4 ++-- ...between-statically-and-dynamically-typed.md | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/Markdowns/Catalog.js b/src/Markdowns/Catalog.js index 1e400f3..a7e90b9 100644 --- a/src/Markdowns/Catalog.js +++ b/src/Markdowns/Catalog.js @@ -38,8 +38,8 @@ export const Catalog = { author: "Natedeploys", }, { - title: "The difference between statically and dynamically typed", - description: "The difference between statically and dynamically typed and also strongly typed and weakly typed", + title: "Difference between statically and dynamically typed", + description: "Difference between statically and dynamically typed and also strongly typed and weakly typed", category: "Craftsmanship", fileName: "difference-between-statically-and-dynamically-typed", author: "Endormi", diff --git a/src/Markdowns/difference-between-statically-and-dynamically-typed.md b/src/Markdowns/difference-between-statically-and-dynamically-typed.md index 6a123ae..df33398 100644 --- a/src/Markdowns/difference-between-statically-and-dynamically-typed.md +++ b/src/Markdowns/difference-between-statically-and-dynamically-typed.md @@ -10,6 +10,15 @@ It's because statically typing is associated with the variable rather than the v Examples of Statically typed languages: C, C++ and Java. +A quick example of statically typed: + +```Java +int a = 1; +a = "foo"; +``` + +This causes an error, because a is supposed to be an integer only. + ## Dynamically Typed Dynamically typed languages do the type checking at run-time which brings some performance cost. @@ -17,6 +26,15 @@ In dynamically typed languages variables are dynamic, meaning you can change the Examples of Dynamically typed: Python, JavaScript, Ruby and scripting languages. +A quick example of dynamically typed: + +```python +a = 1 +a = "foo" +``` + +However doesn't give an error. + ### Strongly typed Python is a language that is dynamically typed and strongly typed.