Crystal

Total posts: 1

静态版Ruby?Crystal语言试用

前几天在思考,Python 和 JS 都拥抱了类型检查(类型注释),但是 Ruby 却只能用 Sorbet 这样的影响性能的类型检查器(Ruby 没有官方的类型检查工具,引入静态类型检查的 gem 反而降低了性能),在搜索中找到了 Crystal 这门语言。

https://crystal-lang.org/

看描述我就惊艳到了:作为一个静态语言,Crystal 居然长得这么像 Ruby,于是本着不妨玩玩的想法,我进行了 Crystal 的初试。

# A very basic HTTP server
require "http/server"

server = HTTP::Server.new do |context|
  context.response.content_type = "text/plain"
  context.response.print "Hello world, got #{context.request.path}!"
end

address = server.bind_tcp(8080)
puts "Listening on http://#{address}"

# This call blocks until the process is terminated
server.listen