Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Absurd Alhazred
Mar 27, 2010

by Athanatos
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?

Adbot
ADBOT LOVES YOU

Thranguy
Apr 21, 2010


Deceitful and black-hearted, perhaps we are. But we would never go against the Code. Well, perhaps for good reasons. But mostly never.

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.

Ranzear
Jul 25, 2013

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

Aurium
Oct 10, 2010


I decided to implement this in a sort visualizer.

https://www.sortvisualizer.com/customsort/

JavaScript code:

async function selectionSort(elements) {

  for (let i = 0; i < elements.length; i++) {
    for (let j = 0; j < elements.length; j++) {
      if (getValue(i) < getValue(j)) {
        await swap(i, j);
      }
    }
  }
}

And left it named selectionSort so you didn't have to change the entry point.

ExcessBLarg!
Sep 1, 2001
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.

Absurd Alhazred
Mar 27, 2010

by Athanatos

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! :mad:

Ranzear
Jul 25, 2013

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.

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe
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.

QuarkJets
Sep 8, 2008
Probation
Can't post for 24 minutes!

New Yorp New Yorp posted:

you can write good code in any language.

This postulate is disputed, as it has never been demonstrated

Ranzear
Jul 25, 2013

Good code and correct code are exclusively different things.

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...

Ranzear posted:

Good code and correct code are exclusively different things.

I don't think that's what the objection is about.

Ranzear
Jul 25, 2013

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.

more falafel please
Feb 26, 2005

forums poster

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.

QuarkJets
Sep 8, 2008
Probation
Can't post for 24 minutes!

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

Athas
Aug 6, 2007

fuck that joker

D34THROW posted:

I want to see what's considered "good code" in brainfuck :allears:

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.

ExcessBLarg!
Sep 1, 2001
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.

Tei
Feb 19, 2011

Ranzear posted:

Good code and correct code are exclusively different things.

confused face (!)

Absurd Alhazred
Mar 27, 2010

by Athanatos

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.

Ranzear
Jul 25, 2013

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

Ola
Jul 19, 2004

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.

Tei
Feb 19, 2011

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.

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.

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

D34THROW
Jan 29, 2012

RETAIL RETAIL LISTEN TO ME BITCH ABOUT RETAIL
:rant:
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? :iiam:

Volte
Oct 4, 2004

woosh woosh
The only good code is deleted code

LOOK I AM A TURTLE
May 22, 2003

"I'm actually a tortoise."
Grimey Drawer
You miss 100% of the bugs you don't write.

QuarkJets
Sep 8, 2008
Probation
Can't post for 24 minutes!

Volte posted:

The only good code is deleted code

Vigil continues to be the best software project

Ranzear
Jul 25, 2013

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.

Tei
Feb 19, 2011

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

ultrafilter
Aug 23, 2007

It's okay if you have any questions.


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.

Doc Hawkins
Jun 15, 2010

Dashing? But I'm not even moving!


didn't von Neumann dress down the first lazy rear end in a top hat who wasted the computer's time with his "assembler"

ultrafilter
Aug 23, 2007

It's okay if you have any questions.


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."

Mellow_
Sep 13, 2010

:frog:
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?

Ola
Jul 19, 2004

Coding Horrors: waste of a valuable scientific computing instrument to do clerical work

QuarkJets
Sep 8, 2008
Probation
Can't post for 24 minutes!

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

Ranzear
Jul 25, 2013

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.

csammis
Aug 26, 2003

Mental Institution
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

BigPaddy
Jun 30, 2008

That night we performed the rite and opened the gate.
Halfway through, I went to fix us both a coke float.
By the time I got back, he'd gone insane.
Plus, he'd left the gate open and there was evil everywhere.


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.

Tei
Feb 19, 2011

everyone can create their own compiler, the tools are democratised

https://www.youtube.com/watch?v=VJGVqR8QSRc

Absurd Alhazred
Mar 27, 2010

by Athanatos
The only compiler you need is cat file > /dev/null.

ExcessBLarg!
Sep 1, 2001

BigPaddy posted:

I looked into that abyss for but a week and came away scarred.
Yeah, Yacc is pretty weird.

Adbot
ADBOT LOVES YOU

Macichne Leainig
Jul 26, 2012

by VG

Absurd Alhazred posted:

The only compiler you need is cat file > /dev/null.

100% success rate on my code. :hmmyes:

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply