Content deleted Content added
Correction of how books were cited. Put into proper format, so links works and they can be used elsewhere in article. |
Wiki-link words and removed erroneous dead link |
||
(48 intermediate revisions by 19 users not shown) | |||
Line 1:
{{Short description|General-purpose programming language}}
{{Use dmy dates|date=November 2023}}{{Infobox programming language
| name = V
Line 13 ⟶ 12:
| programming language = V
| typing = [[Static typing|static]], [[Strong and weak typing|strong]], [[Type inference|inferred]]
| memory management = [[
| platform = [[x86-64]]
| operating system = [[Linux]], [[macOS]], [[Windows]], [[FreeBSD]], [[OpenBSD]], [[NetBSD]], [[DragonflyBSD]], [[Oracle Solaris|Solaris]]
| license = [[MIT License|MIT]]
| file ext = <code>.v</code>, <code>.vsh</code>
| website = {{URL|https://vlang.io}}
| influenced by = [[Go (programming language)|Go]], [[Kotlin (programming language)|Kotlin]], [[Oberon (programming language)|Oberon]], [[Python (programming language)|Python]], [[Rust (programming language)|Rust]], [[Swift (programming language)|Swift]]
}}
'''V''', also known as '''vlang''', is a [[Static type checking|statically typed]], [[Compiled language|compiled]] [[programming language]] created by Alexander Medvednikov in early 2019.{{Sfn|Rao|2021}} It was inspired by
The goals of V include ease of use, [[
==History==
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}}</ref><ref name="hackaday"
[[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>]]
== Features ==
<!--
===Safety===
V has policies to facilitate memory-safety, speed, and secure code
=== 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
=== Memory management ===
# Use of an optional [[Garbage collection (computer science)|
# [[Manual memory management]] via disabling the GC (<code>-gc none</code>).
# Autofree, which handles most [[Object (computer science)|objects]] via free call insertion, and then the remaining percentage is freed by GC (<code>-autofree</code>).
# [[Memory pool|Arena allocation]] (<code>-prealloc</code>).
===Source code translators===
V supports a [[source-to-source compiler]] (transpiler) and can translate C code into V.<ref name="analyticsindiamag"
Working translators are also
== 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 65 ⟶ 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_memory|stack]]. When structs are referenced by using the prefix {{code|1=&}} or have the {{code|1=[heap]}} attribute, they are allocated on the [[Heap-based_memory_allocation|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>
=== Methods ===
[[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 {{code|1=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 172 ⟶ 171:
== Further reading ==
* {{Cite book |date=June 20, 2020 |title=The V Programming Language basic |publisher=Independent Laboratory |asin=B08BKJDRFR |asin-tld=jp |language=ja |ref=none}}
* {{Cite book |
* {{Cite book |
* {{cite journal |
* {{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 |
== External links ==
Line 185 ⟶ 183:
* [https://github.com/vlang/v/blob/master/doc/docs.md Documentation]
* [https://modules.vlang.io/ Modules]
* [https://www.youtube.com/watch?v=pchEsYwA74Q Video: How To Maintain And Iterate With V (Sydney Computing Society)]
* [https://www.youtube.com/watch?v=_dIAcNp9bJs Video: A small presentation of V's features at IBM]
[[Category:2019 software]]
Line 200:
[[Category:Statically typed programming languages]]
[[Category:Systems programming languages]]
<!-- Hidden categories below -->
[[Category:Articles with example code]]
|