Sunday, May 7, 2023

ChatGPT (writing PowerShell example) Will Replace Most of My Searches Targeting StackOverflow.com and Microsoft.com

The Old Way of Technical Search

The modus operandi I use for most of my software-development-related research is to:

  1. Search using Google (yes, I prefer the results to Bing).

  2. Search with keywords and typically target the site that will give me the best results using Google site keyword such as:

    2.1 Find the man page for PowerShell's Invoke-RestMethod cmdlet: Invoke-RestMethod site:microsoft.com. Note above the site: refers to microsoft.com.

    2.2 How to use PowerShell's Where-Object to select a value in an array of arrays: filter array of string arrays PowerShell Where-Object site:stackoverflow.com. Note above the site: refers to stackoverflow.com.

  3. Read through and click on the results. For Stack Overflow (I have loved Stack Overflow for the last fifteen years), this is tedious because a lot of results need to be culled to find an answer to your question.

ChatGPT: the New Way of Technical Search

As an experiment, I asked ChatGPT to help me with a piece of code (yes, I could have written this code without searching) but it is complex code. Here are the instructions I gave ChatGPT:

  • I want to have a PowerShell array of type [PSCustomObject[]] and each element of the array is type [PSCustomObject[]]. I want to select all values where index 4 equals 'monkey'.
  • I want to have a PowerShell array of type [PSCustomObject[]] and each element of the array is type [string[]]. I want to select all values where index 4 equals 'monkey'.
  • [string[]] $a = 'x', 'y', 'z'; [string[]] $b = 'e', 'f', 'g'; [string[]] $c = 'q', 'r', 's'; [PSCustomObject[]] $a, $b, $c. Select all values where array index 1 equals 'f'.
  • enum SegmentIndexes { Region Subregion State }. Select index [SegmentIndexes]::Region equals 'f'.

  • Use the array from the previous example. I am not interested in an array of enumerations.
  • Use the array before that.
  • Rewrite the code with no comments and please put the type in front of the declared variables
  • I did not ask you return $filterArray so the last line is not needed
  • Do not use a ; when populating the hashtable
  • You are incorrect. The ; are still used in the hashtable

Here is the code ChatGPT generated which is correct:

enum SegmentIndexes { Region Subregion State } [PSCustomObject[]]$array = @( @{ 'EmptySlot' = 'x' 'Region' = 'f' 'Division' = 'a' } @{ 'EmptySlot' = 'y' 'Region' = 'g' 'Division' = 'b' } @{ 'EmptySlot' = 'z' 'Region' = 'h' 'Division' = 'c' } ) $filteredArray = $array | Where-Object { $_[[SegmentIndexes]::Region] -eq 'f' }

Apology

Over the past few years, one of the best people I've worked with is Stephen Durant of Stack Overflow. He is a customer liaison to corporate users of Stack Overflow. I do not normally praise someone for doing their job, but Stephen is really elite at his work. So, Stephen, I apologize because ChatGPT has filled many more of my needs related to technical search.

Acknowledgments

This blog was proofed by ChatGPT.

No comments :

Post a Comment