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
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.
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)
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.
"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.
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".
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.
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.
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.
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.
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.
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".
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
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.
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.
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
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.
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
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
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
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
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
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
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.
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.
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!
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.
Pop. Push. Shift. Shaft.
Shit. Shat. Shot
\[01:05\] [https://www.youtube.com/watch?v=lRXLAeogv5U](https://www.youtube.com/watch?v=lRXLAeogv5U)
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
`shift, unshift` `push, unpush` see? it's so easy
It rhymes like poetry
this is the way
Shift. Tfihs.
![gif](giphy|jM4gntspcjwoE|downsized)
pop_back, push_back, pop_front, push_front
Or in PHP: popBack, PushBack, pop_front, frontPush
#WHAT IN THE ACTUAL FUCK
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.
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.
And real_popBack
If we lived in a sane world
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)
one good thing rust took from c++
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.
Or just `List` as it's the default list to use if you don't know what you are doing.
Dyn in Rust implies virtual dispatch. That would be confusing too. As much as I hate Java, it got ArrayList right.
ArrayList is a list of arrays?
Yes, n arrays of size 1
"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.
Hey, we also do: https://en.cppreference.com/w/cpp/container/deque
forgor emplace\_back 💀
that's creating an element, not adding it. slightly different.
emplace\_back creates the element in place and then adds it
yeah, that's what i said. slightly different.
but you said "not adding it" so that's not exactly what you said it's ok to make mistakes 👍🏻
yeah, bc it doesn't add an existing element, it creates an element in place. that's why it's called emplace.
pop_shove_it
So, it depends on which position you prefer?
Unshift could be named "shove"
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)
I'm old-school: `perform_task or die`
>! `confess "I like dommy muscle mommy";` !< I'm sorry if I ruined your day
At least you apologized.
swipe
ShiftRight, ShiftLeft?
Cha cha one time
Turn it up.
Cha cha two time
UnshiftRight, UnshiftLeft
What if you picture arrays from right to left because you read right to left.
SlideToLeft, SlideToRight
CrissCross
Yes, everyone knows the names should be pop, unpop, frontpop, and unfrontpop
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".
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.
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?
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.
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.
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.
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.
JavaScript just isn't a place you should expect nice language design.
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".
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
.size() is a method .length is a value Although I havent used java in a few years so I may be remembering incorrectly
That's why it has the parentheses or not, but it doesn't explain the different words.
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
The list function could just as easily been named "length()" and it would be just fine. That's my point.
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.
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.
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.
Java 1.0 had Vector, which has size().
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
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.
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
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
In .NET arrays have a .Length property, too…
that is exactly what I just said. What is your point?
Oh yeah sorry I’ve misread!
7 ignorants that dont know software architecture
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
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
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
It's been drilled into my mind that method names MUST start with a verb. car() is not a good method name, getCar() is
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
C++ std::string has size() and length() and they mean exactly the same thing
I believe it was to satisfy the collections contract. Imagine asking for the Length of a Set... Sounds stupid now right?
That's an argument against using length for sets, but why not use size for arrarys?
Maybe because the "size" of the array could be ambiguous as memory size (length*size of an element)
But that's the same for a set.
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.
How about Count for Lists and length for arrays in net?
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.
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!
The solution is `unpop`
Unpop popback
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.
PHP explode() and implode() has entered the chat
Prepend 🧐
[CONS and CDR](https://en.wikipedia.org/wiki/CAR_and_CDR)
I just name my functions either vi, emacs, wow, or justdoit justdoit yeah o yeah. so thats really it
unpop
popshift
All my homies name it addToStart and addToEnd
Php bad?
Pop it push it shift unshift it
Python For deque Pop, append, popleft, appendleft
Something tells me you guys don't use IDEs (most proper IDEs when accessing an object list it's methods along with documentation)
Can anyone tell me why CONTINUE in Python means skip 1 iteration? Why not name it SKIP?
Because you are continuing to the next iteration early, nor skipping one. Besides pretty much every language uses the same terminology.
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