Paradigms | Multi-paradigm: functional, imperative, structured, concurrent |
---|---|
Designed by | Alexander Medvednikov [1] |
First appeared | 20 June 2019 [2] |
Stable release | |
Typing discipline | static, strong, inferred |
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, 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]
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]
V has policies to facilitate memory-safety, speed, and secure code. [7] [17] [18] 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).
V uses value types and string buffers to reduce memory allocations. [19] [20] [17] The language can be compiled to human-readable C [4] [21] and is considered to be as performant. [17]
The language's 4 supported options for memory management are the following: [22] [6] [21]
-gc none
).-autofree
).-prealloc
).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]
The "Hello, World!" program in V: [17]
fnmain(){println("Hello, World!")}
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:=1mutb:=2b=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
Struct example: [12]
structPoint{xintyint}mutp:=Point{x:10y:20}println(p.x)// Struct fields are accessed using a dot// Alternative literal syntax for structs with 3 fields or fewerp=Point{10,20}assertp.x==10
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]
structPoint{xintyint}p:=&Point{10,10}// References have the same syntax for accessing fieldsprintln(p.x)
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]
structUser{ageint}fn(uUser)is_registered()bool{returnu.age>16}user:=User{age:10}println(user.is_registered())// "false"user2:=User{age:20}println(user2.is_registered())// "true"
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] [22]
fndo_something(sstring)!string{ifs=="foo"{return"foo"}returnerror("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 tracebackprintln(a)println(b)
In object-oriented (OO) and functional programming, an immutable object is an object whose state cannot be modified after it is created. This is in contrast to a mutable object, which can be modified after it is created. In some cases, an object is considered immutable even if some internally used attributes change, but the object's state appears unchanging from an external point of view. For example, an object that uses memoization to cache the results of expensive computations could still be considered an immutable object.
D, also known as dlang, is a multi-paradigm system programming language created by Walter Bright at Digital Mars and released in 2001. Andrei Alexandrescu joined the design and development effort in 2007. Though it originated as a re-engineering of C++, D is now a very different language. As it has developed, it has drawn inspiration from other high-level programming languages. Notably, it has been influenced by Java, Python, Ruby, C#, and Eiffel.
In computer programming, foreach loop is a control flow statement for traversing items in a collection. foreach is usually used in place of a standard for loop statement. Unlike other for loop constructs, however, foreach loops usually maintain no explicit counter: they essentially say "do this to everything in this set", rather than "do this x times". This avoids potential off-by-one errors and makes code simpler to read. In object-oriented languages, an iterator, even if implicit, is often used as the means of traversal.
In computer programming, an entry point is the place in a program where the execution of a program begins, and where the program has access to command line arguments.
In some programming languages, const is a type qualifier that indicates that the data is read-only. While this can be used to declare constants, const in the C family of languages differs from similar constructs in other languages in that it is part of the type, and thus has complicated behavior when combined with pointers, references, composite data types, and type-checking. In other languages, the data is not in a single memory location, but copied at compile time for each use. Languages which use it include C, C++, D, JavaScript, Julia, and Rust.
Scala is a strong statically typed high-level general-purpose programming language that supports both object-oriented programming and functional programming. Designed to be concise, many of Scala's design decisions are intended to address criticisms of Java.
this, self, and Me are keywords used in some computer programming languages to refer to the object, class, or other entity which the currently running code is a part of. The entity referred to thus depends on the execution context. Different programming languages use these keywords in slightly different ways. In languages where a keyword like "this" is mandatory, the keyword is the only way to access data and methods stored in the current object. Where optional, these keywords can disambiguate variables and functions with the same name.
The C and C++ programming languages are closely related but have many significant differences. C++ began as a fork of an early, pre-standardized C, and was designed to be mostly source-and-link compatible with C compilers of the time. Due to this, development tools for the two languages are often integrated into a single product, with the programmer able to specify C or C++ as their source language.
C++11 is a version of a joint technical standard, ISO/IEC 14882, by the International Organization for Standardization (ISO) and International Electrotechnical Commission (IEC), for the C++ programming language. C++11 replaced the prior version of the C++ standard, named C++03, and was later replaced by C++14. The name follows the tradition of naming language versions by the publication year of the specification, though it was formerly named C++0x because it was expected to be published before 2010.
This article describes the syntax of the C# programming language. The features described are compatible with .NET Framework and Mono.
In computer programming, variable shadowing occurs when a variable declared within a certain scope has the same name as a variable declared in an outer scope. At the level of identifiers, this is known as name masking. This outer variable is said to be shadowed by the inner variable, while the inner identifier is said to mask the outer identifier. This can lead to confusion, as it may be unclear which variable subsequent uses of the shadowed variable name refer to, which depends on the name resolution rules of the language.
In computer programming, a constant is a value that is not altered by the program during normal execution. When associated with an identifier, a constant is said to be "named," although the terms "constant" and "named constant" are often used interchangeably. This is contrasted with a variable, which is an identifier with a value that can be changed during normal execution. To simplify, constants' values remains, while the values of variables varies, hence both their names.
Go is a fast statically typed, compiled high-level general purpose programming language. It is known for its simplicity and efficiency. Its simplicity express through its basic syntax of the language itself and its large library that help the developer to have a small stack for its project. It was designed at Google in 2009 by Robert Griesemer, Rob Pike, and Ken Thompson. It is syntactically similar to C, but also has memory safety, garbage collection, structural typing, and CSP-style concurrency. It is often referred to as Golang to avoid ambiguity and because of its former domain name, golang.org
, but its proper name is Go.
Rust is a general-purpose programming language emphasizing performance, type safety, and concurrency. It enforces memory safety, meaning that all references point to valid memory. It does so without a traditional garbage collector; instead, memory safety errors and data races are prevented by the "borrow checker", which tracks the object lifetime of references at compile time.
Kotlin is a cross-platform, statically typed, general-purpose high-level programming language with type inference. Kotlin is designed to interoperate fully with Java, and the JVM version of Kotlin's standard library depends on the Java Class Library, but type inference allows its syntax to be more concise. Kotlin mainly targets the JVM, but also compiles to JavaScript or native code via LLVM. Language development costs are borne by JetBrains, while the Kotlin Foundation protects the Kotlin trademark.
Swift is a high-level general-purpose, multi-paradigm, compiled programming language created by Chris Lattner in 2010 for Apple Inc. and maintained by the open-source community. Swift compiles to machine code and uses an LLVM-based compiler. Swift was first released in June 2014 and the Swift toolchain has shipped in Xcode since Xcode version 6, released in September 2014.
Nim is a general-purpose, multi-paradigm, statically typed, compiled high-level system programming language, designed and developed by a team around Andreas Rumpf. Nim is designed to be "efficient, expressive, and elegant", supporting metaprogramming, functional, message passing, procedural, and object-oriented programming styles by providing several features such as compile time code generation, algebraic data types, a foreign function interface (FFI) with C, C++, Objective-C, and JavaScript, and supporting compiling to those same languages as intermediate representations.
Zig is an imperative, general-purpose, statically typed, compiled system programming language designed by Andrew Kelley. It is free and open-source software, released under an MIT License.
Gleam is a general-purpose, concurrent, functional high-level programming language that compiles to Erlang or JavaScript source code.