3
\$\begingroup\$

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.

\$\endgroup\$
0
3
\$\begingroup\$

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).

\$\endgroup\$
1
\$\begingroup\$

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).

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.