V (Vlang) 首个主要版本 0.2 发布,安全快速可编译的静态语言

栏目: 软件资讯 · 发布时间: 5年前

内容简介:V (Vlang) 0.2 发布了,作者宣布这是首个主要版本,更新重点是提升稳定性和优化编译时(compile-time)内存管理。 部分更新亮点 通过启用-autofree参数对 compile-time 内存进行管理(计划在 0.3 中默认启用) 提供...

V (Vlang) 0.2 发布了,作者宣布这是首个主要版本,更新重点是提升稳定性和优化编译时(compile-time)内存管理。

V (Vlang) 首个主要版本 0.2 发布,安全快速可编译的静态语言

部分更新亮点

  • 通过启用-autofree参数对 compile-time 内存进行管理(计划在 0.3 中默认启用)
  • 提供对 iOS 和 Android 的早期支持
  • 引入 IO 流
  • 引入 channel 和 lock
  • 引入内联结构体 (Struct embedding)
  • 支持通过 GitHub Actions 自动构建和部署 Linux/Windows/macOS 的 V 二进制文件
  • 支持 C++ 编译器:C 后端生成的代码现在可以由 C++ 编译器编译
  • 泛型语法更简洁,例如使用foo(5)代替foo<int>(5)
  • V 现在可通过 WASM 在浏览器中运行
  • 完善文档
  • ……

详情查看 https://github.com/vlang/v/discussions/7474
V 0.3 Roadmap:https://github.com/vlang/v/blob/master/0.3_roadmap.txt

V 是一个集合了 Go 的简单和 Rust 的安全特性的静态语言,作者表示 V 与 Go 非常相似,如果你了解 Go,那么就已经了解 80% 的 V。V 在 Go 的基础上进行改进之处:https://vlang.io/compare#go

V 主要特性

  • 简单(作者声称可以在不到一小时内学习 V)
  • 快速编译(编译器只有 400kb,而且无第三方依赖)
  • 易于开发:V 在不到一秒钟的时间内完成编译
  • 安全:没有 null、没有全局变量、没有未定义的值、边界检测、默认使用 Immutable 结构体
  • 支持 C/C++ 转换
  • 方便使用的交叉编译
  • 提供跨平台 UI 库
  • 内置图形库
  • 内置 ORM
  • 内置 Web 框架
  • ……

示例代码

数据库访问:

struct User { /* ... */ }
struct Post { /* ... */ }
struct DB   { /* ... */ }

struct Repo <T> {
    db DB
}

fn new_repo<T>(db DB) Repo {
    return Repo<T>{db: db}
}

fn (r Repo) find_by_id(id int) T? { // `?` means the function returns an optional
    table_name := T.name // in this example getting the name of the type gives us the table name
    return r.db.query_one<T>('select * from $table_name where id = ?', id)
}

fn main() {
    db := new_db()
    users_repo := new_repo<User>(db)
    posts_repo := new_repo<Post>(db)
    user := users_repo.find_by_id(1) or {
        eprintln('User not found')
        return
    }
    post := posts_repo.find_by_id(1) or {
        eprintln('Post not found')
        return
    }
} 

网络开发:

struct Story {
    title string
}

// Fetches top HN stories in 8 coroutines 
fn main() {
    resp := http.get('https://hacker-news.firebaseio.com/v0/topstories.json')?
    ids := json.decode([]int, resp.body)?
    mut cursor := 0
    for _ in 0..8 {
        go fn() {
            for  {
                lock { // Without this lock the program will not compile 
                    if cursor >= ids.len {
                        break
                    }
                    id := ids[cursor]
                    cursor++
                }
                resp := http.get('https://hacker-news.firebaseio.com/v0/item/$id.json')? 
                story := json.decode(Story, resp.body)?
                println(story.title)
            }
        }()
    }
    runtime.wait() // Waits for all coroutines to finish 
} 

以上所述就是小编给大家介绍的《V (Vlang) 首个主要版本 0.2 发布,安全快速可编译的静态语言》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Parsing Techniques

Parsing Techniques

Dick Grune、Ceriel J.H. Jacobs / Springer / 2010-2-12 / USD 109.00

This second edition of Grune and Jacobs' brilliant work presents new developments and discoveries that have been made in the field. Parsing, also referred to as syntax analysis, has been and continues......一起来看看 《Parsing Techniques》 这本书的介绍吧!

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

随机密码生成器
随机密码生成器

多种字符组合密码

SHA 加密
SHA 加密

SHA 加密工具