The Cache: Technology Expert's Forum
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
May 24, 2012, 02:07:45 AM

Login with username, password and session length


Pages: [1]
  Print  
Author Topic: Language typing breakdown  (Read 317 times)
isthisthingon
Global Moderator
Lifer
*****
Offline Offline

Posts: 2873



View Profile
« on: February 01, 2010, 04:12:03 PM »

While reading about Python I ran across something that made me stop and think.  Python is considered to be a “strongly typed” language.  Well perhaps I’m alone in missing this subtle yet critical distinction.  However, once I realized that Python is strongly typed as well as dynamically typed, I wanted to share what I read.

The four categories of language typing are:  static/dynamic and strong/weak.  Although I can't recall a language that is both statically typed and weakly typed, it is possible given the definitions.  So here's a breakdown and clarification of each category (From “Dive Into Python"):

  • Statically typed language: A language in which types are fixed at compile time. Most statically typed languages enforce this by requiring you to declare all variables with their datatypes before using them. Java and C are statically typed languages.
  • Dynamically typed language: A language in which types are discovered at execution time; the opposite of statically typed. VBScript and Python are dynamically typed, because they figure out what type a variable is when you first assign it a value.
  • Strongly typed language: A language in which types are always enforced. Java and Python are strongly typed. If you have an integer, you can't treat it like a string without explicitly converting it.
  • Weakly typed language: A language in which types may be ignored; the opposite of strongly typed. VBScript is weakly typed. In VBScript, you can concatenate the string '12' and the integer 3 to get the string '123', then treat that as the integer 123, all without any explicit conversion.

So Python is both dynamically typed (because it doesn't use explicit datatype declarations) and strongly typed (because once a variable has a datatype, it actually matters).
Logged

I would love to change the world, but they won't give me the source code.
nop_90
Global Moderator
Lifer
*****
Offline Offline

Posts: 2203


View Profile
« Reply #1 on: February 02, 2010, 09:47:18 PM »

It is a "strongly dynamically typed" language Smiley
If you look how u make "C" extensions in python then this all makes sense.

Nutshell view (not accurate just for illustration).
Every data type in python inherites from a "C" structure.
which is like this
struct pythonObject :
    type -> type of the object
    data -> what object contains.

you then can make ur own data types, add functions etc.
So python has a string type that inherits off pythonObject.

when u do operations if datatypes do not match or can not be converted an exception occurs.
(little more complex then that but u get the idea Smiley)
   

In contrast TCL is a weakly typed language. All data types are a string which are converted to the appropriate type depending on the operation. There is advantages to this when passing data back and forth from C, it is just a string.

Logged
isthisthingon
Global Moderator
Lifer
*****
Offline Offline

Posts: 2873



View Profile
« Reply #2 on: February 03, 2010, 09:58:46 AM »

Thanks nop!
Logged

I would love to change the world, but they won't give me the source code.
Pages: [1]
  Print  
 
Jump to:  

Perkiset's Place Home   Best of The Cache   phpMyIDE: MySQL Stored Procedures, Functions & Triggers
Politics @ Perkiset's   Pinkhat's Perspective   
cache
mart
coder
programmers
ajax
php
javascript
Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks


Valid XHTML 1.0! Valid CSS!