Content deleted Content added
Chippla360 (talk | contribs) Wikipedia:Articles for deletion/V (programming language) (4th nomination) closed as keep (XFDcloser) Tags: Mobile edit Mobile web edit |
adding for the sake of attribution |
||
(20 intermediate revisions by 8 users not shown) | |||
Line 26:
==History==
The new language was created as a result of frustration with existing languages being used for personal projects.{{sfn|Chakraborty|Haldar|2023}} It was originally intended for personal use, but after being mentioned publicly and increasing interest, it was decided to make it public. V was initially created to develop a desktop messaging client named Volt.<ref name="hackaday"/> On public release, the compiler was written in V, and could [[Self-hosting (compilers)|compile itself]].{{Sfn|Rao|2021}}{{sfn|Chakraborty|Haldar|2023}} Key design goals in creating V were being easy to learn and use, higher readability, fast compiling, increased safety, efficient development, [[Cross-platform software|cross-platform]] usability, improved [[C (programming language)|C]] [[interoperability]], better [[Error detection and correction|error handling]], modern features, and more maintainable software.<ref name="MUO"/><ref name="analyticsindiamag"/><ref name="nasufi"/><ref>{{cite web |title=V language: simple like Go, small binary like Rust|url=https://techracho.bpsinc.jp/hachi8833/2021_03_09/89457/ |website=TechRacho |access-date=3 March 2021}}</ref>
V is released and developed through [[GitHub]],<ref>{{cite web |url=https://ossinsight.io/analyze/vlang/v#overview |title=GitHub Programming Languages (repository details) |via=[[Open-source software|OSS]] Insight using [[TiDB]] }}{{Dead link|date=July 2025 |bot=InternetArchiveBot |fix-attempted=yes }}</ref><ref name="hackaday"/> and maintained by developers and contributors internationally.{{Sfn|Rao|2021}} It is among the languages that have been listed on the [[TIOBE index]].<ref>{{cite web |title=TIOBE Index |url=https://www.tiobe.com/tiobe-index |publisher=[[TIOBE index|TIOBE]]|website=tiobe |archive-url=https://web.archive.org/web/20250411043213/https://www.tiobe.com/tiobe-index/|archive-date=11 April 2025|access-date=11 April 2025}}</ref>
[[File:Veasel.svg|thumb|Veasel is the official mascot of the V programming language<ref>{{cite web |url=https://github.com/vlang/v-mascot/ |title=V's official mascot |website=GitHub |access-date=8 November 2023}}</ref>]]
Line 36:
===Safety===
V has policies to facilitate memory-safety, speed, and secure code,<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 |publisher=[[Valnet]]|website=MakeUseOf (MUO) |date=8 August 2022 |access-date=8 August 2022}}</ref><ref name="HA">{{cite web |last1=Abbas |first1=Hazem |title=Introduction to V Language and Desktop App Development |url=https://medevel.com/v-desktop-app-tutorial/ |website=medevel |date=5 August 2024 |access-date=3 January 2025}}</ref><ref name="hackaday"/> including various default features for greater program safety.<ref name="section"/><ref name="MUO"/>{{sfn|Chakraborty|Haldar|2023}} It employs [[bounds checking]], to guard against out of bounds use of [[Variable (computer science)|variables]]. Option/result [[Type system|types]] are used, where the option [[data type]] ({{code|?}}) can be represented by {{code|none}} (among possible choices) and the result type ({{code|!}}) can handle any returned errors. To ensure greater safety, error checking is mandatory. By default, the following are [[immutable]]: variables, structs, and [[Function (computer programming)|function]] [[Parameter (computer programming)|arguments]]. This includes string values are immutable, so elements cannot be mutated. Other protections, which are the default for the language, are: no use of [[undefined value]]s, [[variable shadowing]], [[null pointer]]s (unless marked as unsafe), or [[global variable]]s (unless enabled via flag).
=== Performance ===
V uses [[value type]]s and string buffers to reduce memory allocations.{{sfn|Rao|2021|p=7}}<ref>{{cite web |title=The V programming language is now open source |url=https://hub.packtpub.com/the-v-programming-language-is-now-open-sourced-is-it-too-good-to-be-true// |publisher=[[Packt Publishing]] |website=Packt Hub |date=24 June 2019 |access-date=24 June 2019}}</ref><ref name="MUO"/> The language can be compiled to human-readable C,<ref name="section"/>{{Sfn|Rao|2021}} and in terms of execution and compilation, it's considered to be as performant.<ref name="MUO"/><ref name="analyticsindiamag">{{cite web |first1=Ambika |last1=Choudhury |title=Meet V, The New Statically Typed Programming Language Inspired By Go & Rust|url=https://analyticsindiamag.com/meet-v-the-new-statistically-typed-programming-language-inspired-by-go-rust|website=Analytics India Magazine (AIM)|date=9 February 2022|access-date=7 July 2024}}</ref>{{sfn|Chakraborty|Haldar|2023}}
=== Memory management ===
V supports 4 memory management options:{{Sfn|Tsoukalos|2022}}<ref name="hackaday"/>{{sfn|Chakraborty|Haldar|2023}}
# Use of an optional [[Garbage collection (computer science)|garbage collection]] (GC), that can be disabled, for handling allocations, and is the default.
Line 50:
===Source code translators===
V supports a [[source-to-source compiler]] (transpiler) and can translate C code into V.<ref name="analyticsindiamag"/><ref>{{cite web |first1=Sarah |last1=Schlothauer |website=JAXenter
Working translators are also being developed for Go, [[JavaScript]], and [[WebAssembly]].<ref>{{cite web |title=Convert Go to V with go2v|url=https://zenn.dev/tkm/articles/go2v-with-go-lsd|website=Zenn |date=26 January 2023 |access-date=26 January 2023}}</ref><ref>{{cite web |title=The V WebAssembly Compiler Backend|url=https://l-m.dev/cs/the_v_webassembly_compiler_backend/|archive-url=https://web.archive.org/web/20240708075458/https://l-m.dev/cs/the_v_webassembly_compiler_backend/ |website=l-m |date=26 February 2023 |archive-date=8 July 2024}}</ref>{{Sfn|Rao|2021}}
Line 56:
== Syntax ==
=== Hello world ===
The [["Hello, World!" program]] in V:<ref name="MUO"/><ref name=":0">{{Cite web |title=V Documentation |url=https://docs.vlang.io/ |access-date=2025-08-25 |website=docs.vlang.io}} {{Free-content attribution|title = V Documentation| license statement URL =https://github.com/vlang/v?tab=MIT-1-ov-file| license=The MIT License|this = yes}}</ref>
<syntaxhighlight lang="v">
fn main() {
Line 64:
=== Variables ===
Variables are immutable by default and are defined using {{code|1=:=}} and a value. Use the {{code|mut}} [[reserved word]] (keyword) to make them mutable. Mutable variables can be assigned to using {{code|1==}}:{{sfn|Rao|2021|pp=28-40}}<ref name=":0" />
<syntaxhighlight lang="V">
mut
</syntaxhighlight>
Redeclaring a variable, whether in an inner scope or in the same scope, is not allowed:{{sfn|Rao|2021|pp=28-40}}<ref name=":0" />
<syntaxhighlight lang="V">
{
}
</syntaxhighlight>
=== Structs ===
Struct example:<ref name="Knott"/><ref name="section"/><ref name=":0" />
<syntaxhighlight lang="
struct
name string
score f32
}
// Struct fields can be initialized by name
var1 := Foo {
number: 21
name: "baz"
score: 2.5
}
// or by position
</syntaxhighlight>
=== Heap structs ===
By default, structs are allocated on the stack. When structs are referenced by using the prefix {{code|1=&}} or have the heap attribute, they are allocated on the heap instead:{{sfn|Rao|2021}}<ref name=":0" />
<syntaxhighlight lang="
struct
}
@[heap]
number f32
}▼
// Structs that are referenced are heap allocated
var1 := &Foo{2}
// Baz is always heap allocated because of its [heap] attribute
var2 := Baz{4.5}
</syntaxhighlight>
Line 116 ⟶ 126:
[[Method (computer programming)|Methods]] in V are functions defined with a receiver [[Parameter (computer programming)|argument]]. The receiver appears in its own argument list between the fn keyword and the method name. Methods must be in the same [[Modular programming|module]] as the receiver type.
The
struct Client {
enrolled bool
▲struct User {
}
fn (
return x.enrolled
}
println(Client{enrolled: true}.enrolled_status()) // true
println(Client{enrolled: false}.enrolled_status()) // false
▲}
</syntaxhighlight>
=== Error handling ===
<syntaxhighlight lang="V">
fn
if
}
println(
println(
</syntaxhighlight>
Line 175:
* {{Cite book |last1=Lyons |first1=Dakota "Kai" |date=April 13, 2022 |title=Beginning with V Programming |publisher=Independently Published |isbn=979-8801499963 |language=en |ref=none}}
* {{cite journal |last1=Tsoukalos |first1=Mihalis |date=May 2022 |title=Discover the V language |publisher=[[Linux Format]]| journal=Linux Format Magazine |issue=288 |issn=1470-4234}}
* {{Cite book |last1=Chakraborty |first1=Soubhik |last2=Haldar |first2=Subhomoy |date=December 6, 2023 |title=Randomness Revisited using the V Programming Language |publisher=[[Nova Science Publishers]] |isbn=979-8891133280 |language=en
* {{Cite book |last1=Trex |first1=Nova |date=24 December 2024 |title=V Programming: Building Robust and Efficient Software Systems |publisher=Wang Press |isbn=979-8304813778}}
|