V (programming language)

V
A capitalized letter V colored blue
The official V logo
ParadigmsMulti-paradigm: functional, imperative, structured, concurrent
Designed byAlexander Medvednikov[1]
First appeared20 June 2019; 5 years ago (2019-06-20)[2]
Stable release
0.4.8[3] Edit this on Wikidata / September 28, 2024; 2 months ago (September 28, 2024)
Typing disciplinestatic, strong, inferred
Memory managementoptional (automatic or manual)
Implementation languageV
Platformx86-64
OSLinux, macOS, Windows, FreeBSD, OpenBSD, NetBSD, DragonflyBSD, Solaris
LicenseMIT
Filename extensions.v, .vsh
Websitevlang.io
Influenced by
Go, Kotlin, Oberon, Python, Rust, Swift

V, also known as vlang, is a statically typed, compiled programming language created by Alexander Medvednikov in early 2019.[4] It was inspired by the language Go, and other influences including Oberon, Swift, and Rust.[5][6][7] It is free and open-source software released under the MIT License, and currently in beta.[8]

The goals of V include ease of use, readability, and maintainability.[9][10]

History

According to one of the developers, the new language was created as a result of frustration with existing languages being used for personal projects.[11] The language was originally intended for personal use, but after it was mentioned publicly and gained interest, it was decided to make it public. V was initially created in order to develop a desktop messaging client known as Volt.[6] Upon public release, the compiler was written in V, and could compile itself.[4] Key design goals behind the creation of V were being easy to learn and use, higher readability, fast compilation, increased safety, efficient development, cross-platform usability, improved C interoperability, better error handling, modern features, and more maintainable software.[12][13][10][14]

V is released and developed through GitHub[15][6] and maintained by developers and contributors from the community.[4]

Veasel is the official mascot of the V programming language[16]

Features

Safety

V has policies to facilitate memory-safety, speed, and secure code.[7][17] The language has various default features for greater program safety.[7][17][6][9] It employs bounds checking, to guard against out of bounds usage of variables. Option/result types are used, where the option type (?) can be represented by none (among possible choices) and the result type (!) can handle any returned errors. To ensure greater safety, the checking of errors are mandatory in V. By default, among the following are immutable: variables, structs, and function arguments. This includes string values are immutable, so elements can not be mutated. Other protections, which are the default for the language, are: no usage of undefined values, no shadowing of variables, no usage of null (unless code marked as unsafe), and no usage of global variables (unless enabled via flag).

Performance

V uses value types and string buffers to reduce memory allocations.[18][19][17] The language can be compiled to human-readable C [4][20] and is considered to be as performant.[17]

Memory management

The language's 4 supported options for memory management are the following:[21][6][22][20]

  1. Use of an optional GC (that can be disabled) for handling allocations, and is the default.
  2. Manual memory management via disabling the GC (-gc none).
  3. Autofree, which handles most objects via free call insertion, and then the remaining percentage is freed by GC (-autofree).
  4. Arena allocation (-prealloc).

Source code translators

V supports a source-to-source compiler (transpiler) and can translate C code into V.[23][24][10]

Working translators are also under development for Go, JavaScript, and WebAssembly.[25][26]

Syntax

Hello world

The "Hello, World!" program in V:[17]

fn main() {
	println("Hello, World!")
}

Variables

Variables are immutable by default and are defined using := and a value. Use the mut keyword to make them mutable. Mutable variables can be assigned to using =:[27]

a := 1
mut b := 2
b = 3

Redeclaring a variable, whether in an inner scope or in the same scope, is not allowed:[27]

a := 1
{
    a := 3 // error: redefinition of a
}
a := 2 // error: redefinition of a

Structs

Struct example:[12]

struct Point {
	x int
	y int
}

mut p := Point {
	x: 10
	y: 20
}
println(p.x) // Struct fields are accessed using a dot
// Alternative literal syntax for structs with 3 fields or fewer
p = Point{10, 20}
assert p.x == 10

Heap structs

Structs are allocated on the stack by default. To allocate a struct on the heap and get a reference to it, the & prefix can be used:[12]

struct Point {
	x int
	y int
}

p := &Point{10, 10}
// References have the same syntax for accessing fields
println(p.x)

Methods

Methods in V are functions defined with a receiver argument. The receiver appears in its own argument list between the fn keyword and the method name. Methods must be in the same module as the receiver type.

The is_registered method has a receiver of type User named u. The convention is not to use receiver names like self or this, but preferably a short name. For example:[9][12]

struct User {
	age int
}

fn (u User) is_registered() bool {
	return u.age > 16
}

user := User{
	age: 10
}
println(user.is_registered()) // "false"
user2 := User{
	age: 20
}
println(user2.is_registered()) // "true"

Error handling

Optional types are for types which may represent none. Result types may represent an error returned from a function.

