4 ms·
Can’t recommend a Linux IDE. I develop quite a lot of .NET for Linux lately, but I’m using a Windows computer with visual studio 2019 to compile and debug. Only
by Const-me 5y ago
Can’t recommend a Linux IDE. I develop quite a lot of .NET for Linux lately, but I’m using a Windows computer with visual studio 2019 to compile and debug. Only using the runtime on Linux to test things, with printf debugging when needed. Still, quite a few people on the internets, in this thread even, are saying Rider is actually good.
About programming, most of the things you have mentioned (except integrals and limits) are in the C# standard library. Here’s a few tips.
Be sure to handle exceptions in your Main(). On Linux, I usually printing messages into `Console.Error` stream and returning a non-zero status code. Without the top-level try/catch in the main, unhandled exceptions crash the process with no information about what happened.
Set <CheckForOverflowUnderflow>true</CheckForOverflowUnderflow> compiler switch in all your *.csproj files. It causes the runtime to detect integer overflows and throw exceptions in runtime when it happens. It’s very useful to debug things (exceptions come with stack traces, if you keep the *.pdb files they will even contain source file names and line numbers), but I usually keeping the setting in release builds too, for a bit of extra safety. The performance overhead is negligible on modern computers.
About the I/O, use modern APIs, the usability’s better. For instance, when you need to read a text file line by line, call File.ReadLines() method, returns a lazily-evaluated sequence of these lines. Also, modern .NET supports spans pretty much everywhere and therefore you can read/write stack allocated buffers or unmanaged memory. Albeit depending on your use cases, stack allocated buffers might be a premature optimization.
About web request, the standard library has two HTTP clients, older WebClient, and newer HttpClient. For many use cases the functionality is equivalent, pick whichever API you like better. In both cases, I recommend their async-await APIs to make requests. The language supports async main for a few versions now.
- dotancohen 5y agoPerfect, thank you. I do love the Jetbrains IDEs professionally, but its an expensive purchase for occasional use. I much appreciate the mention of catching exceptions. For my own programs I usually don't catch exceptions because I want the failure to be hard and informative. It seems that dotnet is the exception here.
- Const-me 5y agoCouple more things. Don’t abuse LINQ. It’s awesome, but I can only recommend for simple use cases. For advanced ones, too easy to screw up, and too hard to debug. When that’s the case, I’m usually writing a foreach loop instead, and/or generator methods. Also, when I do use LINQ I prefer the C# syntax like `seq.Select( x => x.something )` instead of the SQL syntax `select something from seq`. It’s a matter of taste but IMO compiler is doing too much magic with the SQL syntax. A few years ago, .NET finally got what MS calls string interpolation. Good stuff, can recommend, I think Python has an equivalent for a decade: https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/tokens/interpolated https://docs.microsoft.com/en-us/dotnet/csharp/language-refe... Most articles on the internets view C# as an object-oriented language. That’s only part of the story. In the typical code I’m writing, at least 50% of code is pure functions (in FP sense) in static classes. And at least 50% of non-static classes are structures (these are value types, an array or List<> of them will keep items at sequential memory addresses, good for performance) with all the fields marked readonly, i.e. immutable types. .NET 6.0 even has record structs now, with automatic readonly.