When should weak types be avoided?

When should weak types be avoided? Weak types are not encouraged in large projects? If the left side is strongly typed, how would this be an exception to the rule?

   int i = 5
   string sz = i
   sz = sz + "1"
   i  = sz

Does any language support the similar syntax of the above? Tell me more about the pros and cons for weak types and situations.

+3
source share
7 answers

I think that you are misleading a "weak set" with a "dynamic typing".

The term "weak typing" means "not strongly typed", which means that the value of the memory cell may vary depending on what it indicates that it should be.

C - . :

typedef struct
{
    int x;
    int y;

} FooBar;

FooBar foo;
char * pStr = &foo;
pStr[0] = 'H';
pStr[1] = 'i';
pStr[2] = '\0';

, FooBar , .

. , , , , FooBar , FooBar.

#, Java, Lisp, Java Script, Ruby - , . .

" ", , , " ", , . " " " " - . , Lisp " " , "C" " ".

, , " " , . "var" # . , , , .

, :

, , , , .

:

3 :

  • A

, intellisence , - , . "a". , "a" , , ".". , , . , .

, , , . .

. , . , , , , , . , , .

" ", , Microsoft SAL ( ), .

, , .

:

, , . , . Ruby on Rails - .

, , . .

, . .

:

:

  • "" IDE
  • . , Ruby.

:

- . . , , , .

:

- .

, . , , , "ISerializable". , , , , .

.

, .

, . .

+16

- . , .

, COM-, , , , , . Visual Basic, , Microsoft ETC (Extended Type Conversion) Evil Type Cast.

. - , . var, # , LINQ.

, , . . C. , .

, , , . , .

+3

. , , , - , voodoo.

, C ( , , , ), , PHP Perl ( ).

+2

"

? ? , ?

int i = 5 string sz = i sz = sz + "1" i = sz

- ? .

"

, .

++ -, " ", , . :

[std::string str = "Hello World";][1]

, ( T B - , )

.

T& T::operator= ( const B s );

, , , , - , , - -

B& T::operator= ( const T s);

++ , , , , , , void. , , .

, , , , . , , , , , , , .. - , , , , .

, , -, (.. - UNIX). JavaScript Shell Script .

, , , harware, Assembly, , , , dword, qword.

, .

+2

, , , - , . , , . , , , float?

+1

- ?

Perl . , "5" + "1" 6. , : "5" + 1 "51" "6"? Perl , + .

, ( ), .

+1

ASP/VBScript " ", .

, . , .

:

'Config 
    Dim pass
    pass = "asdasd"


If NOT pass = Request("p") Then
Response.Write "login failed"
REsponse.End()
End If

, , , , != ( ). , , .

, , , .

, , ​​ , .

0

Source: https://habr.com/ru/post/1703994/


All Articles