英文:
How to apply Clean Code to R and what are some alternatives specific to R?
问题
以下是翻译好的内容:
我以一种非常糟糕的方式自学了R,并且我正在努力改进。我阅读了Robert C. Martin(2009)的《Clean Code: A Handbook of Agile Software Craftsmanship》,该书提供了编码的最佳实践,我发现它很有帮助。然而,由于我除了R之外没有编程经验,所以很难理解其中的行话(或大部分用Java编写的示例),我的理解能力受到了限制。我的问题是:
1)在附图中,我列出了我不理解的《Clean Code》中的术语,并猜测在R术语中的等效术语,如果我有任何错误,请您纠正我?(我确实买了这本书,但为了这个问题,可以在这里找到《Clean Code》的pdf版本:Clean Code pdf)
如果我找到其他像《Clean Code》一样提供基础最佳实践的书籍,特别是专门针对/与R编写的书籍,这将非常有帮助。我在数据科学中使用R,但几乎没有在项目中取得什么成果,而只是创建了一堆混乱的代码。特别是,我在编写简洁代码方面存在困难,并且不知道何时应该启动新脚本,以及如何使不同的脚本在一起协同工作。
我还阅读了Wilson等人于2017年撰写的《Good Enough Practices for Scientific Computing》,这本书非常棒。我确实使用R项目。感谢您的时间!
英文:
I self-learned R in a really poor way and I’m trying to improve. I’ve read Clean Code: A Handbook of Agile Software Craftsmanship by Robert C. Martin (2009), which provides best practices for coding and I found it helpful. However, my capacity to understand it was limited because I have no programming experience besides R so couldn’t understand the jargon (or much of the examples, written in Java). My question is:
- In the attached image, I’ve listed terms from Clean Code that I didn’t understand and made a guess at what the equivalent would be in R terminology - could you please correct me if I got any of these wrong? (I did buy the book, but for the purposes of this question, a pdf of Clean Code is found here: Clean Code pdf)
If I found other books that provide foundational best practices like Clean Code does that are written specifically for/with R, it would really help. I use R for data science and I never get very far into a project without creating a total rat's nest; in particular, I struggle with writing concise code, and in knowing when I should start a new script, and how to get separate scripts to work together coherently.
I have also read Good Enough Practices for Scientific Computing by Wilson et al. (2017), which is great. I do use R projects. Thank you for your time!
答案1
得分: 0
R是一种多范式语言,因此直接采用面向对象的编码风格来提升你的R技能并不是最好的主意。GoF设计模式中有16种通常模式在函数式编程中是无关紧要或微不足道的(因此在R中也是如此)——将自己局限于面向对象的思维模式将会产生更多的反作用。
我建议阅读《代码整洁之道》(面向对象代码的外观与函数式程序员认为的“整洁”几乎没有什么不同),但要真正优化你的R代码,你需要补充函数式编程。在这种情况下,有很多书供你阅读:Michelson的《通过Lambda演算入门函数式编程》,Neal Ford的《函数式思维》,Joshua Backfield的《函数式转变》。
函数式编程是一种纯粹的未开发利用的力量,你可以在R中使用它。为什么要将自己局限于仅使用面向对象编程呢?
英文:
R is a multi-paradigm language, so directly adapting OOL-like code style to improve your R skills isn't exactly the best idea. 16 of the usual GoF design patterns are irrelevant or trivial in FP (hence also in R) - it would be more than counterproductive to limit yourself with the OO mindset.
I do recommend reading "Clean Code" (the cosmetics of OO code isn't much different than what FP programmers would consider "clean"), but to really optimize your R code you need a supplement of FP. In that case, plenty of books are available for you to read: Michelson's "An Introduction to Functional Programming Through Lambda Calculus" (if you are completely new to FP), "Functional Thinking" by Neal Ford, "Becoming Functional" by Joshua Backfield.
FP is pure untapped power which you can use in R. Why limit yourself only with OOP?
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论