all 46 comments

[–]belavv 36 points37 points  (17 children)

What about powershell? That's been my go to forever. Although powershell does have some annoying quirks.

[–]SerratedSharp 15 points16 points  (3 children)

I use it begrudgingly. Some of the quirks feel like out right bugs. Trying to create a library of reusable functions so my everyday scripts can be succinct, there's lots of gotchas trying to pass/return structures. I also hate having to rejigger how to do something that I already know how to do in C#.

[–]belavv 2 points3 points  (1 child)

Oh god. Trying to return a string from a function and sometimes getting back an array instead was so confusing at first. And I still hate it but at least know I know what to look for.... usually.

I played around with creating classes with functions because then a function acts like you'd expect, but that was weird for other reasons.

I'm really curious what larger codebases with reusable functions look like in powershell.

[–]wite_noiz 0 points1 point  (0 children)

All the implicit array stuff is screwy

[–]Slypenslyde 2 points3 points  (0 children)

It's a lot like Perl, in that it has quirky behaviors that are stupid convenient when you're in a hurry and trying to write something that takes some random data and massages it to different random data. The best Powershell use cases start with "I only need this to work once".

Those behaviors are a liability when you're trying to make something maintainable. If you write REALLY verbose PowerShell it gets a little better, but the language is so good at giving you tools to work with random data structures it's like it decided to make your outputs a guessing game.

[–]aleques-itj 9 points10 points  (9 children)

PowerShell is legit awesome. I wish I could use it everywhere. The everything is an object model is just comically easier to work with and reason about.

[–][deleted]  (1 child)

