Caleb Stanford (talk | contribs) + Tag: 2017 wikitext editor |
m 1) Returned unnecessarily removed safety section. 2) Added citations to safety. 3) Added citations to syntax section per V talk. 4) Removed tag on syntax section as citations added. Tag: Reverted |
||
(7 intermediate revisions by the same user not shown) | |||
Line 21: | Line 21: | ||
}} |
}} |
||
'''V''' also known as '''vlang''', is a statically typed compiled programming language |
'''V''' (/ˈviː/, as in the letter v) also known as '''vlang''', is a statically typed compiled programming language created by Alexander Medvednikov in early 2019.{{Sfn|Rao|2021}} It was mostly inspired by the [[Go (programming language)|Go]] programming language, as well as other influences including [[Oberon (programming language)|Oberon]], [[Swift (programming language)|Swift]], and [[Rust (programming language)|Rust]].<ref>{{cite web |last1=Lewkowicz |first1=Jakub |title=SD Times news digest: V language now open sourced |url=https://sdtimes.com/softwaredev/sd-times-news-digest-v-language-now-open-sourced-smartbear-acquires-bdd-provider-cucumber-and-kaggle-integrates-into-bigquery|website=SD Times|date=25 June 2019 |access-date=25 June 2019}}</ref><ref name="hackaday">{{cite web |last1=James |first1=Ben |date=23 July 2019 |title=The V Programming Language: Vain Or Virtuous? |url=https://hackaday.com/2019/07/23/the-v-programming-language-vain-or-virtuous/ |access-date=23 July 2019 |website=Hackaday}}</ref><ref name="section">{{cite web |last1=Umoren |first1=Samuel |title=Building a Web Server using Vlang |url=https://www.section.io/engineering-education/building-web-server-with-vlang/ |website=Section |access-date=5 April 2021}}</ref> It is [[free and open-source software]], in active development at [[GitHub]]<ref>{{cite web|url=https://ossinsight.io/collections/programming-language |title=GitHub Programming Languages (repository rankings)| via = [[OSS]] }}</ref><ref name="hackaday"></ref>, and released under the [[MIT license]]. |
||
The goals of V include |
The goals of V include being easy to use and readability.<ref name="Knott">{{cite web |last1=Knott |first1=Simon |title=An introduction to V |date=27 June 2019 |url=https://simonknott.de/articles/vlang/ |access-date=27 June 2019}}</ref><ref>{{cite web |last1=Oliveira |first1=Jader |title=VLang for Automation Scripting|url=https://www.linkedin.com/pulse/vlang-automation-scripting-jader-oliveira |website=LinkedIn |access-date=4 June 2021}}</ref><ref name="auto1">{{cite web |last1=Jonah |first1=Victor |title=What is Vlang? An introduction |url=https://blog.logrocket.com/what-is-vlang-an-introduction/ |website=LogRocket |date=25 February 2021 |access-date=25 February 2021}}</ref> The language also promotes safety and the elimination of ambiguity; for example, variable shadowing is not allowed; that is, declaring a variable with a name that is already used in a parent scope will cause a compilation error.{{Sfn|Rao|2021}}<ref name="MUO">{{cite web |last1=Galuh |first1=Rosa |title=A Brief Introduction to the V Language |url=https://www.makeuseof.com/v-language-brief-introduction |website=MUO |date=8 August 2022 |access-date=8 August 2022}}</ref> |
||
==History== |
==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.<ref name="SYNCS 2023">{{cite web |title=How To Maintain And Iterate With V - SYNCS 2023 (Sydney Computing Society at the University of Sydney)|url=https://www.youtube.com/watch?v=pchEsYwA74Q |website=YouTube |access-date=18 October 2023}}</ref> Originally the language was 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.<ref name="hackaday">{{cite web |last1=James |first1=Ben |date=23 July 2019 |title=The V Programming Language: Vain Or Virtuous? |url=https://hackaday.com/2019/07/23/the-v-programming-language-vain-or-virtuous/ |access-date=23 July 2019 |website=Hackaday}}</ref> The V language was created in order to develop it, along with other software applications such as Ved (also called Vid). As the extension in use was already ".v", to not mess up the git history, it was decided to name it "V".<ref name="auto1">{{cite web |last1=Jonah |first1=Victor |title=What is Vlang? An introduction |url=https://blog.logrocket.com/what-is-vlang-an-introduction/ |website=LogRocket |date=25 February 2021 |access-date=25 February 2021}}</ref> Upon public release, the compiler was written in V, and could compile itself.{{Sfn|Rao|2021}} Key design goals behind the creation of V |
According to one of the developers, the new language was created as a result of frustration with existing languages being used for personal projects.<ref name="SYNCS 2023">{{cite web |title=How To Maintain And Iterate With V - SYNCS 2023 (Sydney Computing Society at the University of Sydney)|url=https://www.youtube.com/watch?v=pchEsYwA74Q |website=YouTube |access-date=18 October 2023}}</ref> Originally the language was 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.<ref name="hackaday">{{cite web |last1=James |first1=Ben |date=23 July 2019 |title=The V Programming Language: Vain Or Virtuous? |url=https://hackaday.com/2019/07/23/the-v-programming-language-vain-or-virtuous/ |access-date=23 July 2019 |website=Hackaday}}</ref> The V language was created in order to develop it, along with other software applications such as Ved (also called Vid). As the extension in use was already ".v", to not mess up the git history, it was decided to name it "V".<ref name="auto1">{{cite web |last1=Jonah |first1=Victor |title=What is Vlang? An introduction |url=https://blog.logrocket.com/what-is-vlang-an-introduction/ |website=LogRocket |date=25 February 2021 |access-date=25 February 2021}}</ref> Upon public release, the compiler was written in V, and could compile itself.{{Sfn|Rao|2021}} Along with Alexander Medvednikov, the creator, its community has a large number of contributors from around the world<ref>{{cite web|url=https://ossinsight.io/analyze/vlang/v#people |title=Contributors | via = [[OSS]] }}</ref>{{Sfn|Rao|2021}} who have helped with continually developing and adding to the compiler, language, and modules. Key design goals behind the creation of V: easier to learn and use, higher readability, fast compilation, increased safety, efficient development, cross-platform usability, improved C interop, better error handling, modern features, and more maintainable software.<ref name="auto1"/>{{Sfn|Independent Laboratory|2020}}{{Sfn|Lyons|2022}}<ref name="nasufi">{{cite web |last1=Nasufi |first1=Erdet |title=An introduction to V - the vlang|url=https://debconf22.debconf.org/talks/69-an-introduction-to-v-the-vlang/ |website=DebConf |access-date=24 July 2022}}</ref> |
||
V is released and developed through [[GitHub]].<ref>{{cite web|url=https://ossinsight.io/collections/programming-language |title=GitHub Programming Languages (repository rankings)| via = [[OSS]] }}</ref><ref name="hackaday"></ref> Along with Alexander Medvednikov, the creator, its community has incorporated contributors from around the world<ref>{{cite web|url=https://ossinsight.io/analyze/vlang/v#people |title=Contributors | via = [[OSS]] }}</ref>{{Sfn|Rao|2021}} for continuous development of the compiler, language, and modules. V was released in beta sometime before version 0.4.<ref name=VlangBeta/> |
|||
[[File:Veasel.svg|thumb|Veasel is the official mascot of the V programming language{{citation needed|date=November 2023}}]] |
[[File:Veasel.svg|thumb|Veasel is the official mascot of the V programming language{{citation needed|date=November 2023}}]] |
||
== Features == |
== Features == |
||
<!-- |
|||
Please restore if there are citations, in prose form please, not as bullets |
|||
===Safety=== |
===Safety=== |
||
V has stricter policies to facilitate greater memory-safety, speed, and secure code.<ref name="section"></ref><ref name="MUO"></ref>. Among these default safety features are:<ref name="hackaday"></ref><ref name="section"></ref><ref name="Knott"></ref><ref name="MUO"></ref> 1) Usage of bounds checking. 2) Usage of Option/Result. 3) Mandatory checking of errors. 4) Variables are immutable by default. 5) Structs are immutable by default. 6) Function args are immutable by default. 7) No usage of values that are undefined. 8) No shadowing of variables. 9) No usage of null (unless in unsafe code). 10) No usage of global variables (unless enabled via flag). |
|||
* Usage of bounds checking |
|||
* Usage of Option/Result |
|||
* Mandatory checking of errors |
|||
* No usage of values that are undefined |
|||
* No shadowing of variables |
|||
* No usage of null (unless in unsafe code) |
|||
* No usage of global variables (unless enabled via flag) |
|||
* Variables are immutable by default |
|||
* Structs are immutable by default |
|||
* Function args are immutable by default |
|||
* Sum types can be used |
|||
* Generics can be used |
|||
--> |
|||
=== Performance === |
=== Performance === |
||
Line 65: | Line 48: | ||
=== Compilation time === |
=== Compilation time === |
||
⚫ | The V compiler is [[Bootstrapping (compilers)|written in itself]] and is capable of compiling itself in less than a second.<ref>{{cite web |title=V , the programming language that is making a lot of success |last1=Oliveira |first1=Marcos|url=https://terminalroot.com/vlang-the-programming-language-that-is-making-a-lot-of-success/|website=Terminal Root |date=18 January 2022 |access-date=18 January 2022}}</ref>{{Sfn|Rao|2021}}<ref name="exercism">{{cite web |title=Want to learn and master V?|url=https://exercism.org/tracks/vlang|website=Exercism|access-date=20 January 2023}}</ref> |
||
The V compiler is [[Bootstrapping (compilers)|written in itself]]. |
|||
⚫ | |||
⚫ | |||
<!-- uncited |
|||
⚫ | |||
V performs a minimal amount of memory allocation by using value types and string buffers, promoting a more simple abstraction-free style of code.{{Sfn|Rao|2021}}<ref name="section"></ref> The language's 4 supported options for memory management are the following:{{Sfn|Tsoukalos|2022}}<ref name="hackaday"></ref><ref name="developpez">{{cite web |last1=Emy |first1=Jade |title=The programming language V 0.4 Beta is available|url=https://programmation.developpez.com/actu/347826/Le-langage-de-programmation-V-0-4-beta-est-disponible-simple-rapide-sur-compile-pour-developper-des-logiciels-faciles-a-maintenir-d-apres-son-createur/ |website=developpez |date=29 August 2023 |access-date=29 August 2023}}</ref> 1) Use of an optional [[Garbage collection (computer science)|GC]] (that can be disabled) for handling allocations, and is the default. 2) [[Manual memory management|Manual memory management]] via disabling the GC (<code>-gc none</code>). 3) Autofree, which handles most objects via free call insertion, and then the remaining percentage is freed by GC (<code>-autofree</code>). 4) [[Memory pool|Arena allocation]] (<code>-prealloc</code>). |
|||
* Allocations handled by an optional GC, that is the default, which can be disabled |
|||
* Manual memory management (-gc none) |
|||
* Autofree (-autofree), handles most objects via free call insertion |
|||
** ''Remaining percentage freed by GC'' |
|||
* Arena allocation with (-prealloc) |
|||
--> |
|||
===Source code translators=== |
===Source code translators=== |
||
Line 85: | Line 61: | ||
== Syntax == |
== Syntax == |
||
{{Unreferenced section|date=November 2023}} |
|||
=== Hello world === |
=== Hello world === |
||
The "Hello, World!" program in V:<ref name="MUO"></ref> |
|||
<syntaxhighlight lang="v"> |
<syntaxhighlight lang="v"> |
||
fn main() { |
fn main() { |
||
println(' |
println('Hello, World!') |
||
} |
} |
||
</syntaxhighlight> |
</syntaxhighlight> |
||
=== Structs === |
=== Structs === |
||
Struct example:{{Sfn|Independent Laboratory|2020}} |
|||
<syntaxhighlight lang="V"> |
<syntaxhighlight lang="V"> |
||
struct Point { |
struct Point { |
||
Line 115: | Line 90: | ||
=== Heap structs === |
=== Heap structs === |
||
Structs are allocated on the stack. To allocate a struct on the heap and get a reference to it, use the & prefix: |
Structs are allocated on the stack. To allocate a struct on the heap and get a reference to it, use the & prefix:{{Sfn|Independent Laboratory|2020}} |
||
<syntaxhighlight lang="V"> |
<syntaxhighlight lang="V"> |
||
struct Point { |
struct Point { |
||
Line 131: | Line 106: | ||
V doesn't have classes, but you can define methods to types. A method is a function with a special 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. |
V doesn't have classes, but you can define methods to types. A method is a function with a special 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:<ref name="Knott"></ref>{{Sfn|Independent Laboratory|2020}} |
|||
<syntaxhighlight lang="V"> |
<syntaxhighlight lang="V"> |
||
Line 156: | Line 131: | ||
Optional types are for types which may represent none. Result types may represent an error returned from a function. |
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.<syntaxhighlight lang="V"> |
Option types are declared by prepending ? to the type name: ?Type. Result types use !: !Type.<ref name="Knott"></ref><ref name="section"></ref>{{Sfn|Tsoukalos|2022}} |
||
<syntaxhighlight lang="V"> |
|||
fn do_something(s string) !string { |
fn do_something(s string) !string { |
||
if s == 'foo' { |
if s == 'foo' { |
Revision as of 16:03, 7 November 2023
![]() The official V logo | |
Paradigms | Multi-paradigm: functional, imperative, structured, concurrent |
---|---|
Designed by | Alexander Medvednikov[1] |
First appeared | 20 June 2019[2] |
Stable release | 0.4.2[3]
/ September 30, 2023 |
Typing discipline | static, strong, infered |
Memory management | optional (automatic or manual) |
Implementation language | V |
Platform | x86-64 |
OS | Linux, macOS, Windows, FreeBSD, OpenBSD, NetBSD, DragonflyBSD, Solaris |
License | MIT |
Filename extensions | .v , .vsh |
Website | vlang |
Influenced by | |
Go, Kotlin, Oberon, Python, Rust, Swift |
V (/ˈviː/, as in the letter v) also known as vlang, is a statically typed compiled programming language created by Alexander Medvednikov in early 2019.[4] It was mostly inspired by the Go programming language, as well as other influences including Oberon, Swift, and Rust.[5][6][7] It is free and open-source software, in active development at GitHub[8][6], and released under the MIT license.
The goals of V include being easy to use and readability.[9][10][11] The language also promotes safety and the elimination of ambiguity; for example, variable shadowing is not allowed; that is, declaring a variable with a name that is already used in a parent scope will cause a compilation error.[4][12]
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.[13] Originally the language was 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] The V language was created in order to develop it, along with other software applications such as Ved (also called Vid). As the extension in use was already ".v", to not mess up the git history, it was decided to name it "V".[11] Upon public release, the compiler was written in V, and could compile itself.[4] Along with Alexander Medvednikov, the creator, its community has a large number of contributors from around the world[14][4] who have helped with continually developing and adding to the compiler, language, and modules. Key design goals behind the creation of V: easier to learn and use, higher readability, fast compilation, increased safety, efficient development, cross-platform usability, improved C interop, better error handling, modern features, and more maintainable software.[11][15][16][17]
![](https://upload.wikimedia.org/wikipedia/commons/thumb/d/d4/Veasel.svg/220px-Veasel.svg.png)
Features
Safety
V has stricter policies to facilitate greater memory-safety, speed, and secure code.[7][12]. Among these default safety features are:[6][7][9][12] 1) Usage of bounds checking. 2) Usage of Option/Result. 3) Mandatory checking of errors. 4) Variables are immutable by default. 5) Structs are immutable by default. 6) Function args are immutable by default. 7) No usage of values that are undefined. 8) No shadowing of variables. 9) No usage of null (unless in unsafe code). 10) No usage of global variables (unless enabled via flag).
Performance
At the time of 0.1.24, V was found to be as fast as C.[18][19][20] The language also supports a foreign function interface for interoperability with C.[21][22][23]
Allocations are minimized by the language,[24][better source needed] which also supports serialization without runtime reflection[18]. Native binaries compiled with no dependencies[7][25]
Compilation time
The V compiler is written in itself and is capable of compiling itself in less than a second.[26][4][27]
Memory management
V performs a minimal amount of memory allocation by using value types and string buffers, promoting a more simple abstraction-free style of code.[4][7] The language's 4 supported options for memory management are the following:[28][6][29] 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) from C.[30][31][17]
Working translators are also under development for Go, JavaScript, and WASM.[32][33]
Syntax
Hello world
The "Hello, World!" program in V:[12]
fn main() {
println('Hello, World!')
}
Structs
Struct example:[15]
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. To allocate a struct on the heap and get a reference to it, use the & prefix:[15]
struct Point {
x int
y int
}
p := &Point{10, 10}
// References have the same syntax for accessing fields
println(p.x)
Methods
V doesn't have classes, but you can define methods to types. A method is a function with a special 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][15]
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][28]
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)
References
- ^ "Creator of V". GitHub.
- ^ "First public release". GitHub. 20 June 2019.
- ^ "Latest releases". GitHub.
- ^ a b c d e f Rao 2021.
- ^ Lewkowicz, Jakub (25 June 2019). "SD Times news digest: V language now open sourced". SD Times. Retrieved 25 June 2019.
- ^ a b c d e James, Ben (23 July 2019). "The V Programming Language: Vain Or Virtuous?". Hackaday. Retrieved 23 July 2019.
- ^ a b c d e f Umoren, Samuel. "Building a Web Server using Vlang". Section. Retrieved 5 April 2021.
- ^ "GitHub Programming Languages (repository rankings)" – via OSS.
- ^ a b c d Knott, Simon (27 June 2019). "An introduction to V". Retrieved 27 June 2019.
- ^ Oliveira, Jader. "VLang for Automation Scripting". LinkedIn. Retrieved 4 June 2021.
- ^ a b c Jonah, Victor (25 February 2021). "What is Vlang? An introduction". LogRocket. Retrieved 25 February 2021.
- ^ a b c d Galuh, Rosa (8 August 2022). "A Brief Introduction to the V Language". MUO. Retrieved 8 August 2022.
- ^ "How To Maintain And Iterate With V - SYNCS 2023 (Sydney Computing Society at the University of Sydney)". YouTube. Retrieved 18 October 2023.
- ^ "Contributors" – via OSS.
- ^ a b c d Independent Laboratory 2020.
- ^ Lyons 2022.
- ^ a b Nasufi, Erdet. "An introduction to V - the vlang". DebConf. Retrieved 24 July 2022.
- ^ a b Shóstak, Vic (15 January 2020). "The V programming language". DEV. Retrieved 8 November 2021.
- ^ "C is how old now? - Learning the V programming language". l-m. 10 April 2022. Retrieved 10 April 2022.
- ^ "V language: simple like Go, small binary like Rust". TechRacho. Retrieved 3 March 2021.
- ^ Choudhury, Ambika. "Meet V, The New Statically Typed Programming Language Inspired By Go & Rust". Analytics India Magazine (AIM). Retrieved 3 July 2019.
- ^ "How to install the V programming Language on Ubuntu 20.04 / Debian 10?". osradar. 24 June 2020. Retrieved 24 June 2020.
- ^ Grabowski, Hank. "Fighting Bloat With the V Language". nequalsonelifestyle. Retrieved 25 June 2021.
- ^ "The V programming language is now open source". Packt Hub. 24 June 2019. Retrieved 24 June 2019.
- ^ Dr. Rangarajan Krishnamoorthy. "Building V Language DLL". rangakrish. Retrieved 2 April 2023.
- ^ Oliveira, Marcos (18 January 2022). "V , the programming language that is making a lot of success". Terminal Root. Retrieved 18 January 2022.
- ^ "Want to learn and master V?". Exercism. Retrieved 20 January 2023.
- ^ a b Tsoukalos 2022.
- ^ Emy, Jade (29 August 2023). "The programming language V 0.4 Beta is available". developpez. Retrieved 29 August 2023.
- ^ "Introducing the V Tutorial!". Replit. Retrieved 4 January 2021.
- ^ 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.
- ^ "Convert Go to V with go2v". Zenn. 26 January 2023. Retrieved 26 January 2023.
- ^ "The V WebAssembly Compiler Backend". l-m. 26 February 2023. Retrieved 26 February 2023.
Further Reading
- The V Programming Language basic (in Japanese). Independent Laboratory. 20 June 2020. ASIN B08BKJDRFR.
- Rao, Navule Pavan Kumar (10 December 2021). Getting Started with V Programming. Packt Publishing. ISBN 978-1839213434. OCLC 1290492862.
{{cite book}}
: CS1 maint: date and year (link) - Lyons, Dakota "Kai" (13 April 2022). Beginning with V Programming. Independently Published. ISBN 979-8801499963.
{{cite book}}
: CS1 maint: date and year (link) - Tsoukalos, Mihalis (May 2022). "Discover the V language". Linux Format Magazine (288). ISSN 1470-4234.