What is the difference between the concept of static and dynamic typing and the concept of strongly and weakly typed?

Asked

Viewed 2,097 times

7

There is some confusion about the concept of programming languages with static and dynamic typing and the concept of strongly and weakly typed programming languages.

For example, in my opinion Python is a language with dynamic typing as I can assign any value to a variable (x in the example):

>>> x = 1
>>> x = "teste"
>>>

However, Python is also a strongly typed language because I can’t do something like:

>>> x = "0"
>>> x += 1
Traceback <most recent call last>:
   File "<stdin>", line 1, in <module>
TypeError: Can't covert 'int' object to str implicitly

Could someone explain it to me better?

  • 3
  • 3

    I think we can consider duplicate. Leo Ribeiro, the answer on this link clarifies your doubt?

  • I don’t think @bfavaretto, because the link’s own answer says: The definition of these terms does not help much and to say that a language is weakly or strongly typed uniquely is also not usually true.

  • 2

    But isn’t that just the answer? What’s missing there to clear up your doubt?

  • 2

    @Leoribeiro I consider duplicate. Or it is not clear what you want. There is all the information that I think is necessary to clarify the topic. If you have something more specific that still has doubt, be specific in the question. The answer says this because this is it. Things are not black and white. Languages are not pure. Time it can behave one way, time another.

  • I understand, gentlemen. I believe you can withdraw then.

  • 1

    We don’t erase duplicates, we just put this sign up pointing to another question. Duplicates are seen as alternative ways to get answers. Keeping duplicates means giving people more chance to find the answers they need via search engines. Oh, and welcome to the site! :)

  • I could even answer here and get more dots, but I’d practically copy a part of what’s there :)

Show 3 more comments

1 answer

4

Liskov and Zilles defined strongly typed languages as those where an object, when passed from one function to another, must have type compatible with that declared in the function receiving the object.

Static languages are languages that have static typing, where the type of a variable cannot change. A static language is not necessarily strong typing where the type nay can be interpreted in different ways.

In C, for example, which is static language, we can interpret a data in a memory region in different ways when we use pointers.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.