Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add difference between dynamically and statically typed #25

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/Markdowns/Catalog.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,31 @@ 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: "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",
},
],
Node: [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# 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 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.

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.
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.

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.

Here is a quick example of strong typing:

```Python
a = 1
b = "1"

print(a + b)
```

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

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 weak typing:

```javascript
a = 1
b = "1"

console.log(a + b);
```

Doesn't cause an error and it actually gives 11.