标量与原始数据类型 - 它们是同一回事吗? [英] Scalar vs. primitive data type - are they the same thing?

查看:95
本文介绍了标量与原始数据类型 - 它们是同一回事吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我读过的各种文章中,有时会引用原始数据类型,有时还会引用标量.

In various articles I have read, there are sometimes references to primitive data types and sometimes there are references to scalars.

我对每一个的理解是它们都是一些简单的数据类型,比如 int、boolean、char 等.

My understanding of each is that they are data types of something simple like an int, boolean, char, etc.

我是否遗漏了什么,这意味着您应该使用特定的术语还是这些术语可以简单地互换?每一个的维基百科页面都没有显示任何明显的内容.

Is there something I am missing that means you should use particular terminology or are the terms simply interchangeable? The Wikipedia pages for each one doesn't show anything obvious.

如果这些术语可以互换,哪个是首选?

If the terms are simply interchangeable, which is the preferred one?

推荐答案

我不认为它们可以互换.它们通常相似,但确实存在差异,而且似乎主要在于它们对比的内容和上下文相关的内容.

I don't think they're interchangeable. They are frequently similar, but differences do exist, and seems to mainly be in what they are contrasted with and what is relevant in context.

标量通常与复合形成对比,例如数组、映射、集合、结构体等.标量是单个"对象.值 - 整数,布尔值,可能是字符串 - 而一个化合物由多个标量组成(可能还有对其他化合物的引用).标量"用于相关区别在于单个/简单/原子值和复合值之间的上下文.

Scalars are typically contrasted with compounds, such as arrays, maps, sets, structs, etc. A scalar is a "single" value - integer, boolean, perhaps a string - while a compound is made up of multiple scalars (and possibly references to other compounds). "Scalar" is used in contexts where the relevant distinction is between single/simple/atomic values and compound values.

原始类型,然而,与例如对比.引用类型,当相关的区别是这是直接一个值,还是对包含真实值的东西的引用?"时使用,就像在 Java 的原始类型与引用中一样.我认为这是一种比标量/复合物更低级别的区别,但并不完全如此.

Primitive types, however, are contrasted with e.g. reference types, and are used when the relevant distinction is "Is this directly a value, or is it a reference to something that contains the real value?", as in Java's primitive types vs. references. I see this as a somewhat lower-level distinction than scalar/compound, but not quite.

这实际上取决于上下文(并且经常讨论的是什么语系).举一个可能是病态的例子:字符串.在 C 中,字符串是复合(字符数组),而在 Perl 中,字符串是标量.在 Java 中,字符串是一个对象(或引用类型).在 Python 中,一切(概念上)都是对象/引用类型,包括字符串(和数字).

It really depends on context (and frequently what language family is being discussed). To take one, possibly pathological, example: strings. In C, a string is a compound (an array of characters), while in Perl, a string is a scalar. In Java, a string is an object (or reference type). In Python, everything is (conceptually) an object/reference type, including strings (and numbers).

这篇关于标量与原始数据类型 - 它们是同一回事吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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