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

Should You Buy Bitcoin?

In general, many financial experts support their clients’ desire to buy cryptocurrency, but they don’t recommend it unless clients express interest. “The biggest concern for us is if someone wants to invest in crypto and the investment they choose doesn’t do well, and then all of a sudden they can’t send their kids to college,” says Ian Harvey, a certified financial planner (CFP) in New York City. “Then it wasn’t worth the risk.” The speculative nature of cryptocurrency leads some planners to recommend it for clients’ “side” investments. “Some call it a Vegas account,” says Scott Hammel, a CFP in Dallas. “Let’s keep this away from our real long-term perspective, make sure it doesn’t become too large a portion of your portfolio.” In a very real sense, Bitcoin is like a single stock, and advisors wouldn’t recommend putting a sizable part of your portfolio into any one company. At most, planners suggest putting no more than 1% to 10% into Bitcoin if you’re passionate about it. “If it was one stock, you would never allocate any significant portion of your portfolio to it,” Hammel says.

Find Channels On Telegram?

Telegram is an aspiring new messaging app that’s taking the world by storm. The app is free, fast, and claims to be one of the safest messengers around. It allows people to connect easily, without any boundaries.You can use channels on Telegram, which are similar to Facebook pages. If you’re wondering how to find channels on Telegram, you’re in the right place. Keep reading and you’ll find out how. Also, you’ll learn more about channels, creating channels yourself, and the difference between private and public Telegram channels.

codedump的电报频道 from sg


Telegram codedump的电报频道
FROM USA