V: Appending an element to an array.

Created on 28 Jun 2019  路  5Comments  路  Source: vlang/v

On twitter there was a poll related to appending an element to an array. 54% were in favour of using a method called push to achieve that.

In the vlib code I saw that there is a public method called _push. Can that be renamed to push?

That would be overall a better fit than <<. Another advantage of the method call is that it would play nicely with autocompletion.

Feature Request

All 5 comments

The results were close, I think they would be even closer if there were only two options.

Anyway, I gave this a lot of thought and decided to leave <<.

First, it's already implemented and it works. Second, this is a very frequently used operation, and it is a bit more readable and clean:

users.push(User{
  name: 'Bob'
  age: 20
})

users << User{
  name: 'Bob'
  age: 20
}

Have you considered using actually both? Let the user choose what to use?

That goes against one of V's main rules: only one way of doing things :)

I don't think << is an apt operator for appending to an array.

You introduced an extra operator just for appending to an array, which goes (from what I find) against the design philosophy of V. While arrays are very cool and one of the fundamental data structures, I do not think that they deserve their own operator.

This also introduces inconsistencies. Why to I have to << to push to an array, but delete() elements from it?


The results were close, I think they would be even closer if there were only two options.

Sorry, but that is not true鹿:

image

push has the absolute majority there, if you were to combine all other answers they wouldn't be as popular as push.


I have to admit that this was a bit of a rant, but I do think that push would be beneficial for V's future! I think V has enormous potential and want you to at least reconsider your decision.

Thank you.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

oleg-kachan picture oleg-kachan  路  3Comments

clpo13 picture clpo13  路  3Comments

medvednikov picture medvednikov  路  3Comments

radare picture radare  路  3Comments

PavelVozenilek picture PavelVozenilek  路  3Comments