SitePoint Sponsor

User Tag List

Results 1 to 12 of 12
  1. #1
    ********* Articles ArticleBot's Avatar
    Join Date
    Apr 2001
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Discussion thread for Introduction to Static and Dynamic Typing

    This is a dedicated thread for discussing the SitePoint article 'Introduction to Static and Dynamic Typing'

  2. #2
    Anonymous
    SitePoint Community Guest
    Good article concept, however, the written standard is not so good. There are some contradictions in the piece in the first few paragraphs.

  3. #3
    Anonymous
    SitePoint Community Guest
    uhhhh... maybe you'd know that the C language is really not a weak typed language.

  4. #4
    Dorsey
    SitePoint Community Guest
    This doesn't make sense: "Dynamic typed programming languages are those languages in which variables must necessarily be defined before they are used." Isn't it just the opposite? In fact, doesn't the subseqnet Python example (variable vs. varaible) contradict this statement?

    This is programming 101 stuff, and probably does need an explanation to those not schooled in computer languages. Unless I've missed something, more editorial care should be taken before publication.

  5. #5
    Eloff
    SitePoint Community Guest
    >uhhhh... maybe you'd know that the C language is really not a weak typed language.

    Not true. You may not be able to directly pass an int where a char * is required, but add (char*) in front of it and this will work. (you can also cast to void* first).

    C++ is strongly typed if you refrain from using C casts like that.

  6. #6
    jonathanmns
    SitePoint Community Guest
    I would be clearer if you would use term binding. The binding has to do with the time at which a variable is bound to a certain type either during compile time or runtime. Static type binding and dynamic type binding should be used then to refer to a programming language. Static type binding, implicit/explicit means that the type of variable must be defined before is used. This doesn't mean that is has to be initialized! The binding is done before run time and hence while compile time. So you could say that java, c/c++ are static type bound programming languages, because all their variables must be defined to be of a certain type before they are used. Dynamic type binding means that the type of a variable is not specified. Instead it is bound to be of a certain type when it is assigned a value in an assignment statement and hence during run time. These are mostly interpreted languages such as PHP, javascript and so on. Now for strong and weak typing you must refer first to the term type checking. So a strong type language is one where all the types of operands can be checked either at compile or run time. This all has to do with the ability to detect type errors and thus the reliability of a program and/or programming language. Weak type is the opposite of strong typing. One should also say that type checking either strong/ weak, depends on the definition of strong type checking meaning that a programming language is designed such that it can detect all types of its variables. You can say that java and C# are near strong type languages in the sense that implicit type errors can not go undetected, but then again the programmer can make explicit casts which will go undetected by the compiler. The issue of C/C++ being strong type languages is that according to the definition above, it is not a strong type language. The reason for this is that the language has union types which are not type checked. This type can be declare to of several types and is not checked with tags as in Ada. I must say that for certain topics it is difficult to classify programming languages as some people do, because their design lie on different trade-offs and decisions that take some of the best features to make a language flexible and thus being not all strong type checked. I think that you did not use the right terminology to address this topic. It is not a ď101 stuff as in one of the comments is mentionedĒ. Iíve just finished a semester course of Concepts of programming languages, this course prepare CS students for the compiler construction course next year. I can say that itís not 101 stuff because variable type binding and type checking are topics for which different design issues have to be taken into account such as implementation in specific computer architecture as trade-offs in reliability for flexibility of a purpose programming language to be designed. I think that it is clear that the writer of the article does not hold an academic degree in computer science and lack of knowledge about this topic in order to be able to write about it. The writer also fails to write a clear definition of the topics by using ambiguous definitions, as mentioned earlier in one of the comments: more editorial care should be taken before publication.


  7. #7
    SitePoint Member
    Join Date
    Jan 2005
    Location
    arley
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I would be clearer if you would use term binding.

    The binding has to do with the time at which a variable is bound to a certain type either during compile time or runtime. Static type binding and dynamic type binding should be used then to refer to a programming language. Static type binding, implicit/explicit means that the type of variable must be defined before is used. This doesn't mean that is has to be initialized! The binding is done before run time and hence while compile time.

    So you could say that java, c/c++ are static type bound programming languages, because all their variables must be defined to be of a certain type before they are used. Dynamic type binding means that the type of a variable is not specified. Instead it is bound to be of a certain type when it is assigned a value in an assignment statement and hence during run time. These are mostly interpreted languages such as PHP, JavaScript and so on.

    Now for strong and weak typing you must refer first to the term type checking. So a strong type language is one where all the types of operands can be checked either at compile or run time. This all has to do with the ability to detect type errors and thus the reliability of a program and/or programming language. Weak type is the opposite of strong typing. One should also say that type checking either strong/ weak, depends on the definition of strong type checking meaning that a programming language is designed such that it can detect all types of its variables. You can say that java and C# are near strong type languages in the sense that implicit type errors can not go undetected, but then again the programmer can make explicit casts which will go undetected by the compiler.

    The issue of C/C++ being strong type languages is that according to the definition above, it is not a strong type language. The reason for this is that the language has union types which are not type checked. This type can be declared to be of several types and is not checked with tags as in Ada.

    I must say that for certain topics it is difficult to classify programming languages as some people do, because their design lie on different trade-offs and decisions that take some of the best features to make a language flexible and thus being not entirely strong type checked.

    I think that you did not use the right terminology to address this topic. It is not a ď101 stuff as in one of the comments is mentionedĒ. Iíve just finished a semester course of Concepts of programming languages, this course prepare CS students for the compiler construction course next year. I can say that itís not 101 stuff because variable type binding and type checking are topics for which different design issues have to be taken into account such as implementation in specific computer architecture as trade-offs in reliability for flexibility of a purpose programming language to be designed.

    I think that it is clear that the writer of the article does not hold an academic degree in computer science and lacks of knowledge about this topic in order to be able to write about it. The writer also fails to write a clear definition of the topics by using ambiguous definitions, as mentioned earlier in one of the comments: more editorial care should be taken before publication.
    Last edited by jonathanmns; Nov 6, 2005 at 09:01.

  8. #8
    SitePoint Member
    Join Date
    Mar 2006
    Posts
    0
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Although this article explains the concepts quite well and quite correctly, the definitions in this article of static and dynamically typed languages are totally incorrect. Please do not use them for understanding these concepts.

    For example, the article says, "Static typed programming languages are those in which variables need not be defined before they're used". It also says C, C++ and Java are statically typed languages. These two statements are contradictory. Try using a variable in C without defining it! Even in static type languages, you need to define the variables before they are used.

    The difference between static and dynamic is easy to understand: in case of "static" type languages, the binding of the variable to the type is done at compile time. In dynamic languages, this binding is done at interpretation/run-time. That is, these terms differentiate on the basis of "when" the typing is checked.

    Static languages typically need you to declare every variable before you can use it, because that's how the compiler knows the type of the variable. Initialization of the variable can typically be done when it is declared. (for example, in C).

    In dynamically typed languages, the variable is not specified to be of a particular type before the program is actually run (or interpreted). Hence you can use variables without declaring them.

    Another way to understand this is that in case of language with static binding, it is possible to take a look at the program and tell what type of value every variable will hold any time this program is run. In case of dynamic languages, you can't do that. The types can change.

    Whereas static/dynamic refer to the "when" part of typing, strong/weak refer to the "how" part. This is a qualitative assessment of how strictly the typing of variables, mixing of types, and their conversions are enforced. Some languages enforce typing constraints more loosely than others, and so they are called weakly typed languages. For example, Java is strongly typed as compared to Perl.

    Obviously, it is easier to characterize a language as statically or dynamically typed (although inheritance and virtual functions create some special twists). Whether a language is strongly or weakly typed is, however, not absolute. Strong or weak typing are relative terms and hence, to some extent, subjective.
    Last edited by unmeshk; Mar 10, 2006 at 23:38.

  9. #9
    Bob
    SitePoint Community Guest
    The first paragraphs on static type vs dynamic type are incorrect - you've got them mixed up. You correctly say Java, C++/
    C are static typed, then say that means variable do NOT need to be defined before use. In the next you correctly identify dynamically typed languages and say variables must be defined first, also incorrect.

  10. #10
    Dynamodan
    SitePoint Community Guest
    The perl example given doesn't illustrate perl's dynamic or static typing characteristic. Declaring a variable with 'my' doesn't have anything to do with the type of variable it is, but rather the scope. In perl, a variable's scope is defined with the 'my' and 'our' keywords. The scope of a variable attaches it to a certain namespace within the program, like being global or confined to a sub or code block.

    The perl example given shows the error that is returned when using the strict pragma while not properly initializing the variable. The error message doesn't identify a problem with the variable type, but rather it's scope, it says 'requires a package name.' That's an indication of the variables scope, not type.

    Even though Perl is a dynamically typed language, the interpreter does return type errors if you try to do something with a variable that can't be done with that particular type. For example, if you try to perform a hash operation on a list, you will likely encounter the error 'can't coerce array into hash'. And obviously, variables containing code references will error out if you try performing operations on them that only apply to scalars, lists, or hashes--perl's built-in data types.

    Perl is probably considered dynamically typed because of how it "gracefully" handles type casting and converting.

  11. #11
    fizzbuzz
    SitePoint Community Guest
    I appreciate the effort it takes to write an article like this and the desire to help others understand. Unfortunately, this article is almost 100% wrong. Common Lisp, Scheme, and Erlang are all dynamically typed yet all require variables to be explicitly declared before use. Perl's "use strict" does not turn Perl into a statically typed language either. Static typing means the compiler (actually the type checker, which may or may not be part of a compiler) performs a mechanical, mathematical proof on the source code to ensure that certain "type constraints" can never be violated no matter what values are used at runtime. Nothing more, nothing less. Dynamically typed means that similar kinds of constraints are checked at runtime (dynamically), potentially at each usage site. Nothing more, nothing less. Note that in either case the exact kinds of constraints that are checked can vary a lot depending on the language. Requiring explicit declaration of variables is a completely orthogonal issue. A statically typed language with type inference could conceivably have automatic variable introduction and it would still be statically typed. As for "strong" and "weak", the terms are so overloaded that they've lost any value in any discussion. A short list of what they're frequently used to mean include: static vs dynamic; hard/impossible to bypass vs easy to bypass(e.g. casting in Java/C#); able to define complicated types (Haskell, ML, Scala) vs able to define only simple types (Java < 1.5); no implicit conversions vs lots of implicit conversions; memory safe (most mainstream languages) vs memory unsafe (C, C++). There are probably other definitions of those terms running around in the wild. It's best just to avoid the "strong" and "weak" altogether. But, please, please, let static and dynamic continue to mean the same concepts as in "static analysis" and "dynamic behavior."

  12. #12
    cameFromGoogle
    SitePoint Community Guest
    This is a baffling article. For example:

    "This analogy leads to the analogy we used above to define static and dynamic typing."

    So not only is the article wrong about static and dynamic languages but its full of verbose verbal diarrhoea.

    Scrap it and start again please.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •