|
dc3k posted:everything in linux is a file Removed the spoilers, it's not a surprise to anyone at this point
|
# ? Apr 4, 2024 08:34 |
|
|
# ? Apr 26, 2024 09:41 |
|
Apologies for not contributing earlier.code:
|
# ? Apr 4, 2024 14:58 |
|
https://twitter.com/the_moisrex/status/1776661987855941776
|
# ? Apr 6, 2024 23:34 |
|
GABA ghoul posted:I think there is a very clever solution for this that could save a lot of work I want to know if I can get this through code review, don't tempt me Satan.
|
# ? Apr 8, 2024 16:02 |
|
what yall really need is some solid mathematical background for your IsEvensPython code:
|
# ? Apr 8, 2024 21:47 |
|
RPATDO_LAMD posted:what yall really need is some solid mathematical background for your IsEvens My eyes just rolled into the back of my head
|
# ? Apr 9, 2024 07:38 |
|
I don't think I hate this that much? it's icky, but it's also plain what it does and how it works. (I do hate that resume() returns 0 on both the first iteration and after it's finished)
|
# ? Apr 9, 2024 20:43 |
|
In my head canon Duff's device was named after the Simpsons beer
|
# ? Apr 9, 2024 22:06 |
|
Foxfire_ posted:I don't think I hate this that much? it's icky, but it's also plain what it does and how it works. The post of a broken man
|
# ? Apr 10, 2024 02:40 |
|
Foxfire_ posted:I don't think I hate this that much? it's icky, but it's also plain what it does and how it works. One of the reasons I like the switch statement is how it breaks down into assembly pretty easily... e.g. code:
code:
Using that construct in the screenshot is going to result in assembly language that looks like this: code:
|
# ? Apr 10, 2024 16:40 |
|
I don't think there's anything that gross about it that's not also gross about any switch statement that uses fallthrough logic. The fact that it slices up the for-loop construct is kind of viscerally offputting but starting partway into the for loop isn't really conceptually any different than a do-while loop. It's what I would mildly classify as spaghetti code and not something I would ever do in general, but it's pretty clear what it does and how it works.
|
# ? Apr 10, 2024 17:47 |
|
The problem with it is that having a case statement in the middle of a loop is the kind of thing that might plausibly be undefined behavior or a compiler-specific extension. It’s obvious what the code intends to do, but it’s not a common idiom, so unless you’re familiar with the trick, it’s not obvious whether it will actually do that reliably, even if you run it and it seems to work on your machine. That’s why it’s bad code.
|
# ? Apr 10, 2024 19:22 |
|
Soricidus posted:The problem with it is that having a case statement in the middle of a loop is the kind of thing that might plausibly be undefined behavior or a compiler-specific extension. It’s obvious what the code intends to do, but it’s not a common idiom, so unless you’re familiar with the trick, it’s not obvious whether it will actually do that reliably, even if you run it and it seems to work on your machine. what. duff's device is a little silly, but it's not against the spec
|
# ? Apr 10, 2024 19:47 |
|
Soricidus posted:The problem with it is that having a case statement in the middle of a loop is the kind of thing that might plausibly be undefined behavior or a compiler-specific extension. It’s obvious what the code intends to do, but it’s not a common idiom, so unless you’re familiar with the trick, it’s not obvious whether it will actually do that reliably, even if you run it and it seems to work on your machine. I was going to say that it should be ok because no initialization of variables was being skipped, but actually it potentially is if I understand correctly. The initialization of i to 0 occurs in the for loop header and it ought to run because the state is initialized to "at start" - but having said that, all the properties are public, so the user could construct one of these, then change the state and then call resume() to get it to run without i being initialized? But you could fix that by just initializing i to 0 along with all the other members so I don't know why the author didn't just do that. Even if the enum member was (say) made private so that you couldn't do that, it seems like it's asking a lot of the compiler to prove that i isn't accessed before it's initialized? You would think the compiler would warn about it. I guess in C++ both the "switch" and "for loop" language features translate pretty directly to labels and gotos, and it's clear how you convert that code into labels and gotos and it shouldn't cause any problems, so other than the uninitialized variable thing, I don't know how plausible it really is that it would be undefined. It's a while since I touched C++.
|
# ? Apr 10, 2024 20:14 |
|
leper khan posted:what. This is not really Duff's device though; it’s an implementation of a state machine or coroutine. In Duff's device the loop actually has a function, but here it would not really be necessary if the author had properly initialised "i" in the constructor. efb
|
# ? Apr 10, 2024 20:17 |
|
Zopotantor posted:This is not really Duff's device though; it’s an implementation of a state machine or coroutine. In Duff's device the loop actually has a function, but here it would not really be necessary if the author had properly initialised "i" in the constructor. case statements in a loop have no issues
|
# ? Apr 10, 2024 20:55 |
|
switch in C is unstructured control flow. The nested statement is just an ordinary statement block, and the associated cases can be recursively anywhere inside that block except (of course) within another switch; the switch jumps to the case, entering any scopes along the way and bypassing any earlier code in that scope. (In C++, bypassing initialized declarations is illegal, but otherwise it’s the same.) The only thing special about the switch statement block is that it’s the only statement block in the language that’s never possible to enter from the top. for is structured control flow; there are no branches into arbitrary scopes. You just keep entering the loop body from the top as long as the condition expression evaluates to true. You can desugar a for loop into labels and goto, but at some level that’s true of any local non-conditional control flow. You could desugar if statements into a more primitive “if … goto” instead of using nested blocks, and that would indeed look a lot more like assembly language; that doesn’t mean if isn’t a structured feature, it just means it has definable semantics. rjmccall fucked around with this message at 21:02 on Apr 10, 2024 |
# ? Apr 10, 2024 20:59 |
|
Hammerite posted:I was going to say that it should be ok because no initialization of variables was being skipped, but actually it potentially is if I understand correctly. "this is bad because if you gently caress with internal object state you can put it in an invalid state" is a very "you're holding it wrong" kind of problem to have the real problem is that it's using the switch as a fancy goto which is just fucky and unintuitive to read. you could easily refactor this to use separate start(), loop(), done() functions instead of jumping into the middle of a block of shared code.
|
# ? Apr 10, 2024 21:40 |
|
leper khan posted:what. I didn’t say it was against the spec. I know it’s not against the spec. I said it was the kind of thing that looks like it might be against the spec, and is bad code for that reason. leper khan posted:case statements in a loop have no issues Coding Horrors: case statements in a loop have no issues
|
# ? Apr 10, 2024 22:21 |
|
RPATDO_LAMD posted:"this is bad because if you gently caress with internal object state you can put it in an invalid state" is a very "you're holding it wrong" kind of problem to have It's not internal object state though, it's public. The language gives you the tools to make it internal, but the author of this code neglected to do that. It's not like Python where everything is based on conventions and promises. If something is left public in C++ then the user is entitled to suppose that that means you intended for them to be able to modify it.
|
# ? Apr 10, 2024 22:31 |
|
Bruegels Fuckbooks posted:So really gross for no good reason. well yeah but you chose x86 asm yourself
|
# ? Apr 10, 2024 22:34 |
|
Soricidus posted:it was the kind of thing that looks like it might be against the spec, and is bad code for that reason. This is me writing any line of C++. "But does this really work the way I think it does???"
|
# ? Apr 10, 2024 22:56 |
|
pokeyman posted:This is me writing any line of C++. "But does this really work the way I think it does???"
|
# ? Apr 10, 2024 23:14 |
|
Our org uses SAS programs for regular scheduled reporting, and our data warehouse is a Teradata SQL environment that we can connect to using SAS EG. Generally speaking our programs are set up to to a whole bunch of data manipulation in Teradata, then bring refined datasets into the SAS grid in order to perform a few final transformations and then create the report outputs. However, occasionally I will get a 'can you see why this program is running poorly' maintenance request and well... So someone creates a SAS view via a connection to Teradata. Something like this: code:
code:
|
# ? Apr 10, 2024 23:35 |
|
I wrote a for-case loop the other day for a project. At first I felt pretty bad about it but it's way better than these case-for shenanigans.
|
# ? Apr 11, 2024 00:56 |
|
Microsoft released the code for DOS 4.0 : https://github.com/microsoft/MS-DOS/ As expected, coding horrors : code:
code:
|
# ? Apr 26, 2024 02:04 |
|
|
# ? Apr 26, 2024 09:41 |
|
code:
|
# ? Apr 26, 2024 04:07 |