12 ms·
I coded something dumb and I'm proud of it
- leononame 2y agoI don't think it's dumb. After all, the array can change in between renders, so you kind of have to start from scratch anyways. And for a list of <1000, who cares?
- drfreckles 2y agoExactly :)
- Idiot211 2y agoFYI: The link to "You're the OS" points to localhost OP :)
- ryankrage77 2y agohttps://plbrault.itch.io/youre-the-os https://plbrault.itch.io/youre-the-os
- drfreckles 2y agoOof! I was definitely tired! Thank you!
- Idiot211 2y agoAll good! We all have those moments!
- dontupvoteme 2y agothis is an evil take but i think emojis are massively, massively underrated for use in signaling information (and massively overused in git readmes) A grimacing emoji when a process is thrashing, a fire emoji when it's eating CPU, a sweating smile emoji when the process is running longer than expected, etc etc etc. It sounds dystopian in a way but also useful - neat seeing them used here!
- reidjs 2y agoAgree, especially for conveying tone, eg, happy, frustration, danger, etc, especially in dialog. There is an art to using them to enhance a message instead of obscuring it, though.
- nvartolomei 2y agoYou’ll love to learn more about Chernoff faces! https://en.wikipedia.org/wiki/Chernoff_face https://en.wikipedia.org/wiki/Chernoff_face
- AnimalMuppet 2y agoMore dystopian (and maybe more useful): A roll-eyes emoji when you're asking it to do something stupid. (It's more dystopian, because the computer has to know when you're asking it to do something stupid. Even more dystopian: It gives you the roll-eyes when you ask it to do something that it doesn't want to do.)
- leononame 2y agoPersonally, I disagree. I'm probably in the minority, but emojis don't helot me much when conveying information and I see them more as visual clutter that makes it difficult to distinguish what's going on. This is especially the case when there are a lot of emojis (or other icons for that matter) instead of text, e.g. in menus. It makes it much harder for me to distill the information and it takes me longer to grok what's going on. Maybe I'm just a less visual type than others, but emojis actively make my experience worse. I like them in chat though. Edit: to clarify, e.g. the process list makes it harder for me, because there are emojis on every process. I'd find it a tad more helpful if there were only emojis on processes with events and healthy processes would just have nothing (like the hourglass only being present in some processes). Color coding the background also makes it much more difficult to distinguish the emojis for me.
- colechristensen 2y agoThe young will use and understand them much more. How many years will it be before the Oxford English Dictionary begins listing definitions for individual and groups of emoji? In 100 years they will just be an ordinary feature of language somewhere between a word and a punctuation mark.
- syndicatedjelly 2y agoI played this game a few months ago and it was a lot of fun. Nice work :)
- formerchamp 2y ago[dead]
- deleted 2y ago[deleted]
- cratermoon 2y agoIf you didn't care about efficiency, why not use bubblesort?
- drfreckles 2y agoBecause the animation needs to pretend to use something more efficient.
- jandrese 2y agoIronically the particulars of this implementation make it much less efficient than a dumb bubble sort. Many Quicksort implementations have the worst performance on already sorted data, and in this case it will be run a lot on data that is already mostly sorted. It won't matter here because the data size is always trivially tiny, but it is something to consider in the real world.
- drfreckles 2y agoAgain, the need was not to implement an efficient sort. It was to implement an animation that pretends to execute an efficient sort. Also, quicksort gives a more interesting result visually.
- cratermoon 2y agoThere's also the overhead of quicksort compared to bubblesort, making it a poor choice for tiny sets of data. In this case I understand the author's point is to have something visually interesting to show the work being done.
- gumby 2y ago> you are the operating system of a computer. "I am Jack's ALU"
- timetraveller26 2y ago"I am AMD's idle cpu cycles"
- zwirbl 2y agoI am Jacks branch prediction vulnerability
- jimt1234 2y agoI just wanna throw this up here, because I found it to be a fascinating take on 'Fight Club': https://www.youtube.com/watch?v=wHE7oBvOk9U https://www.youtube.com/watch?v=wHE7oBvOk9U
- kettro 2y agoWell done! It is exactly the correct approach — especially with the dataset potentially changing at each iteration, treating it as a contiguous sequence of executions is wrong anyways. Plus, you should always strive to reduce state as much as possible.
- mjmdavis 2y agoHonestly this comes across as a smart solution, not a dumb one. You big smartie. Such a smart guy. Geez. You're so smart, you're very productive and are helping advance society. Thank you.
- tleb_ 2y agoAnother way to describe what has been done: implement a pure function and avoid storing additional state. It sounds way less dumb that way. It is not really a pure function but the spirit is here. I've done the same during a refactoring of a side-project recently. It handles the input/output to a MIDI controller with many buttons, knobs and matching LEDs. Instead of computing what LED should change at regular interval, I am switching to recomputing the whole state each time. No more complex logic, no more mutable data. Only a pure function that outputs the desired LED state based on software internal state. Then a diff is computed and only changes lead to MIDI messages. Code is less efficient (for 100-ish LEDs) but much more straight forward.
- pavlov 2y agoThis is how React works, or at least the illusion it presents to the developer. Where it goes awry and gets complicated is that web developers want to modify the input state directly within the same functions that produce the output state, and they also want to trigger side effects after the output state has been completed, requiring another pass. I’ve built a React variant for video compositing. Since it renders at a steady frame rate, there’s no reason to ever trigger re-renders. The useState() and useEffect() hooks are practically useless. To my personal taste it’s a sweet spot for React, and I wonder if some kinds of web apps might benefit from similar simplification to the state approach.
- recursive 2y agoI've also struggled with React's insistence on immutability. What if mutability was the only way to update state? I implemented a JSX-powered react-alike that explored the concept[1]. To my lack of surprise, I found the resulting environment easier to get stuff done in. I'm not subjecting my employer to this, but I would totally use this on a solo project that I had to support. [1] https://github.com/tomtheisen/mutraction https://github.com/tomtheisen/mutraction
- p2edwards 2y agoThis is awesome. Thanks for making it.
- willhackett 2y agoYou know what, this is spot on! And, I'm happy you're proud of it.
- ww520 2y agoActually it’s clever not dumb. It partial evaluates to the first change then stops. It does the job and no more. Very insightful. I’m stealing this idea. :)
- AstroJetson 2y agoJust spent 15 mins working as the OS, it's much harder than it looks. I just had a nice word with my browser with the 200+ tabs open, I now know how it feels. Only upgrade I'd make is how fast my "task switching" is, I'd like to think it was subsecond, but it's not. If you haven't played give it a shot. Then play the insane mode, with all the cores and memory it's pretty amazing to keep it all running. As to your code, pretty interesting idea. As noted (above?) I've also done control work, we only send a message to update the display when the value actually changes. Since we are on something like a CAN bus, we can't hog things making display changes at the expense of sensor readings.
- deleted 2y ago[deleted]
- dclowd9901 2y agoIt's honestly one of the hardest things for me, trying to explain to more junior developers that clever almost is never better. Does anyone have any good litmus or heuristic for figuring out when something is "too" clever? I was thinking of a way to quantify "complexity" in a process by a sort of "reference counting" style metric, where the moment you have to reference some other location to figure something out, you add 1 to a number and if that number gets above some figure, it's too complex.
- sgarland 2y agoIf I don't understand something I wrote a month later, it was too clever. Unfortunately, this is a massively lagging indicator.
- Arrath 2y agoYeah that's the textbook example of closing a barn door after the horse gets out, eh?
- tstrimple 2y agoThere's the cyclomatic complexity which I think gets close to your reference counting example. https://en.wikipedia.org/wiki/Cyclomatic_complexity https://en.wikipedia.org/wiki/Cyclomatic_complexity But I don't think that captures most of the "too clever" stuff I typically see. That's usually some abomination of a one liner that does way too much. Those won't get picked up by cyclomatic complexity measurements. Furthermore, I find cyclomatic complexity tends to come from less experienced developers rather than experienced developers trying to be clever. If you're genuinely wondering if something is too clever, ask that junior dev to explain it to you. After all, they will probably be the ones to end up maintaining it later.
- jrochkind1 2y agoThis is kind of fun. A random nit as we like: > I needed to somehow create a function that performs a single step of the algorithm, then gives back control to the main loop (which ironically sounds just like an OS' preemptive scheduling) That sounds more like cooperative scheduling, no?
- drfreckles 2y agoYou're right! I rephrased that.
- fragmede 2y agoYay! This game didn't get much traction the first time it got posted so I'm really glad it's getting some more attention.
- passion__desire 2y agoDoes there exist something similar for human body?
- xg15 2y agoI know this is exactly the opposite of the point OP wanted to make, but wouldn't this be the perfect use case for generators? You could modify the quicksort in python like this: def quicksort_with_steps(arr: [Process]): # Standard Quicksort operations if len(arr) <= 1: yield arr return pivot = arr[len(arr) // 2] left = [process for process in arr if process.sort_key < pivot.sort_key] middle = [process for process in arr if process.sort_key == pivot.sort_key] right = [process for process in arr if process.sort_key > pivot.sort_key] # the magic happens here: # sort each half and pass through the intermediate results of the "sub-sorters" to our own caller, # after modifying them so they contain the entire array again: # left half: left_final = None for left_intermediate in quicksort_with_steps(left): # we're iterating over the "yield" calls here, not the sorted array. yield left_intermediate + middle + right # pass on the intermediate result to our own caller. left_final = left_intermediate # the last iteration has the "final" result for the left side, so store it. assert left_final is not None # the generator always yields at least one result, so this shouldn't happen. # right half: (shorter because we don't have to store anything) for right_intermediate in quicksort_with_steps(right): yield left_final + middle + right_intermediate # the last "yield" returns the fully sorted array. Then if you call the function, it will return an iterator over all the steps of the algorithm. You could either put it in a for loop like in the recursive calls, or "manually" advance it one step using python's next() function, e.g. inside a frame callback. I'm pretty sure, if you're insane enough, you could also whip up something using async/await where the algorithm literally "awaits" the end of the animation...