techhub.social is one of the many independent Mastodon servers you can use to participate in the fediverse.
A hub primarily for passionate technologists, but everyone is welcome

Administered by:

Server stats:

4.6K
active users

#csharp

65 posts39 participants6 posts today

You Don't Need Enums - Refactor Away Enums In #csharp!

Enums in C# are easy for us to use, but often this means it's easy for us to use them ineffectively. While I don't like to say right and wrong for different things, I do like to point out pros and cons of different approaches.

In this video, we look at enum examples in C# and how we can refactor our csharp code to move away from enum usage altogether! Yay for refactoring!

Watch here:
youtube.com/watch?v=xsY9tyRbCV

According to uiCA from uops.info, it is faster (after .NET JIT) to perform (1)

if (flag) {
return constant;
}
return otherMethod();

than it is to run (2)

if (flag) {
return otherMethod();
}
return constant;

This only holds true on SkyLake architecture, where (1) has 9.54 cycles per iteration, and (2) has 9.04.

As of Tiger Lake, both have 6.5 cycles per iteration estimated.

Not accounting for otherMethod-content. je or jne in the branch doesn't make a difference.

One of the many fun parts of #monogame is that I can find books that cover XNA read those and pretty much learn Monogame. It's about 90% 1-to-1, I really appreciate it. I'm getting better at #csharp in general and I generally think if I keep cracking at this I'll have a projects I can put on my resume for an internship or a entry-level position (assuming those are still around when I graduate). Just gotta keep clicking and klacking away on this keyboard.