V语言 安全的全新编程语言开源项目

我要开发同款
匿名用户2019年04月18日
121阅读
开发技术V
所属分类其他
授权协议MIT

作品详情

V语言一个集合了Go的简单和Rust的安全特性的新语言。

主要特性:

快速编译(编译器只有400kb,而且无第三方依赖)安全C/C++转换

示例代码:

数据库访问:

structUser{/*...*/}structPost{/*...*/}structDB{/*...*/}structRepo<T>{dbDB}fnnew_repo<T>(dbDB)Repo{returnRepo<T>{db:db}}fn(rRepo)find_by_id(idint)T?{//`?`meansthefunctionreturnsanoptionaltable_name:=T.name//inthisexamplegettingthenameofthetypegivesusthetablenamereturnr.db.query_one<T>('select*from$table_namewhereid=?',id)}fnmain(){db:=new_db()users_repo:=new_repo<User>(db)posts_repo:=new_repo<Post>(db)user:=users_repo.find_by_id(1)or{eprintln('Usernotfound')return}post:=posts_repo.find_by_id(1)or{eprintln('Postnotfound')return}}

网络开发:

structStory{titlestring}//FetchestopHNstoriesin8coroutinesfnmain(){resp:=http.get('https://hacker-news.firebaseio.com/v0/topstories.json')?ids:=json.decode([]int,resp.body)?mutcursor:=0for_in0..8{gofn(){for{lock{//Withoutthislocktheprogramwillnotcompileifcursor>=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()//Waitsforallcoroutinestofinish}
声明:本文仅代表作者观点,不代表本站立场。如果侵犯到您的合法权益,请联系我们删除侵权资源!如果遇到资源链接失效,请您通过评论或工单的方式通知管理员。未经允许,不得转载,本站所有资源文章禁止商业使用运营!
下载安装【程序员客栈】APP
实时对接需求、及时收发消息、丰富的开放项目需求、随时随地查看项目状态

评论