Homework help! -- ideas for and against typeless languages

Please compose all posts in Emacs.

Moderators: phlip, Moderators General, Prelates

deeder
Posts: 14
Joined: Sat Dec 29, 2007 9:58 pm UTC

Homework help! -- ideas for and against typeless languages

Postby deeder » Mon Feb 04, 2008 2:06 am UTC

I'm in a little over my head in a programming languages class, but I am determined to stick it out. My programming experience is pretty limited and although I find this class very interesting I find myself pretty lost with some of the concepts.

So, the question is:

What are the arguments both for and against the idea of a typeless language?

I've never used a typeless language. So here's a (dumb?) question, once you declare a variable can it be used for anything? Eg: could be used to hold a character then later in the program an integer?

qbg
Posts: 586
Joined: Tue Dec 18, 2007 3:37 pm UTC

Re: Homework help! -- ideas for and against typeless languages

Postby qbg » Mon Feb 04, 2008 3:56 am UTC

Are you sure you are talking about a typeless language and not a dynamically typed language?

EvanED
Posts: 4331
Joined: Mon Aug 07, 2006 6:28 am UTC
Location: Madison, WI
Contact:

Re: Homework help! -- ideas for and against typeless languages

Postby EvanED » Mon Feb 04, 2008 4:16 am UTC

qbg wrote:Are you sure you are talking about a typeless language and not a dynamically typed language?

In this context, I suspect they are one and the same.

To some type theorists, "type" is defined more strictly than in popular use. Specifically, it's a static property of a variable, which makes "dynamically-typed" an oxymoron. Something like Lisp or Python would then be described as "untyped," while something like C would be "weakly typed" and something like ML "strongly typed."

I personally think the term "dynamically typed" makes sense for a number of reasons and is useful even if weren't technically correct for more, but there are still plenty of people who use "untyped" to refer to what most call "dynamically typed."

Rysto
Posts: 1460
Joined: Wed Mar 21, 2007 4:07 am UTC

Re: Homework help! -- ideas for and against typeless languages

Postby Rysto » Mon Feb 04, 2008 4:51 am UTC

The only thing I could possibly consider a true "typeless" language would be the lambda calculus, but really there's only one type in that language.

It's possible that the assignment is talking about assembly language, where everything is a string of bits and the programmer decides the interpretation.

Karrion
Posts: 92
Joined: Fri Jun 22, 2007 12:14 am UTC
Location: Melbourne, AU

Re: Homework help! -- ideas for and against typeless languages

Postby Karrion » Mon Feb 04, 2008 7:42 am UTC

To answer the OP's second question, yes. So in a 'typeless' or 'weakly typed' or 'dynamically typed' (take your pick of terminology), you can do something like:

Code: Select all

$foo = 1;
$foo = "foo";
$foo = new Object("bar", 3);


By contrast, in a strongly typed language, that would be an error, because an numeric variable could only ever hold a number, a string variable could only contain a string, and so on.

EvanED
Posts: 4331
Joined: Mon Aug 07, 2006 6:28 am UTC
Location: Madison, WI
Contact:

Re: Homework help! -- ideas for and against typeless languages

Postby EvanED » Mon Feb 04, 2008 10:31 am UTC

Karrion wrote:To answer the OP's second question, yes. So in a 'typeless' or 'weakly typed' or 'dynamically typed' (take your pick of terminology), you can do something like [snip]

One more point on terminology... the definitions of strong and weak typing are unagreed upon at best.

Sometimes strong and weak typing are synonymous with static and dynamic typing, but needn't be so.

For instance, the same people who argue that "dynamically typed" would disagree with that definition (because then "weakly typed" would also be an oxymoron.) Instead they would use how much type checking is done statically. For instance, ML would definitely be a strongly typed language. Something like C, where you can take a pointer to an int and assign it to a variable of type double*, would be weakly typed.

