F# Quality of Life Questions

前端 未结 3 458
死守一世寂寞
死守一世寂寞 2021-01-01 18:46

I started coding in F# about 2 months ago.

I am greatly enjoying this programming language. I come from a C# background, and every time I need to revert back to C#,

3条回答
  •  佛祖请我去吃肉
    2021-01-01 19:26

    1.There is no auto complete like VS has for C# right

    There is auto-complete for F#. It is not triggered automatically when you start typing though. If you're in Visual Studio and type aPara and then hit Ctrl+Space, it should be auto-completed to aParameter if it is in the scope. Similarly, you can do this in top-level scope to see available types and namespaces. Auto-completion also get triggered automatically when you type .

    2.Debugging is tedious to say the least

    I'd agree with this - debugging pipelines (especially with lazy sequences) is tricky. This is a bit confusing even when you're in C#, but C# does surprisingly good job on this one. There are two ways to deal with this:

    • Use F# Interactive more. I write most of my code in an F# Script file first, where you can run your partially complete solutions and see results immediately. For me, this pretty much replaces debugging, because by the time my code is complete, I know it works.

    • You can define a function tap that materializes the data in the pipeline and lets you see what is going through the pipe. I don't use this very much, but I know some people like it:

      let tap data = 
        let materialized = List.ofSeq data
        materialized
      

      Then you can use it in your pipeline:

      correctedData 
      |> List.filter (fun (_, r, _) -> r <= 3) 
      |> tap
      |> Seq.groupBy (fun (_, r, cti) -> (r,cti))                            
      |> tap
      |> Seq.map (fun ((r,cti),xs) -> (r, cti, Seq.length xs)) 
      |> Seq.toList
      

      This adds some noise to the pipeline, but you can remove it again once you're done with debugging.

提交回复
热议问题