V for C#/Java developers — Mission
Sections
Reading settings
No voice for this language in this browser.
More voices
Code and English terms
Off: the page’s voice reads everything, with no pause between two voices.
No voice for this language in this browser.
More voices
More voices: Microsoft Edge has natural online voices, and Windows (Settings › Time & language › Speech), macOS and Android install others.
Why I’m learning this
Section titled “Why I’m learning this”V promises a small language, close to Go, that compiles to C in about a second, with immutable variables by default, no null, no exceptions, and a garbage collector you can turn off.
I write C# and read plenty of Java. I want to know which of these promises hold in version 0.5.2, what V costs in exchange, and where its documentation and its compiler disagree.
Who this course is for
Section titled “Who this course is for”You are comfortable with C# or Java: classes, interfaces, generics, exceptions, collections, LINQ or streams. You have never written V, and you don’t need to know C. Each lesson starts from the concept you already know and shows where V agrees, where it differs, and what the compiler says when you get it wrong.
V in one table
Section titled “V in one table”| C# | Java | V | |
|---|---|---|---|
| Compiles to | IL, run by the CLR | bytecode, run by the JVM | C, compiled to a native executable |
| Build tool | dotnet |
Maven, Gradle | v itself |
| Project file | .csproj |
pom.xml, build.gradle |
v.mod (optional) |
| Local variable | var x = 1; (mutable) |
var x = 1; (mutable) |
x := 1 (immutable), mut x := 1 |
| Class | class, record, struct |
class, record |
struct with methods, no inheritance |
| Absent value | null, int? |
null, Optional<T> |
?T and none |
| Failure | exceptions | checked and unchecked exceptions | !T, error() and or { } |
| Memory | generational GC | GC (G1 by default) | Boehm GC by default, -autofree, -gc none |
| Namespaces | namespace |
package |
one module per folder |
| Visibility | public, internal, private |
public, package-private, private |
pub or private to the module |
Sources: .NET garbage collection, G1 garbage collector, V documentation.
The documentation and the version
Section titled “The documentation and the version”docs.vlang.io is built from doc/docs.md on V’s master branch, which has moved on since 0.5.2: its page The default compiler, for example, isn’t in the documentation of 0.5.2. This course links to docs.vlang.io for the concepts and checks every behavior with 0.5.2 itself; the documentation of the version studied is doc/docs.md at the 0.5.2 tag, and the standard library is described at modules.vlang.io.
The data
Section titled “The data”Lessons 3 and 4 read code/v-for-csharp-java/data/pages.csv: the 319 pages of this site at commit cbcbb42, with their locale, course, title and number of lines. It is a copy of the file the LadybugDB course extracts from this repository.
Lessons 5 to 8 read code/v-for-csharp-java/data/ga: the 111 .NET projects of GuitarAlchemist/ga at commit a26a7893, their 266 project references and 478 package references, copied from the LadybugDB course too. Lesson 7 walks their references in parallel, lesson 8 tests a module that parses them.
By the end of this course, I will be able to
Section titled “By the end of this course, I will be able to”- install V on Windows, Linux and macOS, and organize a program in modules;
- model data with structs, methods, interfaces and sum types instead of classes;
- handle absence and failure with
?,!andor { }instead ofnulland exceptions; - say where an array, a map or a struct is copied, shared or freed;
- write concurrent code with
spawnand channels; - test, format and document a module, and call a C library.
Outline
Section titled “Outline”| # | Lesson | You already know |
|---|---|---|
| 1 | Installation, v run, modules and projects |
dotnet new, dotnet run, javac, java |
| 2 | Types, immutable variables, structs and methods | var, readonly/final, classes, records |
| 3 | Errors: ?, ! and or { } |
null, Optional, exceptions |
| 4 | Arrays, maps, slices and memory | List<T>, Dictionary, ArrayList, HashMap, the GC |
| 5 | Interfaces and generics | interfaces, generics, constraints |
| 6 | Enums, sum types and match |
enums, sealed hierarchies, switch expressions |
| 7 | Concurrency: spawn, channels and shared |
Task, CompletableFuture, virtual threads, lock/synchronized |
| 8 | Tests, v fmt, v vet and v doc |
xUnit/JUnit, dotnet format, analyzers, XML doc comments |
| 9 | Calling C (coming next) | P/Invoke, JNI, the FFM API |
| 10 | JSON and a web server with veb |
System.Text.Json, ASP.NET Core, Jackson, Spring |
| 11 | The ORM and SQLite | Entity Framework, JPA |
| 12 | Packages, cross-compilation and deployment | NuGet/Maven Central, dotnet publish, jlink |
| — | Journal |
Resources
Section titled “Resources”- V documentation, and
doc/docs.mdat the 0.5.2 tag - V standard library
- V source code, and the 0.5.2 release this course uses
- V’s language tests: the documentation says the compiler and its tests are the reference when they disagree with it