红宝石是强力还是微弱的打字? [英] Is ruby strongly or weakly typed?

查看:104
本文介绍了红宝石是强力还是微弱的打字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ruby​​是强类型还是弱类型?

Is ruby strongly or weakly typed ?

大概对于Javascript也是如此。

Presumably the same is true for Javascript.

推荐答案

Ruby是强类型

强类型意味着对象的类型(不在OOP意义上,但是在一般意义上)在执行需要某种类型的操作之前进行检查。

Strong typing means an object's type (not in the OOP sense, but in a general sense) is checked before an operation requiring a certain type is executed on it.

弱类型意味着没有进行检查以确保操作可以成功在对象上。 (例如,当函数访问字符串和浮点数组时,如果没有进行类型检查,则允许操作)

Weak typed means that no checking is done to ensure that the operation can succeed on the object. (For example, when a function accesses a string like and array of floats, if no type checking is done then the operation is allowed)

编辑:
它是自这个答案发布以来已有6年了,我认为这需要一些额外的澄清:

It's been 6 years since this answer was posted and I think it warrants some extra clarifications:

多年来,类型安全是一个表盘不是绝对的的概念开始用于支持二进制含义(是/否)

Over the years the notion that "type safety is a dial not an absolute" started to be used in favor of the binary meaning (yes/no)

与大多数典型的动态语言相比,Ruby是更强的类型(带有呃)。 ruby需要明确的转换语句IE:Array(foo),42.to_i,Float(23)这一事实使得Ruby输入表盘更接近强类型结束而不是弱类型 。

Ruby is "stronger" typed (with an "er") than most typical dynamic languages. The fact that ruby requires explicit statements for conversion IE: Array("foo"), "42".to_i, Float(23), brings the Ruby typing dial closer to the "Strong Typed" end of spectrum than the "weak typed".

所以我会说Ruby是比大多数常见动态语言更强大的动态语言

So I would say "Ruby is a stronger typed dynamic language than most common dynamic languages"

这篇关于红宝石是强力还是微弱的打字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