That kind of architecture makes all development and design insanely painful though. Rule of thumb: If you are passing boolean parameters, you are doing something wrong.
Generally speaking, Boolean arguments are a code smell that indicates a method is doing too much.
Stuff like widget.enabled(true) is fine. But when you have something like update_fiscal_state(money, actor, true) I start to get real nervous. What does "true" mean here?
More subtly, functions with Boolean flags need to have a combinatorial number of tests to ensure all the possible combinations work, even if some of those combinations make no sense and should "never happen".
Maybe you need two (or more) methods. Maybe you need to refactor out an interface and a couple of classes to support the expected behaviors. But the more Boolean arguments a method accumulates, the more likely it is to need a refactor.
Just to confirm, you're talking about passing hardcoded booleans that have no name to provide context as opposed to in general, right ????
update_fiscal_state(money, actor, true)
If it was something like below, then I presume you wouldn't consider it a code smell? I can see why your example may be bad but how below would be more appropriate (because now you know what the boolean is for / what true means)
Either inject a FiscalUpdater class which can be mocked / configured to/not to commit, or have two methods, one of which commits and one which doesn't.
Again this is going to depend on the context of the surrounding code, but I'd prefer to see either of these.
class BoaFiscalUpdater: FiscalUpdater {
@Override
void update_fiscal_state(money, actor){
//send update to BOA and commit
...
}
}
class MockFiscalUpdater FiscalUpdater {
@Override
void update_fiscal_state(money, actor){
// store call, but don't send it anywhere
...
}
}
The function you’re passing them into will necessarily behave in two different ways depending on the value of the bool.
Instead of having two functions that might individually be reusable / composable, you have one big one that handles both cases. It also violates the single responsibility principle + open/closed principle - your code for one case is tangled with the code for the other, and if you need to make a change to only one, you might inadvertently break the other while you’re there. A working method that is never modified can’t break.
So if a function can behave in two different ways, it should (most of the time) instead be two functions. For example:
There was a discussion recently about this over on the java sub. My takeaway was that the renaming the param for the code in the method should not break external code, which made sense to me.
When your method or constructor already has like 5 parameters and you go adding a sixth, it’s time to start considering other Java options. Builders, overloading, anything other than this.
Adding to my mental list of things I like about C# and really miss in my current Java gig: default arguments and named arguments.
Could also be a security thing. Any mutable state is a vector for attack, and objects are often just a bunch of mutable state. Could also just be an old C dev, yes.
It’s not just a swift thing. It’s also possible on C# and C++. Not sure about Java but since Java is kind of shitty, I wouldn’t be surprised if it isn’t possible.
The only thing Swift has over other languages that you as the API developer can force other people to use the labels. That makes the function calls almost a sentence that you can read. It's really nice and a feature I miss in many other languages.
Oh I know it's not just a Swift thing, but in most other languages with a similar feature it's more of an opt-in thing or just used for params with default values. In Swift it's the default, used everywhere unless you explicitly mark a parameter as having no label.
this from the developers that said maintaining a color toggle option is not possible because it would create an unimaginable undue burden upon development by more than doubling the codebase 😂 not at all surprised by this. something has been rotten with signal's development methodology for a long time, can't say i trust it much anymore
I mean, the code isn’t great, sure, but the code works, and making code work is a higher priority than making code correct. If the product functions and is performant, the code not being pretty doesn’t matter much, does it?
Java. Yes Intellij and Android Studio show the names of the arguments. Still bad code. This is a prime example of where a builder is helpful. These objects are complicated to build, so the build logic should be encapsulated.
279
u/lets_eat_bees Apr 28 '23 edited Apr 28 '23
I can totally see how easy this is to review. "Hey, you have an error there - that 17-th false is supposed to be true."
104
u/Neckbeard_Prime Apr 28 '23
Builder pattern? I hardly know 'er pattern, haw haw haw
59
u/robin_888 Apr 28 '23
The worst offender is the bottom right call, where there are two parameters on one line for some random reason.
56
u/RichCorinthian Apr 28 '23
When your method or constructor already has like 5 parameters and you go adding a sixth, it’s time to start considering other Java options. Builders, overloading, anything other than this.
Adding to my mental list of things I like about C# and really miss in my current Java gig: default arguments and named arguments.
30
u/iNeedOneMoreAquarium Apr 29 '23
Signal is so secure that even its source code is highly obfuscated.
107
u/stao123 Apr 28 '23
That looks like a c Developer trying to write Java-Code (and failing miserably). He doesnt know objects?
12
u/kuurtjes Apr 28 '23
This sometimes happens when IDE's have function parameter hints enabled.
Here's an example: https://i.imgur.com/Ejrcshg.png
The parameter names when calling the function do not exist in the actual code.
13
u/brianddk Apr 29 '23
That all looks machine generated to me.
13
u/MurdoMaclachlan public boolean isInt(int i) { return true; } Apr 29 '23
Image Transcription: Code
[Five images of code. This transcription will list them left-to-right, then down. The first reads as follows:]
[The second image reads as follows:]
[The third image reads as follows:]
[The fourth image reads as follows:]
[The fifth image reads as follows:]
I'm a human volunteer content transcriber and you could be too! If you'd like more information on what we do and why we do it, click here!
8
u/experbia Apr 29 '23
this from the developers that said maintaining a color toggle option is not possible because it would create an unimaginable undue burden upon development by more than doubling the codebase 😂 not at all surprised by this. something has been rotten with signal's development methodology for a long time, can't say i trust it much anymore
4
u/greyhairedcoder Apr 29 '23
I interviewed at signal, was not impressed. Founder was a dick
4
u/agent007bond Apr 28 '23
Meanwhile in JavaScript: freaking objects, man! Godsent miracle!
1
u/Marcelektro Apr 29 '23
What’s that design? Whyyy >_<
1
u/ja_maz Apr 28 '23
Been there
-3
u/ATE47 Apr 28 '23
Knowing how bad signal is compared to the others, it wasn’t unexpected imo
0
u/[deleted] Apr 28 '23
[deleted] — view deleted comment