-
-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Out<T> and Print<T> problematic as generic methods #193
Comments
Removing it outright would regress stuff like this: cathode/src/samples/scrolling/Program.cs Lines 11 to 16 in 095df82
Obviously you shouldn't be writing code in that fashion when performance matters, but it is quite convenient when it doesn't. Not having some sort of "just output the stringified form of whatever I pass in" method will also likely be a significant paper cut for someone coming from The overloading problems do need to be solved though. I'm leaning towards the extension method approach since I don't think any of these methods need access to In regards to these methods being a performance trap: If it happens often enough, maybe you could make use of BannedApiAnalyzers? That's what Cathode itself does to ban <ItemGroup>
<AdditionalFiles Include="BannedSymbols.txt" />
</ItemGroup> And then add the problematic methods to |
Cool, I didn't think to make it a locally banned API for myself. This will work 👍🏽 |
I'm using this banned list to start out:
...and immediately ran into a problem: I don't want to ban The banned symbols format doesn't support un-banning/exclusions, or selecting specific generic instantiations either. I can work around this by tacking on an I wouldn't mind adding my own For the moment, I'm locally modifying Cathode to add |
I think it'd be reasonable to add a |
Cool, I'll do a PR this weekend |
I'm already putting together a patch to extract most of the methods out as extensions, so I'll just do it as part of that. I just posted the above to acknowledge that point. 🙂 |
Even better. :) I look forward to reverting my local changes. |
@scottbilas for |
Yes and PrintLine. My prev comment with the banned api list has the full set I discovered. |
This is an API intended for high-performance scenarios where allocations should be avoided. These methods ran contrary to that. Part of #193.
This helps avoid most cases going through the generic overloads. Part of #193.
Ok, I pushed some initial work on this. Let me know how that looks to you. Still need to do the cathode/src/core/IO/TerminalIOExtensions.cs Lines 236 to 239 in 2d3ed1d
That is, it looks like it's atomically writing the value and the new-line character... of course, in reality, that's not how that plays out at all: cathode/src/core/IO/TerminalIOExtensions.cs Lines 74 to 81 in 2d3ed1d
So I think it should just get the same treatment as |
Looks great! The increasing list of overloads across types would make me reach for some T4 codegen, personally. :D One suggestion - given the nature of Regarding the |
This helps avoid most cases going through the generic overloads. Part of #193.
I think this is mostly done now. One question that remains is: Should
Those should just be |
I've run into problems with the
Print<T>
andOut<T>
generics. These do aToString()
on whatever is passed in, which is generally nice for usability, but I have more than once accidentally passed in something that gets auto-stringized, rather than the compile failing and catching my mistake.Furthermore, the generic blocks my ability to add extension methods for custom type handling. A great example of this is when I wanted to add an
Out(Spectre.Console.Rendering.IRenderable)
extension. Unfortunately, theOut<T>
always wins over an extension, and for any parameter type. And if I simply forget to callAnsiConsole.Console.ToAnsi
first, then I get the default/badObject.ToString
behavior. IMO these generic functions cause more problems than they solve.I can think of a few potential improvements:
Out<T>
entirelyOutValue<T>
Out<T>
to an extension methodOut(object)
(as withSystem.IO.TextWriter
, adding in a bunch of overloads for primitives to reduce boxing)My favorite is the first option. Cathode feels to me much more close-to-the-metal API vs the console stuff .NET ships with. Lots of work has gone into minimizing allocs and avoiding copying. So these stringizing helper methods feel out of place to me.
(Related: #192 (comment))
The text was updated successfully, but these errors were encountered: