Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Activity for klutt
Type | On... | Excerpt | Status | Date |
---|---|---|---|---|
Question | — |
Is there any rationale for the lack of local constants in PHP? The last few years, PHP has basically exploded with lots of modern language constructs that makes the life easier. But local constants are still missing, and I find that very strange. I have found many questions online that asks for this, so it is obviously something many programmers want. Just fo... (more) |
— | 3 months ago |
Answer | — |
A: How to avoid "exception is never thrown" when commenting out a line while debugging While writing the question I actually came up with something that seems to work fairly well, and it's very simple. Just add `if(false)` in front of the statement. (more) |
— | about 2 years ago |
Question | — |
How to avoid "exception is never thrown" when commenting out a line while debugging I have a code block like this: try { ... x.foo(); // This is the line that forces us to have the try block ... } catch (ArrayIndexOutOfBoundsException e) { logger.error(e.getMessage(), e); } `x.foo()` is the line that is potentially throwing the... (more) |
— | about 2 years ago |
Answer | — |
A: Mocking methods with arguments I managed to do it with lambda. Something like this: Set ulist = new LinkedHashSet<>(); @Test void test() { doAnswer(i -> { U arg = i.getArgument(0); if(ulist.contains(arg)) { return 0; } ulist.add(ar... (more) |
— | about 2 years ago |
Question | — |
Mocking methods with arguments Let's say I have this class I want to mock class A { public void add(T arg) { B b = A.getB(); U val = somefunc(arg); V ret = b.add(val); } } I have a spy on A and a mock on B, but when A::foo calls B::bar, I want it to be mocked.... (more) |
— | about 2 years ago |
Question | — |
How to create an object, call one of it's methods and pass it as an argument as a oneliner? Assume I have this class Foo class Foo { private int x; void setX(int x) { this.x = x; } } And I have a Junit test like this: Bar bar; @BeforeEach void setup() { bar = new Bar(); } @Test voi... (more) |
— | about 2 years ago |
Question | — |
How to unittest method that involves contacting remote servers? Let's say I have this class: class myService { private boolean foo(T arg) { return arg == 42; } public Response bar(U arg) { if(foo(U.field)) { return Response.status(Response.Status.BADREQUEST).build(); } // Code th... (more) |
— | about 2 years ago |
Question | — |
How to check if a ldap username is valid without contacting the active directory via ldap? I have some code connecting to an active directory via ldap. Something like this: public Response add(User user) { try { LDAPConnectionPool ldapPool = ldapConnectionPool.getPool(); // Code LDAPResult res = ldapPool.add(user); } catch (... (more) |
— | about 2 years ago |
Question | — |
When does it not work to dereference the pointer for sizeof during malloc? Background This is kind of a subquestion to How to properly use malloc? When allocating, there are basically two common ways of using the `sizeof` operator: int p; p = malloc(n sizeof p); // Method 1: Dereference the pointer p = malloc(n sizeof(int)); // Method 2: Explicitl... (more) |
— | about 2 years ago |
Answer | — |
A: How to properly use malloc? TL;DR You should use int p = malloc(n sizeof p); for two reasons 1. The cast `(int)` is not necessary, which means it's clutter. 2. Using `sizeof p` instead of `sizeof(int)` removes code duplication. But remember to check if allocation succeeded before using the memory. It's don... (more) |
— | about 2 years ago |
Question | — |
How to properly use malloc? I have seen this construct quite a lot: int p = (int) malloc(n sizeof(int)); Is this how it should be? What is the proper way to use `malloc`? I have also seen this: int p = malloc(n sizeof p); Which one is preferable? (more) |
— | about 2 years ago |
Answer | — |
A: Are there references in C? This question most often comes up in relation to C++. That language has something that is called reference in the standard. They work like pointers, with a few differences. 1. They have to be initialized, because (2) 2. They cannot be reassigned. They will always point to the same object. 3. Th... (more) |
— | about 2 years ago |
Question | — |
Are static pointers implicitly initialized to NULL? Consider this code: ``` #include int main(void) { static void ptr; if(ptr == NULL) puts("It's NULL!"); } ``` I wonder if this is guaranteed to print "It's NULL!" I know that 1) Initializing or assigning a pointer to `0` is equivalent to initializing or assigning it to `NU... (more) |
— | about 2 years ago |
Question | — |
Suggestions for improving the UI regarding comments See this picture Expanded comment thread How do you answer in that thread? Hmm, there are two buttons. One says "show more". I click on that and the thread collapse. Is that "more"? Collapsed thread Ok, so I click on the thread again to get back to the first picture. There's one more butt... (more) |
— | about 2 years ago |
Question | — |
How to prevent token from being refreshed I have an Angular application. The frontend has a mechanism that periodically fetches some information like this: ```` ngOnInit(): void { setInterval( () => { this.http.get(... ).subscribe( (data) => { this.data: any = data; } }, ... (more) |
— | about 2 years ago |
Answer | — |
A: A cleanup of "What type of questions can I ask here?" If we compare to SO (and we do) there's one thing I really don't like there. And that is that so many questions get closed for being too opinionated. Granted, many of them is quite naively asked. Like simply "What is best of A and B?" But this can often easily be rephrased in a way that allows an... (more) |
— | about 2 years ago |
Answer | — |
A: How can we grow this community? Increase exposure One way of increasing our exposure is to use Codidact as a source when answering on other forums. As long as we are treating Codidact as any other source, there is absolutely nothing wrong with that. I did that with this answer on SO Improve technical stuff Sure, there are ... (more) |
— | about 2 years ago |
Answer | — |
A: What is a minimal, reproducible example? TL;DR A MRE (minimal reproducible example) is simply the minimal code and information needed for someone who is reading your question to reproduce the problem you are having. It needs to be enough code to actually reproduce the problem. Don't omit code based on a guess where the problem is. And... (more) |
— | about 2 years ago |
Question | — |
What is a minimal, reproducible example? Sometimes when I ask questions here, I get told that I should include a minimal, reproducible example. What is that? (more) |
— | about 2 years 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) |
— | over 2 years 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) |
— | over 3 years 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) |
— | over 3 years 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) |
— | over 3 years 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) |
— | over 3 years 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) |
— | over 3 years 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) |
— | over 3 years 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) |
— | over 3 years 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) |
— | over 3 years 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) |
— | over 3 years ago |