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

Telegram Auto-Delete Messages in Any Chat

Some messages aren’t supposed to last forever. There are some Telegram groups and conversations where it’s best if messages are automatically deleted in a day or a week. Here’s how to auto-delete messages in any Telegram chat. You can enable the auto-delete feature on a per-chat basis. It works for both one-on-one conversations and group chats. Previously, you needed to use the Secret Chat feature to automatically delete messages after a set time. At the time of writing, you can choose to automatically delete messages after a day or a week. Telegram starts the timer once they are sent, not after they are read. This won’t affect the messages that were sent before enabling the feature.

China’s stock markets are some of the largest in the world, with total market capitalization reaching RMB 79 trillion (US$12.2 trillion) in 2020. China’s stock markets are seen as a crucial tool for driving economic growth, in particular for financing the country’s rapidly growing high-tech sectors.Although traditionally closed off to overseas investors, China’s financial markets have gradually been loosening restrictions over the past couple of decades. At the same time, reforms have sought to make it easier for Chinese companies to list on onshore stock exchanges, and new programs have been launched in attempts to lure some of China’s most coveted overseas-listed companies back to the country.

codedump的电报频道 from id


Telegram codedump的电报频道
FROM USA