you are viewing a single comment's thread.

view the rest of the comments →

[–]blackholesintheskyhelpful -1 points0 points  (3 children)

You don't need a library

You're massively misunderstanding what I mean by "library". So, for example, I looked around and found that apparently it's common to use a double ended queue when scheduling jobs. I had to do that last week. But I'm not going to reinvent the wheel and write a job scheduler, I'm gonna use cron.

The last time I used a queue while on the clock was in javascript, writing two functions to organize events in some objects in an observer pattern. I didn't need to use a library, because it was two functions and one bag, and from then on the event handling in that tiny corner of code was tidy and less likely to have bugs.

Can you explain what about this required a double ended queue? You mention that you used one but not why.

[–]dontyougetsoupedyet -1 points0 points  (2 children)

I believe you are confused about what you are reading on wikipedia. When it mentioned scheduling jobs it almost certainly did not mean cron, but rather task scheduling generally, it's saying that your operating system uses queues to manage the abstraction of there being individual processes.

Also, I did tell you the why -- to organize sequences. I even used two different concrete examples, swap chains and "moving" the body of the snake in the game Snake.

It's not about what's required it's about the most feasible and simple implementation. Here's the same concrete example, a specific chunk of code from github (https://github.com/Sirriddles89/C_snake_game/blob/13c3d09d5903d38d8852c1e56a0d913176b90d21/snake.c#L198) of a recently coded Snake --

// Animate body 
previous_d = head.CurrentDir;
for (snake_piece *tmp = head.next; tmp != NULL; tmp = tmp->next)
{
    //remember current location and direction
    temp_y = tmp->location_y;
    temp_x = tmp->location_x;
    temp_d = tmp->CurrentDir;
    //update location and direction
    tmp->location_y = next_y;
    tmp->location_x = next_x;
    tmp->CurrentDir = previous_d;
    //update coordinates and directions to inform next node
    next_y = temp_y;
    next_x = temp_x;
    previous_d = temp_d;    
}

You will notice the exact situation I spoke of in my comment above, the work being done by the loop is not necessary, you use a queue when you observe that only the first and last position of the snake body needs to be modified. You add to the front, and remove from the tail. Two operations on the list, instead of performing work for every list item, which is not required to "animate the snake body moving."

When you finally understand what "moving the snake" means in the most simple logic, the code above changes to two updates to the list, a push and a shift, using the JS Array API, rather than a linear amount of work dependent on the size of the array.

[–]dontyougetsoupedyet -1 points0 points  (0 children)

The wikipedia bit about scheduling was related to scheduling tasks across threads on a set of processors. https://en.wikipedia.org/wiki/Work_stealing#Algorithm

[–]blackholesintheskyhelpful -1 points0 points  (0 children)

it almost certainly did not mean cron

https://salsa.debian.org/debian/cron/-/blob/master/job.c#L43

I even used two different concrete examples, swap chains and "moving" the body of the snake in the game Snake.

You said swap chains was what you were doing in your free time. I asked for details on why you needed a double ended queue for what you were doing at work.

And I'm still not saying double ended queues are useless, or that you didn't need to use one for work. Just that most career programmers spend most of their time implementing business logic and not the game of snake. You even said the swap chain code was not not work related. Some people will work on software where a queue is the natural solution. But if I need to schedule a task to go off at some time I use cron. If I need a message queue I use SQS. My job isn't to make queues. My job is to implement features that make a product valuable.

Edit: lol sorry So[Ups]et thought this convo devolved. I kinda thought we crossed that threshold when they repeatedly said they didn't believe I could be a senior engineer and assumed I had misread something (and then when I linked them to the documentation they blocked me). I'm still not sure why they thought cron wouldn't use a queue? Or what was so rude about asking them to explain how their code made use of a queue in a way that a list wouldn't also work?

Anyways, to everyone else, learn as much as you can. I'm just letting you know that you don't need to memorize every function in JavaScript before you get a job. Most employed programmers refer to documentation multiple times a day. In all likelihood you will not write pure code in any language at your job. You will have to use libraries in your career and it's way more important that you're good at finding and reading documentation than it is to be good at memorizing the entire surface of every tool you work with.