强类型语言与弱类型语言_松散类型与强类型语言

强类型语言与弱类型语言

In programming we call a language loosely typed when you don’t have to explicitly specify types of variables and objects.

在编程中,当您不必显式指定变量和对象的类型时,我们将其称为松散类型的语言。

A strongly typed language on the contrary wants types specified.

相反, 强类型语言需要指定类型。

There are pros and cons, you can argue forever but the reality is that both approaches are great, in their intended context and usage.

有优点也有缺点,您可以永远争论不休,但现实是,这两种方法在其预期的上下文和用法中都很棒。

JavaScript is loosely typed. You don’t have to tell that a string is a string, nor you can require a function to accepts an integer as its parameter.

JavaScript是松散类型的。 您不必告诉一个字符串是一个字符串,也不需要要求一个函数接受一个整数作为其参数。

This gives JavaScript a lot of flexibility. Flexibility lets you move faster, change things quickly, iterate at a faster velocity.

这为JavaScript提供了很大的灵活性。 灵活性使您可以更快地移动,快速更改事物,以更快的速度迭代。

A strong type system instead gives much more structure to a program and it’s a great aid for example when working in teams, when one single programmer can’t really have all the codebase in mind when working on it, and having types helps keep the code manageable.

相反,强大的类型系统为程序提供了更多的结构,例如,在团队合作中,一个程序员不能真正记住所有代码库,而拥有类型有助于保持代码,这将是一个很大的帮助。可管理的。

This is typical of compiled languages (while famous dynamic languages like JavaScript, Python and Ruby are loosely typed).

这是典型的编译语言(而著名的动态语言,如JavaScript,Python和Ruby则是松散类型的)。

You trade some of the flexibility that a loosely typed language gives you to get more security and trust in the codebase.

您可以使用某种松散类型的语言为您提供的灵活性,从而获得更高的安全性和对代码库的信任。

The compiler thanks to types can detect errors at compile time, rather than at runtime, making it simpler to write code that does what you want (and makes the testing phase slightly easier, although nothing can make your programs perfect).

由于类型,编译器可以在编译时而不是在运行时检测错误,从而使编写符合您要求的代码更加简单(并使测试阶段稍微容易些,尽管没有什么可以使您的程序完美无缺)。

TypeScript is a great example of a strongly typed language. It compiles to JavaScript, giving you the benefit of the JavaScript platform plus the intended advantages of types. C, Go, Java and Swift are great examples of strongly typed languages.

TypeScript是强类型语言的一个很好的例子。 它可以编译为JavaScript,为您提供JavaScript平台的好处以及类型的预期优点。 C,Go,Java和Swift是强类型语言的绝佳示例。

Being loosely typed doesn’t mean you don’t have types, of course, as you can see in my JavaScript Types post. You just make use of types implicitly, with the pros and cons that you imagine.

正如我在JavaScript Types文章中所看到的,松散键入并不意味着您没有类型 。 您只是隐式地使用类型,就可以想象其优缺点。

翻译自: https://flaviocopes.com/loosely-strongly-typed/

强类型语言与弱类型语言

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值