Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs

Dashboard
Notifications
Mark all as read

Activity for klutt‭

Type On... Excerpt Status Date
Edit Post #284175 Post edited:
about 1 month ago
Edit Post #284175 Initial revision about 1 month ago
Question Why is it considered bad practice to use float for representing currency?
This is intended to be a canonical post for this problem which is pretty common. Especially among beginners. I've heard that I should avoid using floating point variables for representing currency. What is the reason for that? Representing 123 dollars and 67 cents as 123.67 seems quite natural...
(more)
about 1 month ago
Edit Post #278850 Post edited:
2 months ago
Edit Post #278846 Post edited:
10 months ago
Edit Post #279232 Post edited:
11 months ago
Edit Post #279232 Initial revision 11 months ago
Answer A: Are there best practices for sticking conditions in WHERE clauses vs the JOIN statement?
@BruceAlderman gave a good answer with different aspects that covers the most. I'm not very good at SQL, so my answer is more general. When I have to choose between two different things that are equivalent in performance and functionality and readability is the only thing that's left. Then I try t...
(more)
11 months ago
Comment Post #277537 Good answer. However, I'd say that external memory is also optional. It's fairly common in embedded systems.
(more)
12 months ago
Edit Post #278895 Post edited:
12 months ago
Comment Post #278907 Yes, I could write it as a oneliner, but don't get stuck on the specific example. It was just made as an example, and actually, I would have written it as a oneliner, but I would do it by just removing the newline and have `while(arr[index]) index++;` as a single line. Actually I'm pretty fond of doi...
(more)
12 months ago
Comment Post #278896 Your first example is also something that would be solved by autoindentation. Plus that if I wrote that , I would put braces around the outer if plus the else. Like `if(x) { if(y) a=k; } else { a=m; }`. And also, autoindentation would solve the problem. It was autocompletion that caused the problem i...
(more)
12 months ago
Comment Post #278895 To me it sounds a bit like "you should not use i and j as counters in a nested for loop, because you CAN use the wrong one by accident" ;)
(more)
12 months ago
Comment Post #278895 While that example is pretty interesting, it's anecdotal evidence. I understand that it's still possible to produce bugs like this. One could also reasonably argue that it could have been avoided if they used `else if` instead of `if` or didn't use `goto`.
(more)
12 months ago
Edit Post #278895 Initial revision 12 months ago
Question Is omitting braces for single statements bad practice?
Consider this code: while(arr[index] != 0) index++; vs while(arr[index] != 0) { index++; } Personally, I prefer the first. The fact that the braces are not needed makes them -- unnecessary. :) To me, it's just clutter that wastes a line. Or 2 if you're on...
(more)
12 months ago
Comment Post #278869 Thank you. Performance does not have the highest priority, but I'll incorporate that.
(more)
12 months ago
Edit Post #278846 Post edited:
12 months ago
Edit Post #278865 Initial revision 12 months ago
Answer A: For scripting what are the pros and cons of command line arguments versus capturing input at the start?
@‭laserkittens‭ and @dmckee has already provided good answers, and I will not copy what's there. Personally, I treat cli arguments as the default choice because of the flexibility it gives to scripting. Only choose user input when it's obvious that it's necessary. A good case where you would li...
(more)
12 months ago
Comment Post #278809 *"If certain arguments are optional"* - This is fairly easy to solve in both approaches. I don't think it counts as a difference between these two concepts.
(more)
12 months ago
Edit Post #278846 Post edited:
12 months ago
Comment Post #278848 @MythicalProgrammer Truth to be told, you discovered a bug, but not the one you think. It's a bug in the specification. I was not looking for number of assignments. I was looking for number of arguments that should be passed and wrongly assumed they were the same. So the fix is to put n back and chan...
(more)
12 months ago
Edit Post #278850 Initial revision 12 months ago
Answer A: Counting number of assignments that a `fscanf` format strings implies
I have found an improvement that is worth posting as an answer to my question. One thing that I was not comfortable with was coming up with test cases and figuring out how many assignments a format string should have by just analyzing it visually. so I had to find a second way to achieve the same ...
(more)
12 months ago
Comment Post #278848 @MythicalProgrammer I just made some CRAZY testing that I need to show you. I was not comfortable with manually figuring out how many arguments a format string should have, but on the other hand, that's also the problem I'm trying to solve. But I did a workaound and made the program create a new .c f...
(more)
12 months ago
Comment Post #278848 Hmmm, I don't think it's that important to test %n, but you definitely have a point in general about such things. I should not only test things that should work. I should also test things that should not work. I added tests including the asterisk: "%*d", "%*23d" and "%23*d" even though I'm not sure i...
(more)
12 months ago
Edit Post #278846 Initial revision 12 months ago
Answer A: Are Linux-related questions on-topic?
Linux questions in general are not really topic here. But Bash is. After all, Bash IS a scripting language as much as Javascript. I have a hard time thinking of a question about Bash that is not on topic here. It would also be on topic to ask about problems installing programming software like ...
(more)
12 months ago
Edit Post #278843 Initial revision 12 months ago
Question Autocompleting usernames in comments does not seem to work
It seems like autocompleting usernames does not work. I wanted to answer a comment and started typing @ followed by the first letter in the username, but no suggestion appeared. I tried pressing tab but nothing happened. Is this a bug? Is there's something wrong with my browser (Firefox)? Or is it...
(more)
12 months ago
Comment Post #278837 @CharlieBrumbaugh‭ Yes it is. Those are pretty common in C where exceptions would be used instead in C++ and Java. Feel free to rewrite it as an answer.
(more)
12 months ago
Edit Post #278837 Post edited:
12 months ago
Edit Post #278837 Initial revision 12 months ago
Question Counting number of assignments that a `fscanf` format strings implies
I'm writing a function that counts the number of assignments for a `fscanf` format string. I studied the documentation in C standard 7.21.6.2 It looks like it works. It passes all test cases I have written and yields no warnings with `-Wall -Wextra -pedantic -std=c17`. While I appreciate design ad...
(more)
12 months ago
Comment Post #277217 You were assuming right. I have edited the question, so you might want to remove that part.
(more)
about 1 year ago
Comment Post #277375 The general answer to "Will X make Y faster?" is "Try it and measure"
(more)
about 1 year ago
Comment Post #277331 @chris-barry You're correct. That was just a typo that i missed several times. Question is corrected with a `&`. Sorry for any inconvenience.
(more)
about 1 year ago
Edit Post #277215 Post edited:
about 1 year ago
Edit Post #277215 Post edited:
about 1 year ago
Comment Post #277331 Are you saying that my code would not compile because it's not in a function? I just did not include that code, but the question is changed now.
(more)
about 1 year ago
Edit Post #277266 Post edited:
about 1 year ago
Edit Post #277266 Post edited:
about 1 year ago
Edit Post #277266 Initial revision about 1 year ago
Answer A: Should I cast to (void) when I do not use the return value
This is a bit opinionated, but personally, I would not do it. It would just clutter the code and could hide sources of bugs. But it depends a lot on what function it is. It's also hard to give a very general answer to this. In many cases, the proper answer is "No, you should instead use the retur...
(more)
about 1 year ago
Comment Post #277215 @kami Nope, that line is exactly as it should be.
(more)
about 1 year ago
Comment Post #277215 @olinlathrop Except that `arr[10]` is legal to point at, but not `arr[11]` ;) I mostly posted this question to get this site going.
(more)
about 1 year ago
Edit Post #277215 Initial revision about 1 year ago
Question Is it undefined behaviour to just make a pointer point outside boundaries of an array without dereferencing it?
I have heard that it is undefined behaviour to make a pointer point outside boundaries of an array even without dereferencing it. Can that really be true? Consider this code: int main(void) { char arr[10]; char ptr = &arr[-1]; char c = ptr; } The line `...
(more)
about 1 year ago