Archived

This topic is now archived and is closed to further replies.

Grizwald

Strong vs. Weak Typing

Recommended Posts

what are the advantages of a strong typing system vs a weaker system. I consider a langage like c++ to have strong typing, and BASIC to have weaker typing. that could be a bad assumption. so feel free to correctly. also, which is better for game programming? thanks.

Share this post


Link to post
Share on other sites
Umm.. I don''t really understand by what you mean by having a strong typing system, but for begginning game programming, I think basic is good, however, if you want to get into the nitty gritty of game programming, c++ is definetly better :D.

Share this post


Link to post
Share on other sites
I think he means the difficulty to keyboard without two-finge-typing.

There''s no town drunk here, we all take turns.

Share this post


Link to post
Share on other sites
Umm... OK, for all of you that son''t know, strong typing is when a language enforces types, like int, etc. In c++ you can covnert an int to a double simply with double whatever= int whatever, whereas in java you need to use special functions. It''s really a matter of taste, and C++ is in the middle.

-~-The Cow of Darkness-~-

Share this post


Link to post
Share on other sites
cows,

sadly, your one example (int-to-double) is allowed in C++ There are some implicit casts still in the language. Also, in Java for native types you use casts as well (not "special functions").

Regards,
Jeff

[edited by - rypyr on May 5, 2003 9:06:02 PM]

Share this post


Link to post
Share on other sites
quote:
Original post by rypyr
cows,

sadly, your one example (int-to-double) is allowed in C++ There are some implicit casts still in the language. Also, in Java for native types you use casts as well (not "special functions").

Regards,
Jeff

[edited by - rypyr on May 5, 2003 9:06:02 PM]


I said it was allowed. And java''s casts are special functions, aren''t they?

-~-The Cow of Darkness-~-

Share this post


Link to post
Share on other sites
strong versus weak typing, IMHO, is something of a misnomer; as CANE so adroitly pointed out, "strongly typed" languages such as C often allow quite a bit of type coercion. I think a better distinction would be "variable typing" versus "object typing". With the former, a particular variable assumes a particular type, which is known at compile time and which persists thoughout the variable''s scope. With object typing, a variable has no particular type of its own, but rather stores an object, which has its own type.

I prefer weakly typed scripting languages... easier for beginning programmers to understand. In languages such as C, however, strong typing can lead to greater efficiency, especially in function calls.


How appropriate. You fight like a cow.

Share this post


Link to post
Share on other sites
I said it was allowed. And java''s casts are special functions, aren''t they?

No. You can say something like (int)(2.5). You can do the same thing in C++.

Share this post


Link to post
Share on other sites
quote:
Original post by yaroslavd
I said it was allowed. And java''s casts are special functions, aren''t they?

No. You can say something like (int)(2.5). You can do the same thing in C++.


Oh, really? I always used something like double.toint (I don''t remember exactly).. oh well



-~-The Cow of Darkness-~-

Share this post


Link to post
Share on other sites
Oh, really? I always used something like double.toint (I don''t remember exactly).. oh well

Yeah, you COULD do that, but you don''t need to. You could just do it the way I described.

Share this post


Link to post
Share on other sites
quote:
Original post by yaroslavd
Oh, really? I always used something like double.toint (I don''t remember exactly).. oh well

Yeah, you COULD do that, but you don''t need to. You could just do it the way I described.


That''s good to know... I honestly never knew that.

-~-The Cow of Darkness-~-

Share this post


Link to post
Share on other sites
Sorry cows, misread your point about double-int.

What you are takling about in Java is the native data type wrapper classes like Double (for doubles) and Integer (for ints) that you use when needing a primitive data type to be an Object.

Share this post


Link to post
Share on other sites
I prefer weaker typing. I like the duck philosophy: if it looks like a duck, walks like a duck, and smells like a duck... (i.e. if your object has the properties you use in a function, the function should work)

The advantage of a stronger typing system is that you never make accidental type errors like I made today in Python.

Today, while writing some code to interface with a raytracer, I gave it integer values, and so it screwed up really badly because it was using integer divison instead of floating point division. (Python''s roadmap includes replacing integer division with the division you might expect, so this won''t be a problem some time in the future)

I personally think strong typing is overrated.

Share this post


Link to post
Share on other sites
Strong typing is a good idea. It is much much easier to track down and fix compiler errors than it is to track down buggy program operation. Strong typing by no menas fixes everything, but it certainly doesn''t hurt.

Share this post


Link to post
Share on other sites
quote:
Original post by Flarelocke
I prefer weaker typing. I like the duck philosophy: if it looks like a duck, walks like a duck, and smells like a duck... (i.e. if your object has the properties you use in a function, the function should work)

The advantage of a stronger typing system is that you never make accidental type errors like I made today in Python.


Uhm, Python is strongly typed. It''s just not statically typed.

From [1]:

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 (more on how to do this later in this chapter).


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).

[1]http://diveintopython.org/odbchelper_funcdef.html

...and therefore I believe linux must be destroyed.

Share this post


Link to post
Share on other sites
and actually that explained alot.
thanks Arlid. (actually that the most in-depth response i''ve seen you post. usually they''re just one-liners)

also what is your sig, supposed to be implying?
that you don''t like linux?

Share this post


Link to post
Share on other sites
quote:
Original post by Alpha_ProgDes
also what is your sig, supposed to be implying?
that you don''t like linux?


Sadly, you''d never hear a question like that if someone had a sig saying Windows should be destroyed.

Share this post


Link to post
Share on other sites
quote:
Original post by Alpha_ProgDes
and actually that explained alot.
thanks Arlid. (actually that the most in-depth response i''ve seen you post. usually they''re just one-liners)



back handed compliment or what?

Share this post


Link to post
Share on other sites
quote:
Original post by Alpha_ProgDes
thanks Arlid. (actually that the most in-depth response i''ve seen you post. usually they''re just one-liners)

Actually, if you take out the quote, the URL and the signature, it was a one-liner.

...and that is why I believe linux must be destroyed.

Share this post


Link to post
Share on other sites
quote:
Original post by Grizwald
what are the advantages of a strong typing system vs a weaker system.

Erm... it ensures freedom from type errors? Is this a trick question?

Share this post


Link to post
Share on other sites
quote:
Original post by Arild Fines
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).



Ah, I see. The other three categories I''ve all encountered, but I''ve never encountered a "weakly typed language" by that taxonomy. Seems rather stupid to me.

Share this post


Link to post
Share on other sites