4

변수 유형 (예 : PHP 및 Perl)을 선언 할 필요가없는 언어의 품질 약한 타이핑이나 동적 타이핑? 두 가지 용어로 머리를 감싸는 데 어려움을 겪고 있습니다.변수 유형을 선언 할 필요가없는 언어의 품질입니다. 약한 타이핑 또는 동적 타이핑의 예

동적/정적 입력은 유형 변환과 관련이 있습니다. 반면 약/강력한 입력은 변수의 감속과 관련이 있습니까? 따르면

+2

아니, 한 가지가 함께 할 수 없습니다 다른. C#에서는 "형식 유추"가 있으므로 형식을 선언 할 필요가 없습니다. 즉 문맥에 따라 유형이 무엇인지를 알 수 있습니다. 하지만 여전히 강력한 형식의 언어입니다. –

답변

3

: http://en.wikipedia.org/wiki/Type_system#Static_and_dynamic_type_checking_in_practice

Weak typing means that a language implicitly converts (or casts) types when used.

반면 :

A programming language is said to use static typing when type checking is performed during compile-time as opposed to run-time.

그래서 동적// 강하고 약한 정적 개의 상이한 크기이다. 언어는 strong/weak 중 하나이며 정적 동적 인 언어 중 하나입니다. 예를 들어 Ruby와 Javascript는 모두 동적으로 입력되지만 Ruby는 강하게 입력되는 반면 Javascript는 약하게 입력됩니다. 오류 줄에 즉 루비, 다음과 같은 코드 : 자바 스크립트 반면

1.9.2p290 :001 > 'a'+1 
TypeError: can't convert Fixnum into String 

을, 당신은 얻을 :

> 'a'+1 
>> 'a1' 

그래서, 강력하게 형식화 된 언어는 동일한 유형의 두 변수를 변환 할 필요 (예 : 1.to_s 사용), 약형 언어는 두 가지 변수를 몇 가지 추가 내장 언어 논리를 사용하여 같은 유형으로 강제 변환하려고 시도합니다. JavaScript의 경우 문자열을 결합하면 문자열이 변환됩니다 그것을 String 값으로 변환합니다.

자세한 내용은 http://www.artima.com/weblogs/viewpost.jsp?thread=7590을 참조하십시오.

0

간단히 말해서 강력한 형식 지정은 개체가 바인딩되는 방식 (본질적으로 초기 바인딩 대 후기 바인딩)이 선언 된 방식과 관련이 있습니다.

public class Foo 
{ 
    public int Bar; 
    public double Baz; 
} 

내가 형의 foo 변수 선언 : 나는 푸를 참조 할 때 다음과 같이

var myFoo = new Foo(); 

을 :

의 난이 클래스를 C#으로 가정 해 봅시다

foo. 

Visual Studio를 입력하면 BarBaz이 포함 된 목록이 표시됩니다. .입니다. 이미 알고 있기 때문에 myFoo에 해당 구성원이 포함되어 있습니다. 유형은 Foo입니다. 이것은 강력한 타이핑입니다. Bar 나 Baz의 철자를 잘못 입력하면 프로그램이 컴파일되지 않습니다.

그러나 프로그램이 실행될 때까지의 내가 형이 원인이 지연 될 바인딩 객체 dynamic의 변수를 선언 가정 해 봅시다 : 이것은 컴파일

dynamic myFoo = new Foo(); 
myFoo.Grapes = 6; 

. 프로그램을 실행할 때까지 오류가 발생하지 않습니다. Grapes가 Foo에 존재하지 않으므로 런타임 예외가 발생합니다.

0

이것은 오래된 질문이지만, 미래의 독자를 위해이 위대한 기사는 물건을 취소 할 수 있습니다 : http://blogs.perl.org/users/ovid/2010/08/what-to-know-before-debating-type-systems.html

그것은 종류의 오래입니다하지만 그것은 확실히 가치.

강하고 약한 타자 :

Probably the most common way type systems are classified is "strong" or "weak." This is unfortunate, since these words have nearly no meaning at all. It is, to a limited extent, possible to compare two languages with very similar type systems, and designate one as having the stronger of those two systems. Beyond that, the words mean nothing at all.

정적 및 동적 유형

This is very nearly the only common classification of type systems that has real meaning. As a matter of fact, it's significance is frequently under-estimated [...] Dynamic and static type systems are two completely different things, whose goals happen to partially overlap.

A static type system is a mechanism by which a compiler examines source code and assigns labels (called "types") to pieces of the syntax, and then uses them to infer something about the program's behavior. A dynamic type system is a mechanism by which a compiler generates code to keep track of the sort of data (coincidentally, also called its "type") used by the program. The use of the same word "type" in each of these two systems is, of course, not really entirely coincidental; yet it is best understood as having a sort of weak historical significance. Great confusion results from trying to find a world view in which "type" really means the same thing in both systems. It doesn't.

명시 적/암시 적 유형 :

When these terms are used, they refer to the extent to which a compiler will reason about the static types of parts of a program. All programming languages have some form of reasoning about types. Some have more than others. ML and Haskell have implicit types, in that no (or very few, depending on the language and extensions in use) type declarations are needed. Java and Ada have very explicit types, and one is constantly declaring the types of things. All of the above have (relatively, compared to C and C++, for example) strong static type systems.