Telegram Group & Telegram Channel
#编程语言
#Rust

以前会争论类型标识符,应该放在变量前面还是后面好。

除了美感这种偏主观的判断以外,我在学了一点PLT皮毛之后,有一个新的视角:

类型标识符在变量前面的语言,大多是没有类型推断的,因为放在前面,所以无法省略,就是说:必须在声明这个变量的时候就(由程序员)确定变量的类型。这也有例外,比如C++后面引入的auto关键字,相当于给原先的语法打了一个“补丁”,通过这个关键字声明的变量就能支持类型推断。

反之,放在变量后面的类型标识符,因为是可以做到省略的,省略的时候就是类型推断发挥的空间了:推断出最适合的类型出来;同样也有例外,比如Go就不支持类型推断

比如附图中的这段Rust代码:
同样的let a = 1,在两个上下文(context)里推断出来的是不同的类型:上面的代码由于没有别的信息,所以就选了i32类型;下面的代码由于要和已经声明为u64类型的b相加,所以推断出来a的类型为u64。

支持类型推断(type inference)的语言,(应该都)要做到类型安全(type safety)。比如:不能允许两个变量的数据,操作之后出现溢出等情况。

综上,我更喜欢支持类型推断、类型安全的语言。

Roman Elizarov(Project Lead for the Kotlin Programming Language)的一篇文章《Types are moving to the right》中也提到,21世纪之后才出现的编程语言,很多都是把类型标识符放在变量后面了,Go、Rust、Scala等。



tg-me.com/codedump_notes/547
Create:
Last Update:

#编程语言
#Rust

以前会争论类型标识符,应该放在变量前面还是后面好。

除了美感这种偏主观的判断以外,我在学了一点PLT皮毛之后,有一个新的视角:

类型标识符在变量前面的语言,大多是没有类型推断的,因为放在前面,所以无法省略,就是说:必须在声明这个变量的时候就(由程序员)确定变量的类型。这也有例外,比如C++后面引入的auto关键字,相当于给原先的语法打了一个“补丁”,通过这个关键字声明的变量就能支持类型推断。

反之,放在变量后面的类型标识符,因为是可以做到省略的,省略的时候就是类型推断发挥的空间了:推断出最适合的类型出来;同样也有例外,比如Go就不支持类型推断

比如附图中的这段Rust代码:
同样的let a = 1,在两个上下文(context)里推断出来的是不同的类型:上面的代码由于没有别的信息,所以就选了i32类型;下面的代码由于要和已经声明为u64类型的b相加,所以推断出来a的类型为u64。

支持类型推断(type inference)的语言,(应该都)要做到类型安全(type safety)。比如:不能允许两个变量的数据,操作之后出现溢出等情况。

综上,我更喜欢支持类型推断、类型安全的语言。

Roman Elizarov(Project Lead for the Kotlin Programming Language)的一篇文章《Types are moving to the right》中也提到,21世纪之后才出现的编程语言,很多都是把类型标识符放在变量后面了,Go、Rust、Scala等。

BY codedump的电报频道




Share with your friend now:
tg-me.com/codedump_notes/547

View MORE
Open in Telegram


codedump的电报频道 Telegram | DID YOU KNOW?

Date: |

Newly uncovered hack campaign in Telegram

The campaign, which security firm Check Point has named Rampant Kitten, comprises two main components, one for Windows and the other for Android. Rampant Kitten’s objective is to steal Telegram messages, passwords, and two-factor authentication codes sent by SMS and then also take screenshots and record sounds within earshot of an infected phone, the researchers said in a post published on Friday.

How to Buy Bitcoin?

Most people buy Bitcoin via exchanges, such as Coinbase. Exchanges allow you to buy, sell and hold cryptocurrency, and setting up an account is similar to opening a brokerage account—you’ll need to verify your identity and provide some kind of funding source, such as a bank account or debit card. Major exchanges include Coinbase, Kraken, and Gemini. You can also buy Bitcoin at a broker like Robinhood. Regardless of where you buy your Bitcoin, you’ll need a digital wallet in which to store it. This might be what’s called a hot wallet or a cold wallet. A hot wallet (also called an online wallet) is stored by an exchange or a provider in the cloud. Providers of online wallets include Exodus, Electrum and Mycelium. A cold wallet (or mobile wallet) is an offline device used to store Bitcoin and is not connected to the Internet. Some mobile wallet options include Trezor and Ledger.

codedump的电报频道 from jp


Telegram codedump的电报频道
FROM USA