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: |

How To Find Channels On Telegram?

There are multiple ways you can search for Telegram channels. One of the methods is really logical and you should all know it by now. We’re talking about using Telegram’s native search option. Make sure to download Telegram from the official website or update it to the latest version, using this link. Once you’ve installed Telegram, you can simply open the app and use the search bar. Tap on the magnifier icon and search for a channel that might interest you (e.g. Marvel comics). Even though this is the easiest method for searching Telegram channels, it isn’t the best one. This method is limited because it shows you only a couple of results per search.

What Is Bitcoin?

Bitcoin is a decentralized digital currency that you can buy, sell and exchange directly, without an intermediary like a bank. Bitcoin’s creator, Satoshi Nakamoto, originally described the need for “an electronic payment system based on cryptographic proof instead of trust.” Each and every Bitcoin transaction that’s ever been made exists on a public ledger accessible to everyone, making transactions hard to reverse and difficult to fake. That’s by design: Core to their decentralized nature, Bitcoins aren’t backed by the government or any issuing institution, and there’s nothing to guarantee their value besides the proof baked in the heart of the system. “The reason why it’s worth money is simply because we, as people, decided it has value—same as gold,” says Anton Mozgovoy, co-founder & CEO of digital financial service company Holyheld.

codedump的电报频道 from tw


Telegram codedump的电报频道
FROM USA