What tips do you have for code-golfing in the V lang? I have been trying to find ways to shorten codegolfs on there but can't find any resources on it. Do you guys have any?
Please suggest tips that are at least somewhat specific to the V programming language (e.g. "remove comments" isn't helpful).
Please post one tip per answer.
2 Answers 2
When making an instance of a struct, you can omit argument names if they're in the right order.
Person{age:-1
name:"bar"}
Person{-1"bar"}
If the type is already known, you can omit Person, but you'll have to explicitly give the field names.
When making a change to an object, you can copy it by placing ...x at the start (where x is the object to copy from).
Remove unnecessary whitespace
Take the following code:
mut x:="foo"
println(x)
x+="bar"
println(x)
You can rewrite the code like so:
mut x:="foo"println(x)x+="bar"println(x)
This is still perfectly valid syntax. In general, any two statements can be combined if they are separated by a symbol (though this is not always the case).