Iris Classon
Iris Classon - In Love with Code

AI Assisted Programming: Ten Real Life Coding Prompts I Used Today

This blog post was not written with AI, hence possible typos and grammar issues.

I use AI tools such as GitHub CoPilot and Rider AI Assistant on a daily basis, and I thought it would be interesting for others to know how I use them by sharing some of the prompts from today. For context, I’m working on the Plejd app, which is a Xamarin.Forms app that is in the process of being migrated to MAUI. I’m not on the MAUI migration task right now, so most of the work I’m doing is preparing the Xamarin.Forms app for migration by making sure new additions are migration-friendly. I use speech-to-text when I work, so writing a prompt takes less than a couple of seconds.

Goal: Change all properties to fields

  • Context: Created a custom StackLayout view and started off with public properties that I realize we won’t be using outside the scope of the class.
  • Prompt: Make the properties private fields as we only use them internally. Use correct naming. Underscore and lowercase first letter. Make fields that are only accessed locally in the method into variables. Please provide the full solution.

Goal: Replace EndAndExpand but keep alignment (UI)

  • Context: Same custom view as above. It’s a view with several labels and the view is used in a Grid.Row.
  • Prompt: I’m refactoring this class before moving to MAUI (not making the move yet), and I know EndAndExpand is not supported in MAUI. What would you change? I need the labels to align right.

Goal: Documentation

  • Context: We use XML documentation tags for all properties, fields, and methods, etc. I used to hate documentation, but it’s honestly been very helpful in this codebase that has a lot of domain-specific terms, is complex, not to mention how big the solution is (we are 15 people on my team).
  • Prompt: Write documentation for the fields by using the XML documentation in the X class.
  • Note: Documentation prompt (saved): Write XML documentation for $SELECTION using the conventions in this class and other classes. Short text, avoid remarks.

Goal: Merge methods

  • Context: Old code contained three event handlers that were complex but very similar.
  • Prompt: These three methods are very similar; can we combine them into one?

Goal: Add type reference and explanation in XML comment

  • Context: An old class has been replaced with a newer version/solution moving forward, but we don’t want to mark it as obsolete quite yet. I wanted to add a comment with a class reference, and I always forget how to add type references in XML comments.
  • Prompt: Add a comment for the class to use NewClass for collapsible X content.

Goal: Rename explaining variable

  • Context: I was tired and couldn’t come up with a better name for an ’explaining variable'.
  • Prompt: What’s a better name for the checked state? Suggest ten.
  • Link to video

Goal: Check for missing parameter (that is optional)

  • Context: We have a new extension method that adds a touch handler, and the method has a style parameter for setting the style of the touch. I used a script for adding the extension method where needed in a rather big class, but I suspected the style parameter wasn’t added where it should have been added.
  • Prompt: Have I missed setting the style argument on the WithTouchEffectAsync method in the XView class. Please provide line location.

Goal: Refactoring. Change group to list.

  • Context: General refactoring of complex grouping of light devices.
  • Prompt: I want this as one list of ILights instead of IGroup.

Goal: Refactoring. Improve Linq statement

  • Context: Long Linq statement that could be improved. Before committing the changes I wanted to know if the AI assistant would find potential that I had missed.
  • Prompt: Can these lines be improved?
  • Note: The assistant saw two OfType calls which could be merged into one. I had missed this!

Goal: IDE troubleshooting

  • Context: IDE stopped building binaries
  • Prompt: No binaries are being built for Android, but I get no errors. The configuration options are greyed out and I can’t deploy. Any suggestions?

Do you use AI tools when programmingm, and if so, what and how do you use it? For some reason it seems so taboo to use these tools as a programmer. Which is interesting, as we generally love automating things, right?

Comments

Leave a comment below, or by email.

Last modified on 2024-06-26

comments powered by Disqus