C# and .NET Core Appreciation Post. The most beautiful piece of code I have ever seen... this month!

Sdu - Dec 9 '19 - - Dev Community

Disclaimer!

This post is a little bit ridiculous and over the top but I'd be doing injustice if I do not share my thoughts on how the journey of learning something new feels like. But if you're in a rush, just scroll to the snippet at the bottom

So here's the thing. Years ago, when I had just started programming, as part of my degree, I hated C#. I didn't want anything to do with any project related to Microsoft related tech. Here's the rationale behind this (it's a dumb rationale) Why does C# have a 'C' in its name but looks almost exactly like Java? I also believed that a good programmer must know Java, C/C++, PHP for server programming, and Python just to prove you're smart. I swear this is a phase that I literally went through.

This was because when you've just started coding, for some reason there's this notion of being defined by the programming languages you know and the libraries you use. I'm sure that was greatly influenced by the "Top 10 best languages to learn in 201X" or "Language X is dead, here's why", even "Programming languages used by Facebook" articles that I actively looked for! just so that I don't get left behind in the industry.

Of course, a lot changed in the way I view tech and my career but what I felt about C# or anything related to it never changed, until about 6-7 months ago. See, at work, they use a shit ton of .NET (or dotnet. I'm still getting the hang of this) so I'm learning it now. A few months ago, I completed a 'Basics for beginners' udemy course. It was fine I guessπŸ™„ but learned a lot of cool stuff πŸ€—

Now I'm creating a project so that I learn more of this freaky stuff. Enter .NET Core 3! The most overwhelming piece of framework I've ever encountered (this year. I have to be clear on this). I have never given up so many times but come back to try again, in just a single week, ever for any project that I ever started to learn. When I finally got my thingie to give me a token for authentication, after days and nights of struggle, I ran the most satisfyingly powerful git command known to mankind

git commit -m 'Initial commit'
Enter fullscreen mode Exit fullscreen mode

I was happy. Then I had my supper while rereading up on what I've implemented and that's when I saw it

The masterpiece

private User GetUserByToken(string token)
{
    var user = (from u in _context.Users
        join t in _context.Tokens
            on u.Id equals t.UserId
        where t.Body == token
        select u).SingleOrDefault();

    return user;
}
Enter fullscreen mode Exit fullscreen mode

It's beautiful isn't it? I thought so too
I mean do you understand that the last time I saw something this cool was when I saw JSX for the first time, which looked so confusing but really not so trivial after some time of use. My brain doesn't have to context switch between application code and database scripts but the thing just works seamlessly. And the syntax highlighting plus the IntelliSense! I am stunned.

If you're reading this and you do not understand WTF is going on here, it's okay, it's not your time yet. But later on in your life, you will see what I saw and you'll say "shit, that dude on dev.to wrote a weird post about this feeling I'm feeling right now".

Not convinced? Look again

Code snippet

. . . . . . . . . . . . . . . . . .
Terabox Video Player