Original Post
🔒 Locked
Type Checking
Advertisement
Hi,
Thanks for your reply.
I think that each character in the string would be converted to its numerical code and then the string would then be a long number. Then it would be a simple multiplication which would be writen into memory starting at the address of the float.
BD.
Thanks for your reply.
I think that each character in the string would be converted to its numerical code and then the string would then be a long number. Then it would be a simple multiplication which would be writen into memory starting at the address of the float.
BD.
If I hand you a wrench and then say give me that screwdriver back you would say what screwdriver, you gave me a wrench. Maybe I meant to say wrench and the wrench is what I want. Maybe I really meant screwdriver and I only thought I handed it to you so now I have to figure out what I did with it. Same basic idea. Rather than just blindly doing whatever you ask it checks that you are at least consistant in what you call things.
quote:
Original post by LilBudyWizer
If I hand you a wrench and then say give me that screwdriver back you would say what screwdriver, you gave me a wrench. Maybe I meant to say wrench and the wrench is what I want. Maybe I really meant screwdriver and I only thought I handed it to you so now I have to figure out what I did with it. Same basic idea. Rather than just blindly doing whatever you ask it checks that you are at least consistant in what you call things.
my brain hurts.....
"take a look around" - limp bizkit
www.google.com
Be aware, though, that a number of languages (SmallTalk, Perl, Python, Lisp, ...) use dynamic typing, where the type is not associated with the variable, but with the data itself.
Martee''s code would become something like
s = "Some Useless String";
i = 12345;
f = float(s * i);
And the computer would complain at run time that it can''t multiply a string by an int, or (if it can) that it cannot make a floating point number out of the result.
This adds a lot of flexibility to the language - whether you have a string, list or a number, if a+b is a valid operation, you can use it. The computer will catch the cases where you can''t, without you having to worry about specifying the type ''just so'' (often through a cosmic class hierarchy).
Of course, the downside is that many errors are not caught until run-time, while static typing would have caught them at compile time. In C++, templates let you get some of that flexibility back, by generating any type-based variant of a common code template with little intervention of the user (once you''ve beaten the template system into working the way you want it).
Programming being all about trade-offs, you''ve got to decide what approach works for you.
[ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | C++ FAQ Lite | Function Ptrs | CppTips Archive ]
[ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Free C++ IDE | Boost C++ Lib | MSVC6 Lib Fixes ]
Martee''s code would become something like
s = "Some Useless String";
i = 12345;
f = float(s * i);
And the computer would complain at run time that it can''t multiply a string by an int, or (if it can) that it cannot make a floating point number out of the result.
This adds a lot of flexibility to the language - whether you have a string, list or a number, if a+b is a valid operation, you can use it. The computer will catch the cases where you can''t, without you having to worry about specifying the type ''just so'' (often through a cosmic class hierarchy).
Of course, the downside is that many errors are not caught until run-time, while static typing would have caught them at compile time. In C++, templates let you get some of that flexibility back, by generating any type-based variant of a common code template with little intervention of the user (once you''ve beaten the template system into working the way you want it).
Programming being all about trade-offs, you''ve got to decide what approach works for you.
[ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | C++ FAQ Lite | Function Ptrs | CppTips Archive ]
[ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Free C++ IDE | Boost C++ Lib | MSVC6 Lib Fixes ]
This is offtopic, but Python allows multiplying strings by ints.
a = ''ni'' * 3
a is now ''ninini''
I''m hip because I say "M$" instead of "MS".
a = ''ni'' * 3
a is now ''ninini''
I''m hip because I say "M$" instead of "MS".
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement