|
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 |
|
|
# ? May 4, 2024 09:55 |
|
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 |
|
code:
|
# ? Apr 26, 2024 04:07 |
|
Request to the world: I'm going to do a presentation on magic in software development, using "magic" in the sense of "a system which you use but do not (fully) understand", and focusing on the occasions where that magic breaks down and causes problems for you, the developer using it. I need some examples, so- Please tell me about a time when a tool didn't work the way you expected it, and caused problems for you. To give an example from my recent past, at a project I was working on a couple years ago, I tried to add a component to a module, but nothing appeared to change when I built the project. I brought the issue to my manager, who told me that the build system read from a configuration file to determine what components each module could use as a dependency, and I needed to add the component there as well as importing it in the module. I had assumed import Component from file; would be enough for the build tool to add it as a dependency, I was mistaken, and that caused a problem for me. The thesis of the presentation at time of posting is mostly this koan, plus leaky abstractions and possibly this XKCD. "Magic abstractions are very useful, but they will trip you up if you don't know about them and a little about what they do under the hood".
|
# ? Apr 29, 2024 00:22 |
|
I've had to learn Spring recently and a lot of it boils down to "oh just add the @Magic annotation that you have to just know about." I was having compilation issues when I realized that the framework is so opinionated that it matters what you name things. We're not even building anything complicated, just dumb REST apps.
|
# ? Apr 29, 2024 01:06 |
|
Floating point arithmetic is magic
|
# ? Apr 29, 2024 01:16 |
|
Clanpot Shake posted:I've had to learn Spring recently and a lot of it boils down to "oh just add the @Magic annotation that you have to just know about." I was having compilation issues when I realized that the framework is so opinionated that it matters what you name things.
|
# ? Apr 29, 2024 01:26 |
|
QuarkJets posted:Floating point arithmetic is magic And most relevantly here, the fact that 0.1 + 0.2 != 0.3 is the sort of breaking abstraction I can use in my presentation.
|
# ? Apr 29, 2024 01:35 |
|
Git detached head. After a while I’ve gotten used to it. But I’ve gone from thinking of git as “version control” to “version control with a database with four types of objects each with specific properties.”
|
# ? Apr 29, 2024 02:27 |
|
You can get weird behavior even with machine integers. The function that sends x to -x has two fixed points and that means you can't always assume that abs(x) > 0.
|
# ? Apr 29, 2024 02:27 |
|
darthbob88 posted:Do you have any examples of names that Spring finds objectionable? Everything I can find on a quick search just says "We recommend standard Java naming conventions". One of the ways to write your database access layer in Spring JPA is to declare an interface with methods like "List<User> findByEmailAddress(String emailAddress);". The method name is used to figure out what database field you're wanting to look up (since there could be many possible String fields in your database). This works well enough if your queries are very simple and you know that that's what it's doing under the hood - which is unfortunate, because it might just be good enough to prevent you from switching to something that isn't completely insane.
|
# ? Apr 29, 2024 02:28 |
|
ultrafilter posted:You can get weird behavior even with machine integers. The function that sends x to -x has two fixed points and that means you can't always assume that abs(x) > 0. Isn't there also some division by something other than zero that traps (as SIGFPE in Linux for bonus silly abstraction points)... sadly I am blanking on what it is by did run into it in sort of real life long time ago (grad school project)? Edit: oh, I think it's basically the same thing aa you said. Found what I was thinking of in the GCC manual: quote:Integer division overflows in one specific case: dividing the smallest negative value for the data type (see Maximum and Minimum Values) by -1. That’s because the correct result, which is the corresponding positive number, does not fit (see Integer Overflow) in the same number of bits. OddObserver fucked around with this message at 03:41 on Apr 29, 2024 |
# ? Apr 29, 2024 02:48 |
|
Literally everything in git.
|
# ? Apr 29, 2024 02:52 |
|
Comment rot would be relevant here, there have been plenty of times that I've seen an elaborate set of lines commenting on how some tricky bit of code works and been like "uhh this doesn't work that way at all", then checked the git blame and found out that the comment was written 17 revisions ago
|
# ? Apr 29, 2024 03:38 |
|
Jabor posted:One of the ways to write your database access layer in Spring JPA is to declare an interface with methods like "List<User> findByEmailAddress(String emailAddress);". The method name is used to figure out what database field you're wanting to look up (since there could be many possible String fields in your database). "Spring JPA allows you to skip writing the actual database access, because it will automagically generate the code for you based on the method names you use in the interface..." "...so you have to make sure you name your methods the way Spring JPA likes, and heaven help you if you have any queries more complicated than 'getThingByProperty'."
|
# ? Apr 29, 2024 04:07 |
|
|
# ? May 4, 2024 09:55 |
|
Still beats writing all the lovely little queries by hand, imo Either way, you really just have to get it right once and then you can stop thinking about it.
|
# ? Apr 29, 2024 05:48 |