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
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »

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
Edit Post #290696 Initial revision 2 months ago
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)
2 months ago
Comment Post #289480 That's a really good argument!
(more)
7 months ago
Comment Post #286504 @#56802 I also have to admit that the joke in the end was priceless :D
(more)
over 1 year ago
Comment Post #286504 I don't see where this comes from. Regardless of the any ones opinions of NobleZarkons complaints, their experience is real, and if one person complains about this, it is very likely that there are many others who feel the same way. And sure, since it's people who put in their free time to do this, t...
(more)
almost 2 years ago
Comment Post #286189 Yep, I agree that it could be hard to suggest alternatives. However, as it is now your post gives the impression that finding a replacement is trivial. I think you should at least mention that this can be somewhat tricky. Especially in a portable way. And another thing. You're referring to a quest...
(more)
about 2 years ago
Comment Post #286189 I think this post would benefit a great deal with more suggestions of alternative. After all, you're saying that the most common print function - `printf` - should not be used. Many people don't even know about anything else.
(more)
about 2 years ago
Comment Post #286191 No I did not say that, and the comparison is ridiculous.
(more)
about 2 years ago
Comment Post #286191 In the case that it would mean a catastrophe if the programmer forgets to do the null check in the right place, it makes total sense to have a check in the wrong place.
(more)
about 2 years ago
Comment Post #286191 I find this very dogmatic. "Never" is a very strong word. As someone said: "Blindly following best practices is not best practice." However, I can agree that it seems a bit point(haha)less for two reasons. 1. There is rarely a good way to recover is a NULL pointer is passed. 2. NULL is basica...
(more)
about 2 years ago
Comment Post #286003 @#53185 We ended up using something anyway, and I got pretty good argument from my boss about it. Firstly, our requirements are stricter than the ldap server. We don't care if they match to 100%. The only thing we care about is that those that the check lets through to the server are 100% guaranteed ...
(more)
about 2 years ago
Comment Post #286054 I think the first half of your answer would be better if it was a comment thread on the answer, because that's what it is. :) Fixed the type issue. When it comes to using Set, that fell into the category "I know, but it's not important enough to care about". Did that change too. I was fiddling ...
(more)
about 2 years ago
Edit Post #286039 Post edited:
about 2 years ago
Edit Post #286039 Post edited:
about 2 years ago
Comment Post #286047 I could have sworn I got it, but if you say so. Feel free to edit.
(more)
about 2 years ago
Edit Post #286048 Initial revision about 2 years 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
Edit Post #286047 Initial revision 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
Edit Post #286039 Initial revision 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
Edit Post #286031 Post edited:
about 2 years ago
Comment Post #286031 I really appreciate the help, but now I realized that B is a final class :D I'll have a look. Thanks.
(more)
about 2 years ago
Comment Post #286031 When I saw what you wrote I thought "Omg, that's so obvious", but unfortunately, B does not have a default constructor :( (And no, it cannot be added)
(more)
about 2 years ago
Comment Post #286031 In the real code, A::add calls B::add. I want to intercept this and make A::add call BMock::add instead. And yes, A::add is being called multiple times. Well, actually it's kind of that I call A::import, which in turn will call A::add multiple times. So there is a bit of nesting here.
(more)
about 2 years ago
Edit Post #286031 Initial revision 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
Comment Post #286013 Using protected made a lot of sense, and that's what I ended up doing. Also mocked a lot.
(more)
about 2 years ago
Edit Post #286017 Post edited:
about 2 years ago
Comment Post #286017 My first reaction to this was what you wrote in the second post. It's just that kind of clever code I'm trying to avoid. It's often the case that I think code is too airy. Sometimes it makes sense with dense code. Because having to scroll back and forth when reading code can be extremely distr...
(more)
about 2 years ago
Comment Post #286017 That makes good sense. I think you should write an answer with it.
(more)
about 2 years ago
Comment Post #286017 @#53078 Thanks for your input. And yes, I agree to 100% that less lines isn't necessarily better. But there are cases where it is. On the contrary, I'd say that more abstractions, less duplication and big dose of "best practice" isn't necessarily better either. Oneliners isn't the main goal. Well...
(more)
about 2 years ago
Edit Post #286017 Post edited:
about 2 years ago
Comment Post #286019 Look at this for instance: Foo a; a = new Foo(); a.setX(42); assertEquals(13, bar.fun(foo).getY()); a = new Foo(); a.setX(43); assertEquals(10, bar.fun(foo).getY()); a = new Foo(); a.setX(44); assertEquals(16, bar.fun(foo).getY()); a = new Foo(); a.setX(47); assertEqua...
(more)
about 2 years ago
Comment Post #286019 I completely understand your skepticism, and don't get me wrong. In many (most) cases what you're saying here is the correct approach. I'm just investigating options for when I want another option. I do make changes to the code for testing. But almost never something that would not also make sens...
(more)
about 2 years ago
Comment Post #286018 I honestly didn't even think about this simple solution. I'll use it. Thanks.
(more)
about 2 years ago
Comment Post #286017 @#53078 Yes, I know, but as I mentioned, I don't want to modify neither `Foo` nor `Bar`.
(more)
about 2 years ago
Edit Post #286017 Post edited:
about 2 years ago
Edit Post #286017 Initial revision 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
Comment Post #286005 @#53305 Yes, I actually saw that. I agree with what they say in the accepted answer. That private methods should be considered implementation details in general. But reality does not follow the books unfortunately. In my case, `foo` has a very simple, yet very distinct task. It's job is to validat...
(more)
about 2 years ago
Comment Post #286005 @#53305 Yes, you're completely right. I'm looking for a mocking solution now. However, I would still like to be able to test this separately. Mainly because some tests will go very quick to run, and can be executed as part of the build process. But other tests will be to much of a slowdown.
(more)
about 2 years ago
Edit Post #286003 Post edited:
about 2 years ago
Comment Post #286003 @#53305 You're probably right there. I'm using the protocol Ldap to connect to an active directory. When I google it, I'm not the first one to mix this up. :D
(more)
about 2 years ago
Edit Post #286005 Post edited:
about 2 years ago
Edit Post #286005 Initial revision 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
Edit Post #286003 Post edited:
about 2 years ago
Edit Post #286003 Initial revision 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