V (programming language): Difference between revisions

Content deleted Content added
No edit summary
m remove arbitrary fixed sizes
Line 3:
| name = V
| logo = V Logo SVG.svg
| logo size = 140px
| logo caption = The official V logo
| logo alt = A capitalized letter V colored blue
Line 13 ⟶ 12:
| programming language = V
| typing = [[Static typing|static]], [[Strong and weak typing|strong]], [[Type inference|inferred]]
| memory management = [[List_of_programming_languages_by_typeList of programming languages by type#Languages_with_optional_manual_memory_managementLanguages with optional manual memory management|optional]] ([[Garbage collection (computer science)|automatic]] or [[Manual memory management|manual]])
| platform = [[x86-64]]
| operating system = [[Linux]], [[macOS]], [[Windows]], [[FreeBSD]], [[OpenBSD]], [[NetBSD]], [[DragonflyBSD]], [[Oracle Solaris|Solaris]]
Line 22 ⟶ 21:
}}
 
'''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 language [[Go (programming language)|Go]], and other influences including [[Oberon (programming language)|Oberon]], [[Swift (programming language)|Swift]], and [[Rust (programming language)|Rust]].<ref>{{cite web |last=Lewkowicz |first=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 |last=James |first=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 |last=Umoren |first=Samuel |title=Building a Web Server using Vlang |url=https://www.section.io/engineering-education/building-web-server-with-vlang |website=Section |archive-url=https://web.archive.org/web/20230313021526/https://www.section.io/engineering-education/building-web-server-with-vlang|archive-date=13 March 2023|access-date=5 April 2021}}</ref> It is [[free and open-source software]] released under the [[MIT License]], and currently in [[Software_release_life_cycleSoftware release life cycle#Beta|beta]].<ref name=VlangBeta>{{Cite web |title=The V Programming Language |url=https://vlang.io/ |access-date=2023-11-04 |website=vlang.io}}</ref>
 
The goals of V include ease of use, [[Computer_programmingComputer programming#Readability_of_source_codeReadability of source code|readability]], and [[Maintainability#Software|maintainability]].<ref name="Knott">{{cite web |last=Knott |first=Simon |date=27 June 2019 |title=An introduction to V |url=https://simonknott.de/articles/vlang/ |access-date=27 June 2019}}</ref><ref name="nasufi">{{cite web |last=Nasufi |first=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>
 
==History==
According to various sources, 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>{{sfn|Chakraborty|2023}}{{Sfn|Trex|2024}} 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.<ref name="hackaday"/> Upon public release, the compiler was written in V, and could compile itself.{{Sfn|Rao|2021}}{{sfn|Chakraborty|2023}} 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.{{Sfn|Independent Laboratory|2020}}{{Sfn|Lyons|2022}}<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}}</ref><ref name="hackaday">< /ref> and maintained by developers and contributors from around the world.{{Sfn|Rao|2021}}{{Sfn|Trex|2024}}
 
[[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 37 ⟶ 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 |website=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>{{Sfn|Trex|2024}} The language has various default features for greater program safety.<ref name="section">< /ref><ref name="MUO">< /ref>{{Sfn|Trex|2024}} It employs [[bounds checking]], to guard against out of bounds usage of variables. Option/result [[Type_systemType system|types]] are used, where the option 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, the checking of errors are mandatory in V. By default, 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 value|undefined values]]s, no [[variable shadowing|shadowing of variables]], no usage of [[null pointer|null]] (unless code marked as unsafe), and no usage of [[global variable|global variables]]s (unless enabled via flag).
 
=== Performance ===
Line 57 ⟶ 56:
== Syntax ==
=== Hello world ===
The [["Hello, World!" program]] in V:<ref name="MUO">< /ref>
<syntaxhighlight lang="v">
fn main() {
Line 115 ⟶ 114:
 
=== 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 [[Modular_programmingModular programming|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">
Line 142 ⟶ 141:
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 {{code|?}} to the type name: ?Type. Result types use {{code|!}}: !Type.<ref name="Knott">< /ref><ref name="section">< /ref>{{Sfn|Tsoukalos|2022}}
<syntaxhighlight lang="V">
fn do_something(s string) !string {