Last in, first out?
May 15, 2009 1:01 PM   Subscribe

In software that's designed to process a set of files or records, why do you sometimes see that the last record in the set is processed first? Is this some kind of processing convention, programming limitation, or what?

I was uploading batches of photos using Flickr Uploadr today, and I noticed that the last photo iadded to the batch was always uploaded first. Then, the first photo was uploaded, and it progressed through the batch sequentially. It reminded me that I've seen this behavior before - in a custom application at work that processes sets of database records. So, I was just wondering if it's a coincidence, or if it's done on purpose for some reason.
posted by cabingirl to Computers & Internet (10 answers total)
It's the Windows file picker; for whatever reason it does this when multiple files are selected. Your browser opens a standard Windows file dialog to let you select files to upload, so the filenames are handed back to the browser by Windows in this order.
posted by orthogonality at 1:13 PM on May 15, 2009 [2 favorites]

I bet what's going on is totally a user-interface phenomenon. In many GUI (graphical user interface) programming libraries, list boxes have two different methods: one for getting the single "current" item (the one with a border around it) and one for getting a list of all the items that are selected (the dark-blue ones). Probably, these programmers write code that looks like this:

1. Process the current item
2. Did the user also select some other items? If so, process them too.

The thing is, if you're selecting items from top-to-bottom, the current item is going to be the last one you selected--so it will process that one first, then it will go through all the other items in order. Does this explain the behavior you're seeing?
posted by goingonit at 1:29 PM on May 15, 2009 [3 favorites]

Yes, orthogonality has it right, it's a Windows file selection thing. You'll get the same issue if you, for example, open a folder of media files, select them, and drag-drop them into a media player playlist. And as goingonit says, it's because the last item ends up being the "current item" when you're done making your selection. You can fix this issue by selecting the first item last (such as by dragging a selction box from the bottom up rather than the top down).
posted by burnmp3s at 1:34 PM on May 15, 2009 [1 favorite]

This is purely a guess, but could it have something to do with the desirability of using the fewest places to enumerate members of a set?

For example, if you had 8 objects and wished to give them each a binary number, you could get away with using only three places only if you were willing to number one of them '000', but in that case, you have the choice of naming the first one '000' the second '001' and so on, but that has the unfortunate feature of giving each member of the set a number name one less than its rank in the set-- or you could give each member of the set a number that corresponds exactly with its rank except the last, which you would number '000'.

Then suppose some software wants to do something with this set (like upload) and has an instruction which amounts to 'take the smallest number first'. That software would then take the last member of your set first.
posted by jamjam at 2:01 PM on May 15, 2009 [1 favorite]

Technically it's called a stack as opposed to a queue. Generally with a stack you push something onto it, and pop the last thing off of it. But to be honest, I can't think of a good reason why you would choose to do one or the other unless you were working in a scheme or lisp.
posted by KirkJobSluder at 3:28 PM on May 15, 2009

I disagree the previous posters. I think it's because flickr presents photos most-recently-uploaded first.

If the app uploaded your images in the order that they're displayed in the app, 1.jpg then 2.jpg then 3.jpg, when you went to flickr you'd see 3.jpg then 2.jpg then 1.jpg. People using the app might find this surprising.
posted by jjwiseman at 4:52 PM on May 15, 2009

Response by poster: jjwiseman: that is how they appear in your recent activity (like on the home page) but if you are viewing a set, they can be sorted differently. In the set in question I think I had them sorted by "date uploaded - oldest first." As they were uploaded, I would refresh the set window, and the new files appeared at the end of the set.

I like the Windows file picker answer and it makes sense to me. However, using the PC version of the Flickr Uploadr, the filenames are being returned to the app window, not the browser. When I view them in the app window, the last file is shown last. It's only in the actual upload process that the last file ends up being the first.

Also, the work app doesn't use the Windows file picker. It uses a search screen to query a SQL database and select records.
posted by cabingirl at 5:42 PM on May 15, 2009

Orthogonality has it. The other situation you see this frequently is drag-and-drop. Most people will select from the top, control-click the bottom, and start dragging from the bottom. This makes the last first. If it bothers you, you can drag from the top.
posted by Horselover Fat at 6:07 PM on May 15, 2009

Duh, does it have an "undo?"
posted by KirkJobSluder at 7:02 PM on May 15, 2009 [1 favorite]

Oh, and you can go in the Organizr and sort the set by time taken, oldest to newest, then save the order, if you want.

(Just started playing with Flickr a few days ago)
posted by vsync at 6:51 AM on May 17, 2009

« Older ( ) technical ( ) legislative ( ) market-based ( )...   |   Who's reading? Newer »
This thread is closed to new comments.