Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds Array#prepend and Array#append. #5629

Closed

Conversation

chris-huxtable
Copy link
Contributor

@chris-huxtable chris-huxtable commented Jan 22, 2018

Aliases for unshift and push.

Hopefully this won't be super controversial.

The current unshift/pusharen't well matched and a PITA to remember. Ruby recently, in 2.5, finally added them. I think it would make sense to add them to our Array as well.

Aliased `unshift` and `push`.
@chris-huxtable chris-huxtable changed the title Adds Array.prepend and Array.append. Adds Array#prepend and Array#append. Jan 22, 2018
@asterite
Copy link
Member

They are controversial. We don't have aliases in Crystal.

@RX14
Copy link
Contributor

RX14 commented Jan 22, 2018

Perhaps rename unshift to prepend, but no aliases please.

@chris-huxtable
Copy link
Contributor Author

chris-huxtable commented Jan 22, 2018

If absolutely no alias's are permitted I would propose replacing unshift and push. Even though that would be a crippling, breaking change.

I do understand the importance of push if you are using an Array as a stack, but in the context on an Array append makes much more sense.

@chris-huxtable
Copy link
Contributor Author

If it helps I can sed -i 's/.unshift/.prepend/g' **/*.cr && sed -i 's/.push/.append/g' **/*.cr and push that.

@Sija
Copy link
Contributor

Sija commented Jan 22, 2018

Removing Array#push and/or Array#unshift will break a lot of code since they are well-known widely-used idioms.

@chris-huxtable
Copy link
Contributor Author

@Sija - Thats why I am proposing the aliases.

@Sija
Copy link
Contributor

Sija commented Jan 22, 2018

@chris-huxtable I know, yet Crystal doesn't like/use those (aliases).

@chris-huxtable
Copy link
Contributor Author

chris-huxtable commented Jan 22, 2018

@Sija - Something that I think is unfortunate. In different contexts similar functions have different names. Let alone the issue with unshift.

@straight-shoota
Copy link
Member

Whatever gets decided, it will have some downside.

  • push/unshift are widely known and very common accros languages, but difficult to get used to for beginners.
  • append/prepend are much easier to comprehend - starting from a blank state they should really be preferred IMO. Yet, having only those would break much code and would alienate experienced programmers.
  • having both would introduce aliases which should be avoided in Crystal.

I don't know which way is best. We should look for the least evil.

@chris-huxtable
Copy link
Contributor Author

chris-huxtable commented Jan 22, 2018

I don't really understand the aversion of aliases other then API bloat and support. Which aren't insignificant issues. But an outright 'ban' I think as equally problematic.

One of the other things that has confused me is the 'prescriptive' nature of Crystal which is very Python. Where as Ruby is more 'descriptive' which is one of the things I appreciate about it. That is to say there is more then one way to skin a cat.

@Sija
Copy link
Contributor

Sija commented Jan 22, 2018

We should look for the least evil.

No such thing exists, I'd look for better solution :)

@RX14
Copy link
Contributor

RX14 commented Jan 22, 2018

But having direct aliases with no difference always creates more api for no gain. So why bother?

I like push and pop for the end of a list, buy also like prepend and ??? For the start of a list.

Why not just have insert and delete with, 0 and -1 for both these cases?

@chris-huxtable
Copy link
Contributor Author

@RX14 - That strikes me as a bit extreme.

@asterite
Copy link
Member

Array as it is now works fine. These aliases were just recently introduced in Ruby, I never needed them. Old Ruby coders will now find these new aliases and wonder why they exist. This means they have to learn new things. Maybe decide what name to use from now on.

All of this is a big waste of time, nothing else.

@ysbaddaden
Copy link
Contributor

I'm getting tired of issues and pull requests that merely revolve around "matter of taste and preference". Nobody will agree.

We have push, pop, shift and unshift. They're ubiquitous across many languages. They're fine. Close subject. Please.

@rdp
Copy link
Contributor

rdp commented Apr 1, 2020

I know it came from Ruby but... #unshift is really awkward, sadly... :|

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants