F#生活质量问题 [英] F# Quality of Life Questions

查看:70
本文介绍了F#生活质量问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在大约2个月前在F#中开始编码。

I started coding in F# about 2 months ago.

我非常享受这种编程语言。我来自C#背景,每次需要恢复到C#时,感觉很麻烦和blo肿。

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

但是我仍然认为有问题的是F#,这是我的问题与...有关:

But there are still things I think are problematic in F#, and this is what my questions are related to:


  1. 没有自动完成,像VS有C#对吗?例如。在一个使用参数aParameter的函数内部,如果我写了一个没有自动完成的文件。 VS内部是否有功能可以解决这个问题,我不知道什么?

  1. There is no auto complete like VS has for C# right ? E.g. inside a function that takes parameter aParameter, if I write aPara no auto complete comes up. Is there a functionality inside VS that can solve this issue and which I am not aware of?

调试很乏味。由于F#支持管道/链接或任何您想要调用的链接,我通常会尝试链接尽可能多的东西(无论何时当然)。示例:

Debugging is tedious to say the least. Since F# supports piping / chaining or whatever you want to call it, I typically try to chain as many things as possible (wherever it makes sense of course). Example:

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


这只是四分之一我的整个链接完成了。每当我在这些链中乱七八糟的时候,我觉得很难调试出错了。

And this is just quarter of my whole chaining done. Whenever I mess something up in these chains, I find it very very hard to debug where it all went wrong.

我这样做是否错了(滥用)?从我的观点来看,这种链接的中介从来没有以原子态存在,所以没有理由有中间价值观。但是由于这个语义的观点,我也失去了有助于我调试的中介价值的力量。所以我必须将它们插入代码,调试,然后再次删除。但这是浪费的努力。有没有办法呢?

Am I doing this chaining wrong (abusing it)? From my point of view, nothing intermediary from this chaining makes sense to exist atomically, thus there is no reason to have intermediary values. But because of this semantic point of view, I also lose the power of having intermediary values which help me debug. So then I have to insert them in the code, debug, then remove them again. But this is a wasted effort. Is there any way around this?

另外,调试一个链中的List.map匿名函数比起来,再次感到尴尬和困难。一个for循环。

Also, debugging a List.map anonymous function inside a chain feels again awkward and hard compared to e.g. a for loop.

我确信我缺少一些东西,而我目前的调试方式可能不是最佳的 - 不是一个长镜头 - 所以任何建议欢迎。

I am sure that I am missing something, and that my current way of debugging is probably not optimal - not by a long shot - so any suggestions are welcome.

推荐答案


1.没有自动完成,如VS对于C#正确

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

F#自动完成。当您开始打字时,不会自动触发。如果您在Visual Studio中,并键入 aPara ,然后按 Ctrl + 空格,则应自动完成到 aParameter 如果它在范围内。类似地,您可以在顶级作用域中查看可用的类型和命名空间。当您输入时,自动完成也会自动触发。

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.调用是很难说至少

2.Debugging is tedious to say the least

我同意这一点 - 调试管道(特别是懒惰序列)是棘手的。即使您在C#中,这有点令人困惑,但是C#在这一方面做得非常出色。有两种方法来处理这个问题:

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:


  • 更多使用F#Interactive。我首先在F#脚本文件中写入我的大部分代码,您可以在其中运行部分完整的解决方案,并立即查看结果。对于我来说,这几乎取代了调试,因为在我的代码完成的时候,我知道它是有效的。

  • 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

然后你可以在你的管道中使用它: / p>

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.

这篇关于F#生活质量问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