Option types are declared by prepending ? to the type name: ?Type. Result types use !: !Type.[9][7][21]

fn do_something(s string) !string {
	if s == "foo" {
		return "foo"
	}
	return error("invalid string")
}

a := do_something("foo") or { "default" } // a will be "foo"
b := do_something("bar") or { "default" } // b will be "default"
c := do_something("bar") or { panic("{err}") } // exits with error "invalid string" and a traceback

println(a)
println(b)

See also

References

  1. ^ "Creator of V". GitHub.
  2. ^ "First public release". GitHub. 20 June 2019.
  3. ^ "Release 0.4.8". 28 September 2024. Retrieved 28 September 2024.
  4. ^ a b c d Rao 2021.
  5. ^ Lewkowicz, Jakub (25 June 2019). "SD Times news digest: V language now open sourced". SD Times. Retrieved 25 June 2019.
  6. ^ a b c d e James, Ben (23 July 2019). "The V Programming Language: Vain Or Virtuous?". Hackaday. Retrieved 23 July 2019.
  7. ^ a b c d Umoren, Samuel. "Building a Web Server using Vlang". Section. Archived from the original on 13 March 2023. Retrieved 5 April 2021.
  8. ^ "The V Programming Language". vlang.io. Retrieved 4 November 2023.
  9. ^ a b c d Knott, Simon (27 June 2019). "An introduction to V". Retrieved 27 June 2019.
  10. ^ a b c Nasufi, Erdet. "An introduction to V - the vlang". DebConf. Retrieved 24 July 2022.
  11. ^ "How To Maintain And Iterate With V - SYNCS 2023 (Sydney Computing Society at the University of Sydney)". YouTube. Retrieved 18 October 2023.
  12. ^ a b c d Independent Laboratory 2020.
  13. ^ Lyons 2022.
  14. ^ "V language: simple like Go, small binary like Rust". TechRacho. Retrieved 3 March 2021.
  15. ^ "GitHub Programming Languages (repository rankings)" – via OSS.
  16. ^ "V's official mascot". GitHub. Retrieved 8 November 2023.
  17. ^ a b c d e Galuh, Rosa (8 August 2022). "A Brief Introduction to the V Language". MUO. Retrieved 8 August 2022.
  18. ^ Rao 2021, p. 7.
  19. ^ "The V programming language is now open source". Packt Hub. 24 June 2019. Retrieved 24 June 2019.
  20. ^ a b Chakraborty 2023.
  21. ^ a b Tsoukalos 2022.
  22. ^ Emy, Jade (29 August 2023). "The programming language V 0.4 Beta is available". developpez. Retrieved 29 August 2023.
  23. ^ Choudhury, Ambika (9 February 2022). "Meet V, The New Statically Typed Programming Language Inspired By Go & Rust". Analytics India Magazine (AIM). Retrieved 7 July 2024.
  24. ^ Schlothauer, Sarah. "The trendy five: Blazing hot GitHub repos in June 2019". JAXenter. Archived from the original on 17 February 2020. Retrieved 1 July 2019.
  25. ^ "Convert Go to V with go2v". Zenn. 26 January 2023. Retrieved 26 January 2023.
  26. ^ "The V WebAssembly Compiler Backend". l-m. 26 February 2023. Retrieved 26 February 2023.
  27. ^ a b Rao 2021, pp. 28–40.

Further reading

Read other articles:

RoubaixBalai kota Koordinat: 50°41′24″N 3°10′54″E / 50.69°N 3.18167°E / 50.69; 3.18167NegaraPrancisArondisemenLilleKantonKota utama dari 2 kantonAntarkomuneMétropole européennede LillePemerintahan • Wali kotaGuillaume Delbar (UMP)Kode INSEE/pos59512 /  Gereja paroki Santo Martinus Roubaix (bahasa Belanda Robaais) ialah sebuah kota di Nord, Prancis utara, dekat kota Lille dan Tourcoing serta perbatasan Belgia. Pemandangan Yang paling utama...

 

Halicnemia salomonensis Klasifikasi ilmiah Kerajaan: Animalia Upakerajaan: Parazoa Filum: Porifera Kelas: Demospongiae Ordo: Halichondrida Famili: Heteroxyidae Genus: Halicnemia Spesies: Halicnemia salomonensis Beberapa atau seluruh referensi dari artikel ini mungkin tidak dapat dipercaya kebenarannya. Bantulah dengan memberikan referensi yang lebih baik atau dengan memeriksa apakah referensi telah memenuhi syarat sebagai referensi tepercaya. Referensi yang tidak benar dapat dihapus sewaktu-...

 