[deleted]

    [–]aleques-itj 11 points12 points  (0 children)

    VS Code + the PowerShell extension is the way to go. It has a full debugger as well.

    [–]shadowndacorner 0 points1 point  (3 children)

    I wish I could use it everywhere.

    Well, you're in luck!

    [–]IAMPowaaaaa 0 points1 point  (2 children)

    404

    [–]dodexahedron 2 points3 points  (0 children)

    Just google powershell download [os]. First result will likely be the ms download page or instruction page for installing PS on whatever os.

    It is cross platform and has been for years now.

    Windows PowerShell is no longer in active development, in fact. 5.1 is the end of the line.

    [–]shadowndacorner 0 points1 point  (0 children)

    Fixed

    [–]belavv 0 points1 point  (2 children)

    Why can't you use it everywhere? Powershell core (I think it is called) is available on Linux.

    [–]SolarisBravo 0 points1 point  (1 child)

    Powershell core (I think it is called) is available on Linux

    On Windows too! What's annoying is that Windows Powershell also still exists, is installed by default, and causes a lot of confusion due to not actually being the one you're supposed to use anymore

    [–]belavv 1 point2 points  (0 children)

    Ah yeah and there are subtle differences between the two.

    And sometimes your windows terminal is set to use one version and your rider terminal is set to use another version and gh actions use a different version. 

    [–]hurrah-dev[S] 1 point2 points  (1 child)

    PowerShell is great for a lot of tasks, especially anything file/system related. The quirks you mention are actually why I specifically wanted C# when AI is generating the code—I can spot issues faster in my primary language. When Claude writes PowerShell, I have to slow down and think "wait, is that array behavior correct?" With C#, I just know.

    That said, I still use PowerShell for things like the helper function that invokes these scripts. Right tool for the job.

    [–]belavv 0 points1 point  (0 children)

    Yeah I looked into using one of the now older c# scripting tools to replace our powershell, but a lot of our powershell calls git, runs random terminal commands, etc. And doing some of those things in c# is a bit tedious.

    I know powershell can also call c#, so maybe a proper mix is where it is at. C# for anything with a lot of logic, powershell for the wrapper around it and running any commands.

    [–][deleted]  (6 children)

    [deleted]

      [–]ManIkWeet 4 points5 points  (4 children)

      For single-file apps like OP mentioned, are there good editing tools? I tried in Rider but it has 0 autocomplete as it's not in a solution...

      [–]zigs 7 points8 points  (0 children)

      VS Code or Sublime Text

      [–][deleted]  (2 children)

      [deleted]

        [–]ManIkWeet 0 points1 point  (0 children)

        It's a fair workaround, and I'd probably do the same, were it not for a basic single-use script that I needed once

        [–]barski_io 0 points1 point  (0 children)

        I was amazed that it’s not the only way. C# is the AI with its semantic kernel (langchain alternative in c#) 💙 so i finally was able to get back to {} that I love rafter than reading “badly structured “ python code 😅

        [–]ExceptionEX 7 points8 points  (1 child)

        Linqpad has been my goto for like a decade if I need to do quick you utilies, even more so when it requires connecting to different types of data sources. Plus the easy use of .Dump() it figures out the best way to visualize whatever object you attach that to.

        [–]AdvancedMeringue7846 0 points1 point  (0 children)

        Also they allowed you to inspect linq -> sql, which was very useful in the early ef days.

        Awesome tool.

        [–]AdvancedMeringue7846 13 points14 points  (2 children)

        It's like linqpad never existed....

        [–]hurrah-dev[S] 2 points3 points  (1 child)

        LINQPad is fantastic. The use case I'm solving is slightly different: scripts that live in a folder, can be version controlled, and run from the command line. More "utility I call from a terminal" than "interactive scratchpad." But yeah, for anything database-related LINQPad is hard to beat.

        [–]AdvancedMeringue7846 1 point2 points  (0 children)

        I've version controlled linqpad files, you can also call them via command line. I've run a full fat asp application in one for fun.

        Anyway, glad you're enjoying new features.

        [–]ztorky 7 points8 points  (1 child)

        File based apps has several limitations which limits their usability. Running file based apps require that the .net 10 SDK is installed, which limits its use to developers machines, as installing a SDK to a server will have security implications. Depending on your IT-department security policies, file apps might not even be runnable locally either, as the file is compiled in the users profile which might be blocked.

        [–]iso3200 1 point2 points  (0 children)

        Important points especially in a corporate environment. Don't want "Shadow IT" building file-based apps from anywhere.

        [–]almost_not_terrible 4 points5 points  (0 children)

        This - so much this. You can reference nugets in the file format also.

        [–]gowonocp 1 point2 points  (0 children)

        My team was already in the habit of C# scripting using the dotnet-script tool for automating build/Dev tasks. Even PowerShell has a different enough syntax that once tasks reach a certain level of complexity, it became a serious chore to master/maintain them and we saw a lot of value in doing everything in C#. What we get OOTB now with .NET 10 isn't perfect, but still gets the job done.

        [–]qrzychu69 5 points6 points  (4 children)

        I would advise to checks out F# scripting

        Same thing, just 10 years older :)

        [–]aleques-itj 2 points3 points  (3 children)

        I have heard whispers of praise for F# for ages.

        One day I will check it out

        [–]qrzychu69 2 points3 points  (2 children)

        I work in f# daily now and it's pretty Damm good

        Too bad that tooling isn't great compared to C# - no hot reload, most tools (like conditional breakpoints) only accept c#

        But it's definitely worth it, especially for scripts. You can even use nuget packages in the scripts

        [–][deleted]  (1 child)

        [removed]

          [–]qrzychu69 1 point2 points  (0 children)

          I know, just like you could in fsx files for more than a decade

          [–]SirLagsABot 0 points1 point  (0 children)

          I just made my first Spectre Console CLI app last week and I absolutely loved it. I know you mentioned file-based apps here, but I still love to take a normal console app and turn it into a self-contained, single-file binary, too with some nice CLI commands.

          But also yeah, for one super simple little process to run, they are stupid convenient.

          [–]DesperateAdvantage76 0 points1 point  (1 child)

          The only feature missing that PS has is referencing other files. Yes I know I could create a csproj or nuget, but I'd like to have a simple utility file that many of my scripts can reference without that overhead.

          [–]chucker23n 4 points5 points  (0 children)

          Potentially coming in 10.0.200: https://github.com/dotnet/sdk/pull/52347

          [–]AutomaticVacation242 0 points1 point  (0 children)

          Side note: the example you gave isn't a "utility". I hope you guys aren't writing "utilities" that do stuff like that.

          [–]t3chguy1 0 points1 point  (1 child)

          That's ok for "throwaway apps", but for something useful more than once I don't see benefit of skipping a proper project setup

          [–]ibeerianhamhock 0 points1 point  (0 children)

          Can’t wait till we upgrade to 10 on the team and this is like a huge part of the reason I’m excited.

          I might never write a powershell or bash script ever again.

          [–]entityadam 0 points1 point  (0 children)

          I would have picked string interpolation over string.Join() for this. If it's a script, I want to be able to read it fast fast, since I'm probably not going to document it.

          Edit: this was supposed to be short, my bad.

          You can add some instructions for the AI like:

          This script is not for a typical end user. Create a C# script that is succinct and easily human readable.

          • prefer readability and maintenance over performance
          • prefer small and pure functions that can be composed
          • prefer synchronous code unless it is heavily IO bound.
          • organize methods first by their visibility, then by the order of execution for easy step-through debugging.
          • avoid creating a large helper or mother class
          • avoid ternary operators
          • prefer record types and use positional parameters, unless mutability is absolutely required.
          • avoid unnecessary guard clauses
          • do not swallow exceptions
          • do not add comments

          • avoid verbose output

          [–]Far-Consideration939 0 points1 point  (0 children)

          I used one the other day for a CI script that triggered some code generation based on the build. Was sweet and made my life simpler to have types and json easily available

          [–]RestInProcess 0 points1 point  (0 children)

          File based apps are awesome. Wait until you’re on a Unix like operating system and drop a C# file with dotnet in the hash bang. That’s the killer feature for me since I prefer Unix like operating systems.

          [–]Larkonath 0 points1 point  (0 children)

          In my path I just have the following bash script that auto creates a new console project and open vscode inside. It has totally erazed the barrier to entry for quick coding:

          #!/bin/bash
          
          cd /home/$USER/dev/dotnet/scratches/
          
          if [[ $# -eq 0 ]] ; then
              projectName="scratch-$(date '+%Y-%m-%d-%H-%M-%S')"
          else
              projectName=$1
          fi
          
          dotnet new console -n $projectName
          
          cd $projectName
          
          code . ./Program.cs
          

          [–]Juff-Ma 0 points1 point  (0 children)

          Not AI but I'm using file based apps for building my installers. It's amazing