Remix.run Logo
contextfree 4 hours ago

A dumber but related habit I've gotten into is that if I want to use AI to do some sort of refactoring on a C# codebase, instead of asking it to edit the code directly I ask it to write a code transformation using the Roslyn compiler API, then run that on the code. The result is less likely to have subtle bugs if it appears to work and gets through a light code review on the transformation (i.e., attempts to cheat with weird special-casing are more likely to stand out amongst the Roslyn API code, and if there isn't such weird special-casing but the code is wrong, the result is more likely to be completely broken rather than subtly broken)

twosdai 2 hours ago | parent [-]

This sounds interesting, I am really naive. I don't code in C#, is there an analogy for other programming languages, like GO, or Python or Typescript?

Like are you prompting like:

--- I need code that does X,Y, and Z. Write it so that the Roslyn compiler on this machine can compile and the code passes the repo's styling and formatting requirements. ---

Or something else.

kaashif 2 hours ago | parent | next [-]

No, they are talking about refactoring, not adding new functionality to code.

So it would be something like:

Rewrite this Python code to use match/case instead of if/elif/else chains, write a script using the ast module to rewrite the code, do not edit it yourself, also write some tests with clear inputs and outputs I can inspect.

Or something.

bob1029 2 hours ago | parent | prev [-]

Here's the official docs if it helps

https://learn.microsoft.com/en-us/dotnet/csharp/roslyn-sdk/t...