Sony XperiaPembuatSony MobileJenisPonsel cerdas, tablet, phabletTanggal rilis27 Oktober 2008; 15 tahun lalu (2008-10-27)Sistem operasiAndroid (sejak tahun 2010)Windows Mobile (2008–2010)MasukanLayar sentuh Xperia (/ɛkˈspɪəriə/) adalah sebuah merek ponsel cerdas dan tablet milik Sony Mobile. Nama Xperia berasal dari kata experience, dan pertama kali digunakan pada tagline Xperia X1, yakni I Xperia the best. Sony Mobile sebelumnya dikenal secara global dengan nama Sony Ericsson, dan...

Lemur Lemur ekor-cincin (Lemur catta) Klasifikasi ilmiah Kerajaan: Animalia Filum: Chordata Kelas: Mammalia Ordo: Primates Subordo: Strepsirrhini Infraordo: LemuriformesGregory, 1915 Superfamili Lemuroidea Lorisoidea Lemur (Latin: lemurescode: la is deprecated ) atau Warik Madagaskar adalah hewan dari ordo primata yang hidup dan tinggal di Madagaskar, Afrika.[1] Arti dari kata lemures ini adalah makhluk atau arwah di malam hari atau hantu.[1] Hal ini mungkin karena bentuk mat...

 

Historic site in Cambridge, Massachusetts Longfellow House–Washington's Headquarters National Historic SiteThe Longfellow HouseShow map of MassachusettsShow map of the United StatesLocationCambridge, Massachusetts, USACoordinates42°22′36″N 71°07′35″W / 42.37667°N 71.12639°W / 42.37667; -71.12639Area2 acres (0.81 ha)EstablishedOctober 9, 1972Visitors50,784[1] (in 2015[1])Governing bodyNational Park ServiceWebsiteLongfello...

 

2008 2015 (départementales) Élections cantonales de 2011 dans la Haute-Marne 16 des 32 cantons de la Haute-Marne 20 et 27 mars 2011 Type d’élection Élections cantonales Majorité départementale – Bruno Sido Liste UMPDVD Sièges obtenus 23  2 Opposition départementale – MoDem Liste PSDVGPCFPRG Sièges obtenus 10  3 Président du Conseil général Sortant Élu Bruno Sido UMP Bruno Sido UMP modifier - modifier le code - voir Wikidata  Les éle...

U2U2 at Hauptwache stationIkhtisarJenisAngkutan cepatSistemFrankfurt U-BahnStatusBeroperasiLokasiFrankfurt am Main, Bad HomburgTerminusStasiun Frankfurt SelatanBad Homburg-GonzenheimStasiun21LayananA IV, A II, A I, A III, A 1, A 2OperasiDibuka04 Oktober 1968 (1968-10-04)PemilikVerkehrsgesellschaft FrankfurtOperatorVerkehrsgesellschaft FrankfurtDepoHeddernheimRangkaianU4, U5Data teknisPanjang lintas166 km (103 mi)Lebar sepur1.435 mm (4 ft 8+1⁄2 in) sepu...

 

Singaporean politician For Indian politician, see S. Jayakumar (Indian politician). In this Indian name, the name Shunmugam is a patronymic, and the person should be referred to by the given name, Jayakumar. S. JayakumarBBM DUTசண்முகம் செயக்குமார்4th Senior Minister of SingaporeIn office1 April 2009 – 20 May 2011Serving with Goh Chok Tong (2004–2011)Prime MinisterLee Hsien LoongPreceded byLee Kuan YewSucceeded byTeo Chee HeanTharman S...

 

