V语言一个集合了Go的简单和Rust的安全特性的新语言。
主要特性:
快速编译(编译器只有400kb,而且无第三方依赖)安全C/C++转换示例代码:
数据库访问:
structUser{/*...*/}structPost{/*...*/}structDB{/*...*/}structRepo<T>{dbDB}few_repo<T>(dbDB)Repo{returRepo<T>{db:db}}f(rRepo)fid_by_id(idit)T?{//`?`measthefuctioretursaoptioaltable_ame:=T.ame//ithisexamplegettigtheameofthetypegivesusthetableamereturr.db.query_oe<T>('select*from$table_amewhereid=?',id)}fmai(){db:=ew_db()users_repo:=ew_repo<User>(db)posts_repo:=ew_repo<Post>(db)user:=users_repo.fid_by_id(1)or{epritl('Userotfoud')retur}post:=posts_repo.fid_by_id(1)or{epritl('Postotfoud')retur}}网络开发:
structStory{titlestrig}//FetchestopHNstoriesi8coroutiesfmai(){resp:=http.get('https://hacker-ews.firebaseio.com/v0/topstories.jso')?ids:=jso.decode([]it,resp.body)?mutcursor:=0for_i0..8{gof(){for{lock{//Withoutthislocktheprogramwillotcompileifcursor>=ids.le{break}id:=ids[cursor]cursor++}resp:=http.get('https://hacker-ews.firebaseio.com/v0/item/$id.jso')?story:=jso.decode(Story,resp.body)?pritl(story.title)}}()}rutime.wait()//Waitsforallcoroutiestofiish}
评论