4
\$\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.

hyperneutrino
42.8k5 gold badges72 silver badges227 bronze badges
asked Jun 1, 2021 at 14:25
\$\endgroup\$
0

2 Answers 2

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

answered Jun 1, 2021 at 18:49
\$\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).

answered Jun 1, 2021 at 18:35
\$\endgroup\$

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.