|
I mean, I don't think it's bubble sort, it's selection sort with dragging? I think you'd expect to have: Max, ???? Next Max, Max, ???? Next Next Max, Next Max, Max, ???? etc?
|
# ? May 10, 2022 02:43 |
|
|
# ? May 28, 2024 15:55 |
|
Plorkyeran posted:Look at the actual comparison it's doing. It isn't actually bubble sort. All O(n^2) sorts are the same, even if this one is twice the worst case of a bubble sort in comparisons and more but still n^2 in copies.
|
# ? May 10, 2022 02:55 |
|
Selection sort is probably closer in raw behavior. I forget that one exists.Thranguy posted:All O(n^2) sorts are the same Not entirely accurate at face value. Quicksort is n2 if pivot selection is intentionally bad. That's where I was at bringing up bubble sort or whatever though, because it's just one of those double iterating algos without any shortcutting logic. "Behaves like x if you did x badly" is an infinite set of sort algos. It's neat though. I threw it in python just to double check there wasn't something extra stupid going on like only working on even cardinality or something. Python question: Is foo[i], foo[j] = foo[j], foo[i] relatively new behavior, or was I really missing out on such a nice shortcut back in school (~7 years ago)? Ranzear fucked around with this message at 03:13 on May 10, 2022 |
# ? May 10, 2022 03:07 |
|
I decided to implement this in a sort visualizer. https://www.sortvisualizer.com/customsort/ JavaScript code:
And left it named selectionSort so you didn't have to change the entry point.
|
# ? May 10, 2022 03:16 |
|
People, read the linked paper. They already explain that it behaves like exchange sort on the first outer loop iteration, and then insertion sort on subsequent iterations with a bunch of redundant passes.
|
# ? May 10, 2022 03:19 |
|
ExcessBLarg! posted:People, read the linked paper. They already explain that it behaves like exchange sort on the first outer loop iteration, and then insertion sort on subsequent iterations with a bunch of redundant passes. I didn't leave academia back into industry to READ!
|
# ? May 10, 2022 03:28 |
|
ExcessBLarg! posted:People, read the linked paper. I barely shitpost effectively before coffy, I'm sure as gently caress not digging into a pdf. Unrelated: fembot has officially corrupted the autocorrect on my phone.
|
# ? May 10, 2022 03:32 |
|
Yeah, there’s a bunch of little things it does in the first iteration which would be practically helpful if the algorithm was actually useful, but the succinct correctness proof is simpler than that: (1) in the first iteration, it finds a maximal element and moves it to the front; (2) as an invariant between iterations, the prefix up to index i-1 is sorted, and the maximal element is at index i-1; (3) the effect of the iteration is to insert the element at index i into its proper position in the now-longer prefix, reestablishing the invariant, and then do nothing.
|
# ? May 10, 2022 03:57 |
|
New Yorp New Yorp posted:you can write good code in any language. This postulate is disputed, as it has never been demonstrated
|
# ? May 10, 2022 04:02 |
|
Good code and correct code are exclusively different things.
|
# ? May 10, 2022 04:12 |
|
Ranzear posted:Good code and correct code are exclusively different things. I don't think that's what the objection is about.
|
# ? May 10, 2022 04:23 |
|
I wasn't disagreeing. "One can write correct code in any language" is unobjectionably true, as otherwise it wouldn't be a complete language. No doubt there is plenty of 'correct' code that isn't 'good' in any language, but a language where no code is good but can still be correct can certainly exist. This isn't even my personal pedantry. She has code in the unix kernel. I mean the 1970s one.
|
# ? May 10, 2022 04:33 |
|
Rottbott posted:They did a nice cross-platform abstraction for online stuff and then didn't bother to implement bits of it for Steam even though it was dead simple to do so. Unity can't get away with that poo poo because it's closed source and they can't rely on their customers doing it for them. Yeah, it may be relevant to mention that most of my work is consulting, especially for online stuff, so "Epic didn't implement a bunch of the online stuff for <platform>" means I get work.
|
# ? May 10, 2022 04:56 |
|
Ranzear posted:Python question: Is foo[i], foo[j] = foo[j], foo[i] relatively new behavior, or was I really missing out on such a nice shortcut back in school (~7 years ago)? It's been around for a long time but idk how long; probably as long as tuple unpacking, whenever that got introduced
|
# ? May 10, 2022 05:55 |
|
D34THROW posted:I want to see what's considered "good code" in brainfuck It's the same thing as in most languages: use whitespace to show structure, use comments to explain intent (which is very important in Brainfuck, just as in assembly). This is an example of somewhat good Brainfuck, although it's unrealistic in the sense that you normally wouldn't comment this much. This is a more realistic example, and in particular it uses whitespace to show the control flow (up to a limit). This is what most people think of when they think of Brainfuck code, but it's not really what it looks like when you write it. The page even mentions that this has been passed through a comment remover. Nobody expects "good code" to transcend what is fundamentally possible in the language, but even in a dilapidated bathroom, you should wipe and flush after taking a poo poo.
|
# ? May 10, 2022 06:06 |
|
Like the brainfuck examples, you can write "good" code, or at least, understandable-the-best-you-can code in assembler using the same approach. But one of the main benefits of C over assembler is that the structure provided by the language itself goes a long way to making the code understandable without having to duplicate all the logic between generally-opaque instructions and the explanatory comments. And basically every systems language since C has been designed to make it easier to write increasingly-complex applications that are both understandable and correct (or at least, with better fail-safes) than the last.
|
# ? May 10, 2022 12:02 |
|
Ranzear posted:Good code and correct code are exclusively different things. confused face (!)
|
# ? May 10, 2022 12:48 |
|
Ranzear posted:Good code and correct code are exclusively different things. There is no limit on aesthetics or performance if your code is not required to actually work.
|
# ? May 10, 2022 14:43 |
|
Tei posted:confused face (!) Not all correct code is good code. That's the gist. 'Correct' code works perfectly, it might even have documented proof of completeness, but that doesn't mean it's good code. Strong example: Code golf submissions. There are professionals who operate entirely on that logic where correct code is obviously good code ... If only that were at least true until someone else has to submit a change or even just maintain it. There are also those cases where the code is completely perfectly correct in the most restricted scope possible, like completely sandboxed from external interaction or in some other way can't share variables or resources with other code that should be able to access those, that it's useless to anyone else trying to develop on top of it. I didn't mean to imply they were mutually exclusive things, just that they are entirely separate concepts that shouldn't be confused. Ranzear fucked around with this message at 03:28 on May 11, 2022 |
# ? May 11, 2022 03:26 |
|
Right now I'm working on 6-700 lines of correct code that hopefully will be 50 lines of good, correct code when I'm done.
|
# ? May 11, 2022 07:00 |
|
Ranzear posted:Not all correct code is good code. That's the gist. 'Correct' code works perfectly, it might even have documented proof of completeness, but that doesn't mean it's good code. Strong example: Code golf submissions. oh, you mean using the definition of "correct" has "it compiles and does what is supposed to do". I suppose is fine. I suppose my confusion was because if I am doing a code review, and I find completelly ofuscated code, I am not going to accept that, I am going to make a lot of questions and suggestions. code is not only supposed to run on a machine, thats a binary, code is supposed to be read by human beings (and a compiler), so if is hard to read, is not quite doing his job
|
# ? May 12, 2022 12:40 |
|
But a compiler or interpreter is less demanding than a human. Good code to me works, is well-commented where it needs to be, uses meaningful variable names, and is otherwise self-documented. When poo poo is obscure, I comment my code. Even in my current project, I completely forgot what a chunk of code I wrote a month ago does, or what my ultimate goal was with it, because I didn't comment it well. I mean...why do I have 2 functions to serialize a class in the same mixin?
|
# ? May 12, 2022 14:16 |
|
The only good code is deleted code
|
# ? May 12, 2022 14:17 |
|
You miss 100% of the bugs you don't write.
|
# ? May 12, 2022 15:09 |
|
Volte posted:The only good code is deleted code Vigil continues to be the best software project
|
# ? May 12, 2022 17:02 |
|
Tei posted:oh, you mean using the definition of "correct" has "it compiles and does what is supposed to do". I suppose is fine. The person whom I picked up these notions from developed them regarding code as in stacks of punch cards. Rather stark difference in opinions about correctness over fast iteration when crashing the machine is 20 minutes of downtime for everyone with their own hundreds of cards already loaded in the magazine while they fish yours out. I'd just append "and only what it's supposed to do" to your statement just for completeness. To be honest I'll take the rigorous ugly code over bloated pretty code all day erry day, as long as that rigor is well communicated.
|
# ? May 12, 2022 17:30 |
|
if the code is hard to read, is hard to mantain, hard to optimize, and the other isms. some people write code that works 100% and may not pay any attention to the isms. that code is a timebomb
|
# ? May 12, 2022 17:51 |
|
Ranzear posted:The person whom I picked up these notions from developed them regarding code as in stacks of punch cards. Rather stark difference in opinions about correctness over fast iteration when crashing the machine is 20 minutes of downtime for everyone with their own hundreds of cards already loaded in the magazine while they fish yours out. A lot of the established wisdom in our field dates back to those days and really isn't relevant any more.
|
# ? May 12, 2022 18:13 |
|
didn't von Neumann dress down the first lazy rear end in a top hat who wasted the computer's time with his "assembler"
|
# ? May 12, 2022 18:22 |
|
Yep:quote:In the 1950s von Neumann was employed as a consultant to IBM to review proposed and ongoing advanced technology projects. One day a week, von Neumann "held court" at 590 Madison Avenue, New York. On one of these occasions in 1954 he was confronted with the Fortran concept; John Backus remembered von Neumann being unimpressed and that he asked, "Why would you want more than machine language?" Frank Beckman, who was also present, recalled that von Neumann dismissed the whole development as "but an application of the idea of Turing's 'short code."' Donald Gilles, one of von Neumann's students at Princeton, and later a faculty member at the University of Illinois, recalled that the graduate students were being "used" to hand-assemble programs into binary for their early machine (probably the IAS machine). He took time out to build an assembler, but when von Neumann found out about it he was very angry, saying (paraphrased), "It is a waste of a valuable scientific computing instrument to use it to do clerical work."
|
# ? May 12, 2022 18:24 |
|
C'mon y'all the linked paper is only 7 pages long. It takes maybe 15 minutes to read, why not read the subject matter before talking about it?
|
# ? May 12, 2022 18:24 |
|
Coding Horrors: waste of a valuable scientific computing instrument to do clerical work
|
# ? May 12, 2022 21:41 |
|
Mellow_ posted:C'mon y'all the linked paper is only 7 pages long. It takes maybe 15 minutes to read, why not read the subject matter before talking about it? I don't have the time, I'm busy assembling binary programs by hand
|
# ? May 12, 2022 22:06 |
|
To be fair, loading and running the assembler was probably slower than having grad students do it by hand. We take for granted the amount of work even just a linter does for us in comparison. The IAS was one of the first machines that could run instructions from memory, but still had manual input. On it, Neumann invented loops, in case it wasn't sounding archaic enough. Try writing fresh hot code directly in python cli sometime, try doing a loop btw, and now also think about doing some kind of cross compilation in there. Kinda unfair to Neumann and definitely a spoiled opinion of him. "Not really relevant anymore" is also hiding how much help we get compared to the earliest programmers and understanding what the absolute rawest baseline of code truly looks like is important. Knocking things down for lacking features that didn't loving exist yet is silly. Indeed, behold these true horrors of coding and despair, and then go back to arguing about braces on newlines or not.
|
# ? May 13, 2022 05:44 |
|
If we accept the axiom that all code is bad and that to write code is a sin, then von Neumann, Turing, Backus, Lovelace, Hopper, etc. are the greatest sinners of them all
|
# ? May 13, 2022 05:57 |
|
At university one course was compiler construction. I wrote a Java compiler in Java down to generating the bitcode. I looked into that abyss for but a week and came away scarred.
|
# ? May 13, 2022 13:38 |
|
everyone can create their own compiler, the tools are democratised https://www.youtube.com/watch?v=VJGVqR8QSRc
|
# ? May 13, 2022 13:45 |
|
The only compiler you need is cat file > /dev/null.
|
# ? May 13, 2022 14:38 |
|
BigPaddy posted:I looked into that abyss for but a week and came away scarred.
|
# ? May 13, 2022 15:34 |
|
|
# ? May 28, 2024 15:55 |
|
Absurd Alhazred posted:The only compiler you need is cat file > /dev/null. 100% success rate on my code.
|
# ? May 13, 2022 15:40 |