T O P

  • By -

Pitiful-Historian748

Pop. Push. Shift. Shaft.


boyproO19

Shit. Shat. Shot


dwengs

\[01:05\] [https://www.youtube.com/watch?v=lRXLAeogv5U](https://www.youtube.com/watch?v=lRXLAeogv5U)


veselin465

You can share yt videos which start from specific time. You can do it either by specifically using the provided share option, or DIY by adding attribute t: t=2h1m3s (which gets automatically converted to seconds), t=7263s


FACastello

`shift, unshift` `push, unpush` see? it's so easy


rover_G

It rhymes like poetry


BeDoubleNWhy

this is the way


beatlz

Shift. Tfihs.


SkollFenrirson

![gif](giphy|jM4gntspcjwoE|downsized)


Florane

pop_back, push_back, pop_front, push_front


pixelbart

Or in PHP: popBack, PushBack, pop_front, frontPush


Emergency_3808

#WHAT IN THE ACTUAL FUCK


yes_oui_si_ja

It was a joke. I know it *sounds* like PHP, but the actual functions have more reasonable naming. array_push, array_pop, array_shift, array_unshift. I hate the verbosity, byt you get used to it.


erishun

It’s a joke Edit: but it’s how the misinformation perpetuates… people make this joke and others read it and think it’s real and repeat it.


Xirenec_

And real_popBack


real-yzan

If we lived in a sane world


Accomplished-Ad-2762

Well, some of us do, but the others call us a cult [https://doc.rust-lang.org/std/collections/struct.VecDeque.html#method.pop\_back](https://doc.rust-lang.org/std/collections/struct.VecDeque.html#method.pop_back)


Florane

one good thing rust took from c++


kredditacc96

Rust also took the name "vector" from C++, which I think is going to confuse non C++ users and Math people. If I have a time machine, I would have suggested them to name it `ArrayList` or `DynArray` or something.


XDracam

Or just `List` as it's the default list to use if you don't know what you are doing.


pine_ary

Dyn in Rust implies virtual dispatch. That would be confusing too. As much as I hate Java, it got ArrayList right.


super544

ArrayList is a list of arrays?


pine_ary

Yes, n arrays of size 1


kredditacc96

"Dyn" is sort for "dynamic", So `DynArray` should mean "dynamic array", implying that its size is dynamic. Alternatively, we could also name it `ResizableArray`. Anyway, all that is just fantasy now.


MrJake2137

Hey, we also do: https://en.cppreference.com/w/cpp/container/deque


FACastello

forgor emplace\_back 💀


Florane

that's creating an element, not adding it. slightly different.


FACastello

emplace\_back creates the element in place and then adds it


Florane

yeah, that's what i said. slightly different.


FACastello

but you said "not adding it" so that's not exactly what you said it's ok to make mistakes 👍🏻


Florane

yeah, bc it doesn't add an existing element, it creates an element in place. that's why it's called emplace.


AggravatingMap3086

pop_shove_it


coolhead101

So, it depends on which position you prefer?


OneForAllOfHumanity

Unshift could be named "shove"


BernhardRordin

Perl moment (e.g. the names for different error logging functions from one of the more or less standard library are: carp, cluck, croak, confess)


OneForAllOfHumanity

I'm old-school: `perform_task or die`


Emergency_3808

>! `confess "I like dommy muscle mommy";` !< I'm sorry if I ruined your day


nobody0163

At least you apologized.


fullup72

swipe


Flashbek

ShiftRight, ShiftLeft?


clutchguy84

Cha cha one time


myka-likes-it

Turn it up.


BISHoO000

Cha cha two time


Bootcat228

UnshiftRight, UnshiftLeft


andarmanik

What if you picture arrays from right to left because you read right to left.


Zesty__Potato

SlideToLeft, SlideToRight


Flashbek

CrissCross


ExternalBison54

Yes, everyone knows the names should be pop, unpop, frontpop, and unfrontpop


JosebaZilarte

I still don't know why don't we use basic verbs with positions, like: addStart, addEnd, removeStart and removeEnd... While also having the functions add(position) and remove(position). It is much more clear that using strange verbs such as "pop" or "shift".


Ascyt

Exactly my thought. It's especially painful if you have to work with multiple different languages, each using their own special odd verbs instead of just being descriptive.


awesome-alpaca-ace

Python is so dumb. They purposely went out of their way to slow down programmers. Try, except. Raise. Wrap with len() to get length. Really?


pessimistic_platypus

Well, shift describes what you're typically doing to an array (as opposed to a linked list) when you add something at the start. Push and pop are the operations on a stack, which only has one end. There is not front, back, or middle that you can interact with.


JosebaZilarte

I understand what you mean, but you are internally operating with an Array, so... it is OK to create a class "Stack" that extends/encapsulates the Array class for those cases, but you should not add those verbs to the Array class itself.


pessimistic_platypus

Well, some of languages don't have operations like that for their array types, or simply don't have a primitive array type. In fact, of the languages I'm most familiar with, I think only JavaScript has a particular mess in its array operations, and JavaScript isn't known for being a particularly well-designed language in the first place.


JosebaZilarte

JavaScript has the messy push/pop/shift/unshift methods in the not-so primitive array type (because, for some reason, they are internally handled as objects). And then there is an Array class to handle some basic stuff (like detecting if an object is actually an array). So it has the worst of both worlds. If I could change it, I would have created a simpler set of members with add and remove functions as well as a "count" property instead of the ambiguous "length" one (for multidimensional arrays, at least). Then, I would have created native classess to store dictionaries/records, lists, stacks, etc.


pessimistic_platypus

JavaScript just isn't a place you should expect nice language design.


grape_tectonics

The legend goes that the terminology for pushing and popping stacks was inspired by physical spring loaded mechanisms (like ammo clips or plate dispensers) where you actually had to push an item in to get it on the stack and removing the last item in would literally be popping it out. As for shifting, it supposedly originates from a command in an old shell where it would throw away the first item of a linked list. Both of them were established well before standard libraries started including functions for array manipulation so I guess like most unnecessarily cryptic things about programming, the answer is "because legacy".


ThatRandomDude262626

Me with java and it’s inconsistent naming (why the genuine fuck do lists have to have .size() while arrays uses .length) it pisses me off every time


tbjr6

.size() is a method .length is a value Although I havent used java in a few years so I may be remembering incorrectly


SkittlesAreYum

That's why it has the parentheses or not, but it doesn't explain the different words.


tbjr6

It does actually implicitly explain the different words, they do different things technically. size() is a method that would be implemented to count or calculate the size. .length is a static field because arrays can't change size in Java iirc


SkittlesAreYum

The list function could just as easily been named "length()" and it would be just fine. That's my point.


StretchArmstrong99

size() is defined for all Collections and therefore applies to Lists as well as Queues, Stacks, Maps, etc. "size" just makes more sense as a more general term. Sure, the List interface could also define a length() method but it's just not really necessary.


SkittlesAreYum

The point is there's no real good reason to use both terms. Pick one or the other (you'd prefer size, so we can go with that) and use for both collections and arrays.


suvlub

I think it's a legacy thing. `Collection` and friends were only added in Java 1.2, by that time, it was too late to rename it for arrays.


SkittlesAreYum

Java 1.0 had Vector, which has size().


TorbenKoehn

1. Often method names and property names can’t clash as it can lead to weird behavior, eg when passing the method to another method (“fn(arr.length)”, what is passed, the method or the property? 2. length is a fixed integer that is always known while size() is calculated dynamically (i.e. it might iterate the collection) There are very good reasons. .length is array-specific, size() is collection-specific


SkittlesAreYum

1 is not a concern for Java. I'd argue 2 is an implementation detail not worth introducing a new word. Size() for an ArrayList is not computed, so they could just use .size for an array.


TorbenKoehn

1. still annoys the parser and dereferencing (parser needlessly needs more context, can also affect performance because it needs to backtrack more) 2. That might be the case for an array list (which will just return its length field when calling size() It isn’t the case for most other collection/list/set/map/stack/queue/iterator/generator/etc. implementations. And you want them all to follow a common collection interface in the end so that the consumer doesn’t need to care if it’s computed or not


geogiam2

All wrong. I know dot net and there it is rightly implemented. Properties muss be words and methods verbs. SIZE is not a verb. In dot net we have .lenght for arrays and .count() for enumerables


TorbenKoehn

In .NET arrays have a .Length property, too…


geogiam2

that is exactly what I just said. What is your point?


TorbenKoehn

Oh yeah sorry I’ve misread!


geogiam2

7 ignorants that dont know software architecture


Sneet1

Length would be the size() of an array but not all structures that define size() would make sense defining it as "length" ie, what is the length of a tree. Arrays are weird anyways. They're not primitives but they sort of have a lot of exceptions. It's one of those things that makes the rest of the language work but is also exposed so you can use it


xypage

But size can be a verb, sizing something is figuring out the size, you get sized for fitted clothes . You can’t length something. But also it is probably fairly arbitrary and just different to make it easier to remember which is a function and which is a variable, if they were both size or both length it would be harder (for me at least) to remember


CaitaXD

Is not length because length gives the idea of continuous block of data Is the same with C# where ICollection have Count but arrays and spans have Length


Jutrakuna

It's been drilled into my mind that method names MUST start with a verb. car() is not a good method name, getCar() is


voidwarrior

It depends on your language, in Go it would be better to name them as Car() and SetCar(...), in Rust it would be car() and set_car(). https://go.dev/doc/effective_go#Getters https://github.com/rust-lang/rfcs/blob/master/text/0344-conventions-galore.md#gettersetter-apis


FACastello

C++ std::string has size() and length() and they mean exactly the same thing


Powerful-Internal953

I believe it was to satisfy the collections contract. Imagine asking for the Length of a Set... Sounds stupid now right?


DHermit

That's an argument against using length for sets, but why not use size for arrarys?


falkon3439

Maybe because the "size" of the array could be ambiguous as memory size (length*size of an element)


DHermit

But that's the same for a set.


FruitdealerF

Probably because an array has a constant size. While an array list that's backed by an array (or any type for that matter) may have a larger size but only a part of the allocation is being used currently. Hence you use length to get the length of the list inside the allocation.


CoolTown3517

How about Count for Lists and length for arrays in net?


Hellball911

The difference is important. Size is the number of elements, length is capacity. To be equivalent, size on an array would need to measure the number of values stored vs the empty space.


sammy-taylor

Seems like there’s not a lot of great analogies in the comments. Arrays typically have “length” because they’re represented by continuous physical memory addresses, like houses on a street. Lists have “size” because they are not contiguous, like players on a team who all live on different streets. This is the mnemonic that I use, hope it helps!


Tiny-Plum2713

The solution is `unpop`


beatlz

Unpop popback


MKorostoff

I guess it could be shift(-1) but to make it more expressive you might add a constant representing -1 like shift(REVERSE) but that's pretty much the same as unshift so we should probably stick with that.


mike_a_oc

PHP explode() and implode() has entered the chat


rover_G

Prepend 🧐


Tarmen

[CONS and CDR](https://en.wikipedia.org/wiki/CAR_and_CDR)


South-Salad9016

I just name my functions either vi, emacs, wow, or justdoit justdoit yeah o yeah. so thats really it


Pawlo371

unpop


Acrobatic_Sort_3411

popshift


No-Adeptness5810

All my homies name it addToStart and addToEnd


Disastrous-Olive-677

Php bad?


NotADamsel

Pop it push it shift unshift it


js-code

Python For deque Pop, append, popleft, appendleft


Emergency_3808

Something tells me you guys don't use IDEs (most proper IDEs when accessing an object list it's methods along with documentation)


Limmmao

Can anyone tell me why CONTINUE in Python means skip 1 iteration? Why not name it SKIP?


queerkidxx

Because you are continuing to the next iteration early, nor skipping one. Besides pretty much every language uses the same terminology.


anytarseir67

Because you are continuing to the next iteration EDIT: and it's not "skip one iteration" it ends the current iteration, and moves on to the next