#If statement within if statement

1 messages · Page 1 of 1 (latest)

copper pulsar
#

Is using this for readablity bad for optimization?

gray cedar
#

depends how you use it but in most cases no

unique bronze
#

...it depends on how much, really

gray cedar
#

if you gonna stack 10 if's in each other its probably bad

daring crest
#

When it comes to performance, I think you need to benchmark. Always.
https://www.youtube.com/watch?v=EWmufbVF2A4

Become a Patreon and get source code access: https://www.patreon.com/nickchapsas
Check out my courses: https://nickchapsas.com

Hello everybody I'm Nick and in this .NET tutorial we will take a first look at benchmarking our .NET code using BenchmarkDotNet. BenchmarkDotNet is a nuget package that allows us to run benchmarks against our C# method...

â–¶ Play video
unique bronze
#

benchmark a singular if inside another one? damn, you must be slow.

daring crest
#

I mean, in general.

#

I just think asking questions about performance is a bad idea in general, because there are no good answers other than, "Benchmark it."

plush oracle
#

Even if it wasn't bad for performance its still not optimal

#

Why would you intentionally make your code look like shit

#

Time consuming aswell

daring crest
#

You can put an if-statement on multiple lines if you want to as well. 😅

#
if (extremelyLongBooleanExpression
    && anotherExtremelyLongBooleanExpression)
oblique marsh
#

just a couple of if statements are still really fast, if you check simple bool states,
what determines if it's slow or not is what you actually evaluate inside the if checks and other code, like what methods you call for the if check and their execution time

left cave
#

cool thing I really like to do is

void SomeFunction()
{
  if(!Something)
    return;
  if(!SomethingElse)
    return;
  
  DoStuff();
}
#

inverse the statement and return early

#

doesn't always work, but when it does, it usually improves readability

vast cradle
left cave
vast cradle