Jason Sudeikis Jason Sudeikis en 2023. Données clés Nom de naissance Daniel Jason Sudeikis Naissance 18 septembre 1975 (48 ans)Fairfax, Virginie, États-Unis Nationalité Américaine Profession Acteur, scénariste Films notables Trop loin pour toiBon à tirer (BAT)Comment tuer son boss ?Moi, députéLes Miller, une famille en herbe Séries notables Saturday Night Live Ted Lasso modifier Jason Sudeikis est un acteur et scénariste américain né le 18 septembre 1975 à Fairfax (Vi...

Cet article est une ébauche concernant une localité croate. Vous pouvez partager vos connaissances en l’améliorant (comment ?) selon les recommandations des projets correspondants. Consultez la liste des tâches à accomplir en page de discussion. Pour la ville du Latium, voir Segni. Sinj Vue de Sinj Administration Pays Croatie Comitat Split Dalmatie Code postal 21230 Indicatif téléphonique international +(385) Indicatif téléphonique local 021 Démographie Population 11 46...

 

Premier League Malti 1945-1946 Competizione Premier League Malti Sport Calcio Edizione 31ª Organizzatore MFA Date dal 1945al 1946 Luogo  Malta Partecipanti 7 Formula 1 girone all'italiana Risultati Vincitore  Valletta(4º titolo) Statistiche Incontri disputati 84 Gol segnati 181 (2,15 per incontro) Cronologia della competizione 1944-45 1946-47 Manuale Il campionato era formato da sette squadre e la Valletta F.C. vinse il titolo. Classifica finale Pos. Squadra G V N P ...

 

この項目には、一部のコンピュータや閲覧ソフトで表示できない文字が含まれています(詳細)。 数字の大字(だいじ)は、漢数字の一種。通常用いる単純な字形の漢数字(小字)の代わりに同じ音の別の漢字を用いるものである。 概要 壱万円日本銀行券(「壱」が大字) 弐千円日本銀行券(「弐」が大字) 漢数字には「一」「二」「三」と続く小字と、「壱」「�...

Paul CavanaghCavanagh dalam The Woman in Green, 1945LahirWilliam Grigs Atkinson(1888-12-08)8 Desember 1888Felling, County Durham, InggrisMeninggal15 Maret 1964(1964-03-15) (umur 75)London, InggrisMakamLorraine Park Cemetery, Baltimore, MarylandPekerjaanPemeranTahun aktif1928–1959Suami/istriCatherine Layfield Luhn (1946–1964)Anak1 William Grigs Atkinson[1] (8 Desember 1888 – 15 Maret 1964), yang lebih dikenal sebagai Paul Cavanagh, adalah seorang pemeran ...

 

Israeli football referee Alon Yefetאלון יפתBorn (1972-09-01) September 1, 1972 (age 51)Netanya, Israel Alon Yefet (Hebrew: אלון יפת, born September 1, 1972) is a former international football referee who was the first Israeli to officiate a UEFA Champions League match.[1] Yefet became a FIFA referee in 2001.[2] He has served as a referee in qualifying matches for the 2006,[3] 2010,[4] and 2014[5] World Cups. In addition, Yefet officia...

 

Questa voce sull'argomento tennisti statunitensi è solo un abbozzo. Contribuisci a migliorarla secondo le convenzioni di Wikipedia. Marion Zinderstein Nazionalità  Stati Uniti Tennis Carriera Singolare1 Vittorie/sconfitte Titoli vinti Miglior ranking Risultati nei tornei del Grande Slam  Australian Open -  Roland Garros -  Wimbledon QF (1924)  US Open F (1919, 1920) Doppio1 Vittorie/sconfitte Titoli vinti Miglior ranking Risultati nei tornei del Grande Slam &#...

Small container used in laboratories This article is about a tool used in laboratories. For the region of the Republic of the Congo, see Cuvette Region. This article has multiple issues. Please help improve it or discuss these issues on the talk page. (Learn how and when to remove these template messages) This article may require cleanup to meet Wikipedia's quality standards. The specific problem is: some references cited are vendor catalogs. Please help improve this article if you can. (Nove...

 

Weekly newspaper in the US The New Jersey Jewish NewsTypeWeekly newspaperOwner(s)JJMedia, LLCEditorJoanne PalmerFounded1946Headquarters70 Grand Ave., Suite 104River Edge, New Jersey, U.S.Circulation24,000[1]Websitenjjewishnews.timesofisrael.comFree online archivesArchives at the Jewish Historical Society of New Jersey The New Jersey Jewish News (NJJN) is a weekly newspaper. Coverage and scope In addition to other issues, it covers local, national, and world events; Jewish culture and ...

 

American baseball player (born 1968) For other people named Gary Sheffield, see Gary Sheffield (disambiguation). Baseball player Gary SheffieldSheffield with the New York Yankees in 2005Outfielder / Third basemanBorn: (1968-11-18) November 18, 1968 (age 55)Tampa, Florida, U.S.Batted: RightThrew: RightMLB debutSeptember 15, 1988, for the Milwaukee BrewersLast MLB appearanceSeptember 30, 2009, for the New York MetsMLB statisticsBatting average.292Hits2,689Hom...

安国寺 所在地 大分県国東市国東町安国寺2245位置 北緯33度33分41.4秒 東経131度43分11.2秒 / 北緯33.561500度 東経131.719778度 / 33.561500; 131.719778座標: 北緯33度33分41.4秒 東経131度43分11.2秒 / 北緯33.561500度 東経131.719778度 / 33.561500; 131.719778山号 太陽山宗派 臨済宗妙心寺派創建年 応永元年(1394年)開基 足利尊氏正式名 太陽山安國禪寺別称 豊後安国...

 

Perpindahan moda kereta api ke jalan raya yang dapat juga dilakukan angkutan laut Angkutan Multimoda adalah angkutan barang dengan menggunakan paling sedikit 2 (dua) moda angkutan yang berbeda atas dasar 1 (satu) kontrak sebagai dokumen angkutan multimoda dari satu tempat diterimanya barang oleh badan usaha angkutan multimoda ke suatu tempat yang ditentukan untuk penyerahan barang kepada penerima barang angkutan multimoda.[1] Sementara OECD mendefinisikan angkutan multi moda sebagai M...