DEV Community

Discussion on: Should you pick C# over JS? Maybe.

Collapse
aarone4 profile image
Aaron Reese

Ignoring node and demo which are js on the server, and blazor which is C# in the browser (via webassembly) they are solving problems in different parts of the stack so I don't see how you choose one over the other. Also it would be more appropriate to compare C# to Typescript as both give you static types and type checking. My biggest issue with C# was the number of using statements required to achieve even the simplest of tasks. For example simply connecting to a SQL database requires about 20 lines if code to import and set up the connection protocol.

Collapse
denvercoder profile image
Tim Myers Author

And I’m not sure what you mean here. You say that C# and JavaScript are “different parts of the stack” but I can build a front end with JS or C#. I can build a Mobile app with JS or C#. I can build a server with JS or C#. I can build a game with JS or C#.

How are they different parts of the stack?

Collapse
aarone4 profile image
Aaron Reese

Traditionally JS is used for browser / client side interactivity and data manipulation C# is middleware and intercepts the HTTP GET/POST calls and does something with them. The lines are more blurred now becase you can run JS on the server in node, I am not aware of a native implementatin of C# in a browser. You can compile to web assemby but that is a different topic altogether. JS is front end code, C# is middleware

Thread Thread
denvercoder profile image
Tim Myers Author

LOL. Blazor is C# running in the browser using web assembly.

Thread Thread
pjotre86 profile image
pjotre86

Is that the thing which needs to download the .Net runtime into the browser in order to work?

Collapse
rehman000 profile image
Rehman Arshad

I think the poster meant to say that C#, and (vanilla) JS are not really comparable, because C# is statically typed so a better (Apples to Apples) comparison would be Typescript v.s C#. But in complete fairness, you're not entirely wrong. They (C# and JS) can accomplish the exact same end goal. You can make a mobile app with JS or C#, you can make a backend server with JS or C#. So the overall functionality of what your trying to accomplish would still be the same, aside from the language differences.

So why wouldn't they (C# or JS) hold the same spot on the stack? Maybe I'm confused sorry. I apologize.

Thread Thread
denvercoder profile image
Tim Myers Author

I wasn’t comparing them. I was saying that instead of starting with JavaScript you could start with C#.

Collapse
denvercoder profile image
Tim Myers Author

20 using statements vs 20,000 node_module files? 🤔

Collapse
denvercoder profile image
Tim Myers Author

With JavaScript you can use the fetch api but it sucks and almost no one does so you ‘npm install’ axios and then add an import statement. JavaScript doesn’t have good date time handling so you ‘npm install’ date-fns.

Would you like to see how many import statements I have on my current JavaScript project?

Thread Thread
denvercoder profile image
Tim Myers Author

There are several files with 30+ imports but the average is about 12 per file.

Now with Blazor all of your front-end usings can be put into one file and you can maintain them there.

Collapse
aarone4 profile image
Aaron Reese

Ah yes, but I don't need to know WHICH 20,000 mode_module files :)

Thread Thread
instanceid profile image
instance.id

I can't remember the last time I had to manually add a using statement with Rider, or really with most any modern IDE. They just add them for me.

Thread Thread
denvercoder profile image
Tim Myers Author

Yep. I use rider too. Or you can use Resharper. And I don’t know if it’s still around but there issues to be Visual Studio Power Tools that added usings.

denvercoder profile image
Tim Myers Author

And I don’t need to know what usings I have. If you place your cursor over the red squiggly then hit CTRL+ . It will add them for you. 😂