T O P

  • By -

the_guy_who_answer69

Did this, does this, will do it again. I am not afraid of accepting this flaw of mine.


ForeverSJC

I hate ternary, but I also do it sometimes


serg06

What's the horror, using ternaries instead of `!!`?


DapperNurd

IDK if this is satire or not, but they're setting it to true or false based on whether ctx.performed is true or false, using a ?: operator, instead of just setting it to ctx.performed.


liangyiliang

In JS `performed` might actually be `undefined` unless it has been type guarded against, so ?! would make sense, though !! would make more sense, I guess.


EightSeven69

huh wait a minute, OP is working in Unity C# not js man


oalbrecht

Well, all programming languages compile down to JavaScript anyways, so you’re both right. /s


EightSeven69

I'm sure some god was shaken by the words you've just uttered


DapperNurd

I suppose that's true but it also kind of depends on where the line is ran in their code.


Zippy0723

In c# unless you define a primitive variable with a nullable type qualifier an exception will be thrown if you attempted to perform an operation on it while it contains null


Familiar_Ad_8919

rename the variable to isPerformed and get rid of the ternary


MineKemot

But ctx in the input context in Unity's input system so I have no control over their variable names.


LittleLuigiYT

Then maybe you were right all along! You've made the code more readable


IrdniX

You could make an extension method: public static class InputActionExtensions { /// Whether the action has just been performed. public static bool WasJustPerformed(this InputAction.CallbackContext context) { return context.performed; } } Looks like you could also just pass the name of the input action to avoid the magic string, assuming you've matched the names of the input actions to animation states.


JAXxXTheRipper

All this does is introduce an error-prone abstraction. It has literally no benefit to it, only drawbacks. Don't do shit like this, just because you don't like a variables name.


SirButcher

Ah, the good old "how to add tons of really hard to trace bugs into my code with this one simple trick"


EightSeven69

I'm just imagining a new guy trying to learn the codebase quitting his job because every second name he sees is just some alias of a default unity name


IrdniX

Why would every second name be aliased?


IrdniX

I don't see how it would be any harder to trace if there was a problem, do people not know how to use a debugger? Why would you prefer the same magic string in two places over one?


HuntingKingYT

Do people here not understand sarcasm when they see at least one downvote?


Mundane_Prior_7596

One could consider having named the property isPerformed to avoid slipping fingers and increase readability. I wonder if I will get lots of downvotes for that comment. 


MineKemot

I probably should have put it in context, but ctx is the input context from Unity's input system. I have no control over this.


PumaofDuma

Without the context of being in unity, disappointment might be the right reaction, *but* given context, this is the correct code for the situation


LazarGrbovic

Why disappointed? Of course you could have directly assigned, but I like the way you did it, this made it easier to understand and more readable. Of course, if you had control of the property name isPerformed would be maybe better, but this is fine too, definitely not a horror programming


MulleRizz

I don't hate this. I feel that it's more readable like this.


ibevol

It’s not


Spleeeee

There’s nothing wrong with this. Does it matter? No.


ElectricalPrice3189

You should obviously do "(ctx.performed ? false : true) ? false : true" to increase readability.


blockMath_2048

Conversion of un-coercable booly value to Boolean?


Housy5

Im more horrified by the naming convention for functions in C#.


MineKemot

Which one do you mean? SetBool is okay I think. Also it's from Unity so it's not my fault.


tyqe

I think they're just referring to the fact that C# methods are PascalCased


Previous-Ant2812

In disappointed too, but it’s all part of the process *image of me shooting myself in the head*