If you move on and accept that the term "dynamically typed" makes sense, this definition is still helpful, as static vs. dynamic and strong vs. weak become orthogonal axes, and in fact all four combinations are possible, at least if you use this definition of weakly typed. [Digression: Firefox's dictionary has "combination" but not "combinations". WTF? How does Mozilla produce a generally very nice browser that comes with such a shitty dictionary?]

For instance, a lot of people would argue that Perl is a weakly typed language, because there are a ton of conversions that it will do without explicitly being asked. For instance, you can add a string to a number; e.g. "2" + 2 will yield 4. (A lot more would argue that these conversions are always guaranteed to work correctly, so Perl is strongly typed. More on that definition in a second.)

Using this definition of weak typing (that the "system" -- be it an interpreter or compiler -- will allow "a lot" of conversions), we can categorize languages along both axes:

Code: Select all

         |   Strong   |   Weak
-----------------------------------
Static   |  ML        |  C
         |  (C++)     |
-----------------------------------
Dynamic  |  Python    |  Perl   
         |  Lisp      |  Javascript


But even with this definition, things aren't crystal clear. I put C++ in the strong typing column, but probably most PL people wouldn't. It still exposes some unsafe casting operations, and more to the point, there are a lot of things that are easy to do that break type safety. Buffer overruns for instance. (Even static vs. dynamic isn't crystal clear. If it goes in one of the categories, it's clearly static, but dynamic_cast gives it a small measure of dynamic type checking.) So strong vs. weak is a continuum.

One other definition for strong vs. weak typing is whether type errors can arise during execution. For instance, if I assign the wrong kind of pointer in C, I can begin a chain of memory corruption that leads to a crash, I can get incorrect results, etc.; the type system doesn't do anything to say "hey, this block of bits is an int*, not a double*". But in Perl, the expression "2" + 2 causes the runtime to do a string to integer conversion: it doesn't interpret the bits of "2" as if it were an integer. And in this sense, Perl would be strongly typed.

The author of this mailing list post counted 8 different, incompatible definitions of strong vs. weak typing, and pages claiming that Lisp, Perl, C, and C++ were strongly and weakly typed. (Many of the definitions don't vary much. I can't tell what the difference is between 1 and 2 for instance. 1 & 2 roughly correspond to strong = static and weak = dynamic, 3 corresponds to my final definition, 4 & 5 roughly correspond to the first definition I gave.)

I guess my point is the following:
  • Avoid using "strong" and "weak" to describe type systems (unless you are in a class and that's what the instructor uses, and he or she gives you a solid definition; then use in the context of that class). The terms are too ambiguous. If you tell me you like your favorite language because it is strongly-typed, that tells me almost nothing because I don't know which of the several common definitions you are using.
  • If someone else uses the term "strong" or "weak", make sure you understand what they mean.

qbg
Posts: 586
Joined: Tue Dec 18, 2007 3:37 pm UTC

Re: Homework help! -- ideas for and against typeless languages

Postby qbg » Mon Feb 04, 2008 4:02 pm UTC

Answering the OP's question, dynamically typed languages are good for rapid prototyping but are less efficient.

If your language of choice is dynamically typed but allows for type declarations (*cough* Common Lisp), then you could view static typing as being premature optimization. :D

EvanED
Posts: 4331
Joined: Mon Aug 07, 2006 6:28 am UTC
Location: Madison, WI
Contact:

Re: Homework help! -- ideas for and against typeless languages

Postby EvanED » Mon Feb 04, 2008 6:02 pm UTC

There's a whole thread on this (probably in the religious wars forum, and probably called static vs. dynamic typing or something similar) where you can get good examples.

Personally, my views are as follows:

Dynamic typing pros:
- Quicker to build
- More flexible
- Easier to change to do something else

Static typing pros:
- Allows more compiler optimization
- Allows the compiler to check more things for you

Dynamic typing is good for small programs, but I think that if you want to do a larger project or one where stability is important, static typing is the way to go. If I try to add a vector to a number in C++, the compiler will growl at me. I know that if I call o.foo(), the object o refers to has a foo() method. These are not true of a dynamically typed language, which means you can get method not found exceptions, incompatible type exceptions, etc. If you talk to people who program in ML, a common thing they will say is that it's a pain in the ass to get something to compile because its type system is so strict, but once you do, there is much less traditional debugging than in other languages.

deeder
Posts: 14
Joined: Sat Dec 29, 2007 9:58 pm UTC

Re: Homework help! -- ideas for and against typeless languages

Postby deeder » Mon Feb 04, 2008 9:07 pm UTC

Thanks for all the replies! The whole typeless/strong typed/ weak typed etc. debate sure complicates things.

EvanED, I'll try to find the other thread.. I did a quick search but didn't come up with anything before I started this thread.

Thanks again everyone :mrgreen:



Return to “Religious Wars”

Who is online

Users browsing this forum: No registered users and 6 guests