V: function parameters with a defaut value

Created on 19 Oct 2019  路  7Comments  路  Source: vlang/v

please think about default parameters hat allow for easy calls.

fn (v mut x) dummy(path string, x1 int = 100, y1 int = 200) foo {...}

calls like:

x.dummy("foo")
x.dummy("foo", 500)
x.dummy("foo", 500, 1000)

Feature Request

Most helpful comment

This goes against the philosophy of V.

All 7 comments

This goes against the philosophy of V.

This goes against the philosophy of V.

Why ?

It could also be the occasion to have function kwargs:

dummy("path", y1:300)

After all, there is already this kind of struct initialiation in V:

s := MyStruct{ b: 6}

@Nicoco220983 @Delta456
Nicco - that correct. it is not question of personal feeling, but rather of usability.

@medvednikov
please think about it

@medvednikov have you got an opinion about that yet?

This has already been discussed here #453.
Bottomline: default parameters won't be allowed in functions but I believe there are plans to include them in structs. Don't know for sure.

@r-k-o default struct values have been implemented, so they can be used instead.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

medvednikov picture medvednikov  路  3Comments

arg2das picture arg2das  路  3Comments

penguindark picture penguindark  路  3Comments

clpo13 picture clpo13  路  3Comments

cjmxp picture cjmxp  路  3Comments