Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I'm trying to illustrate the differences between the four different type systems -- static vs. dynamic typing and weak vs. strong typing.

  • Dynamic + weak = JavaScript
  • Dynaimc + strong = Python
  • Static + strong = Java (is there a good purely interpreted language for this? The Java "compiler" can be annoying without a framework like Ant of Maven)
  • Static + weak = ???

For static + weak the one that is most immediately apparent is C++, with operator overloading, pointer arithmetic, and, frankly, the ability to treat almost any data type as some form of number, it seems like it would be a very clear example of static typing and weak typing. But, it is also incredibly complicated, especially if I want to teach a beginner.

What alternative teaching languages are there for beginners which are both statically and weakly typed? Ideally something which is easy to install and get running with minimal effort? (Even more ideally, something which supports OOP in some form?)

share|improve this question
    
"weakly typed" doesn't really have a generally agreed definition, so this is hard to answer. –  Michael Borgwardt Jul 25 '11 at 14:08
    
It seemed like that was the case (I generally only ask a SE question if I really have no idea how to approach a question), but I was still hoping to have some sort of example. –  cwallenpoole Jul 25 '11 at 14:15
    
@Michael Are you thinking that this might be better as an "Exercise left to reader?" –  cwallenpoole Jul 25 '11 at 14:16
    
Example for what? If you can't define your goal, how do you know, whether an example fits? Fits to what? –  user unknown Jul 25 '11 at 14:28
    
More like "not a useful classification". It's used for at least two completely different things: treating memory just as a bunch of bytes and types as an instruction how to interpret it that can be switched at will (that's what C does), or having implicit semantic type conversions (like JavaScript). Discussions about what it means tend to devolve into everyone arguing against their favourite language being considered "weakly typed". –  Michael Borgwardt Jul 25 '11 at 14:32
show 7 more comments

4 Answers

up vote 13 down vote accepted

I vote for C.

It's vastly simpler than C++, and it clearly shows what's happening under the hood, because it doesn't have any hood! :-)

share|improve this answer
1  
But - C compared with Java is not the same as Javascript compared with Python. Javascript doesn't allow you to easily subvert the type system the way that C does AFAIK. When C was called weakly typed in the past, it was usually in comparison with Pascal-family languages that needed more (sometimes all) casts to be explicit, and that may apply to Javascript vs. Python - IIRC, Javascript will implicitly translate strings to numbers etc, where Python won't. But Javascript doesn't have C-style hacking-the-in-memory-representation type-punning that I remember. –  Steve314 Jul 25 '11 at 16:11
    
I consider C weakly typed because of automatic casts, not because you can do whatever you want with memory; that's an added bonus :-) –  Javier Jul 25 '11 at 19:10
    
thinkig about it, the non-safety of C memory could be seen more as some primitive form of dynamic typing than of weak typing. –  Javier Jul 25 '11 at 19:13
add comment

C is the classic example of a statically and weakly typed language. Also, in response to your question about Java, see http://stackoverflow.com/questions/376611/why-interpreted-langs-are-mostly-ducktyped-while-compiled-have-strong-typing for examples of interpreters for statically typed languages.

share|improve this answer
add comment

Visual Basic (the one with V 6.0, not the VB.NET) has a cast in stone set of types, which is nearly impossible to tell from each other, when you read the code. It might fit perfectly into your matrix.

C may not be completely static (depending on your definition of static language) because of typedef the keyword.

share|improve this answer
    
typedef is static; it's even more static than Java classes. –  Javier Jul 25 '11 at 19:12
    
I fail to follow up on it, because there is no definitive language to define the languages. What did Christopher asked about languages being "static" is a mystery –  user7071 Jul 25 '11 at 19:20
add comment

What about Objective-C, it's a superset of C++ and is way more easy than C and C++ (well, depends on what you're coding, of course). Besides that, you can code iOS-apps using it, so it's probably more enjoyable to learn =)!

share|improve this answer
    
Most of Obj-C's weak-typedness comes from its dynamic features, so I don't think it serves as a good 'canonical' example of weak and static language. –  Javier Jul 25 '11 at 21:25
    
nitpicking: Obj-C is a superset of C, Obj-C++ is a (little used) superset of C++. –  Javier Jul 25 '11 at 21:26
    
Now that's confusing :p. I always thought it to be a superset of C++, since you can use any C++-code (besides NSStrings and const char*s you can also use std::String. But you're right though :)! –  Tim van Elsloo Jul 26 '11 at 7:51
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.