News for hackers. Stuff that matters.
Re:.NET Core 3.0 Concludes the .NET Framework API Porting Pr... by jayd16 on Tuesday October 15, 2019 @04:17AM (#21256511)
The closest you'll get to free floating functions are methods in a static class. The static classes essentially become namespaces.

Then with static using directives, you don't need to spell out the namespaces.

https://docs.microsoft.com/en-us/dotnet/csharp/language-refe...

You can even put every global function into a single class but still organize your code across multiple files by making them all part of the same partial class.

I personally wouldn't organize my code this way, but it seems like you can achieve what you want today with minimal effort.

Re:.NET Core 3.0 Concludes the .NET Framework API Porting Pr... by jeswin on Tuesday October 15, 2019 @05:04AM (#21256742)
> Then with static using directives, you don't need to spell out the namespaces.

Static using directives! Certainly a useful tool, thank you. I had been away from the .Net universe for a while and I think I have some more catching up to do. Some of the newer changes in C# help a lot with reducing code heft, even though it makes the language more complex.

However, the Framework seems to be headed in the opposite direction when it comes to simplicity. Here's for example the IOptions pattern: https://docs.microsoft.com/en-us/aspnet/core/fundamentals/co...

Re:.NET Core 3.0 Concludes the .NET Framework API Porting Pr... by noderat on Tuesday October 15, 2019 @10:31AM (#21258780)
I really wish the documentation for things like DI, IOptions and ILogger were moved out of the ASP.NET documentation. Trying to decipher from the documentation how to use these in a non-ASP.NET project is needlessly complicated.
Re:.NET Core 3.0 Concludes the .NET Framework API Porting Pr... by WorldMaker on Tuesday October 15, 2019 @04:13PM (#21263186)
It's getting pushed out of ASP.NET with the "Generic Host" efforts. It's still for the time being in ASP.NET documentation, but you see it's moving in that direction.

https://laurentkempe.com/2019/09/03/WPF-and-dotnet-Generic-H...

https://docs.microsoft.com/en-us/aspnet/core/fundamentals/ho...

Re:.NET Core 3.0 Concludes the .NET Framework API Porting Pr... by thomasz on Tuesday October 15, 2019 @08:36AM (#21257727)
The asp configuration thing is complicated but powerful. If you don't want that, you can just use ``Environment.GetEnvironmentVariable`` and be done with it.
Re:.NET Core 3.0 Concludes the .NET Framework API Porting Pr... by shhsshs on Tuesday October 15, 2019 @08:42AM (#21257759)
Plus it’s barely any extra work to load settings from environment variables. And it lets you write code agnostic to where the settings are coming from, and then choose to load them from environment variables, a file, hard coded values, etc.

Makes testing easier too because you don’t have to write a fixture around your settings. Just build the class with known setting values without writing code purely for testing.

Re:.NET Core 3.0 Concludes the .NET Framework API Porting Pr... by bob1029 on Tuesday October 15, 2019 @09:31AM (#21258138)
I have found that large partial classes declared across many physical source files creates lots of issues with intellisense throughput. At 50+ partials, you are looking at solid 10+ second delays in the IDE between when you typed something naughty and when you are informed of it. This behavior has been replicated across many different computers and versions of visual studio, so I think it's just a fundamental limitation.

We have some solid use cases for free floating functions (e.g. business rules that need to be able to arbitrarily invoke each other) which we ultimately decided to scope to one public function per class. This allowed for some other interesting advantages in terms of consolidating tightly-coupled business logic that was formerly spread across the codebase (e.g. items used only by the one function - mappers, request/response models, private utility methods, etc). We even explicitly duplicated out some logic in order to enable completely isolated verticals of BL.

Re:.NET Core 3.0 Concludes the .NET Framework API Porting Pr... by rafaelvasco on Tuesday October 15, 2019 @09:11AM (#21257966)
Don't get why people want floating functions. It makes easier to do bad coding and architecture imo. At least you must namespace them;
Re:.NET Core 3.0 Concludes the .NET Framework API Porting Pr... by goto11 on Tuesday October 15, 2019 @09:32AM (#21258148)
Consider something like the Math class. In practice it just works like a namespace for math-related functions. The only reason to have a class is because the language requires it.

It would certainly be cleaner without having to define a useless class.

Re:.NET Core 3.0 Concludes the .NET Framework API Porting Pr... by rafaelvasco on Wednesday October 16, 2019 @03:59PM (#21274818)
Well, a static Math class always did make perfect sense to me. Never bothered me. Even after I discovered languages that allow you to define functions everywhere, I still prefer static classes; As long as there's no performance penalties, I'm good. In fact, static classes method calls are really fast;
Re:.NET Core 3.0 Concludes the .NET Framework API Porting Pr... by jayd16 on Tuesday October 15, 2019 @04:23PM (#21263301)
Yeah, except I like that Log() isn't already a reserved function name.
Re:.NET Core 3.0 Concludes the .NET Framework API Porting Pr... by goto11 on Wednesday October 16, 2019 @07:38AM (#21269266)
I don't think anyone is suggesting the function names should be reserved names. They would still exist in a namespace.
Re:.NET Core 3.0 Concludes the .NET Framework API Porting Pr... by dragonsngoblins on Wednesday October 16, 2019 @09:18PM (#21278050)
I don't really understand how this is significantly different than having a static class with the function