两种编程语言转换_熟悉两种以上的编程语言

两种编程语言转换

Editor’s Note: Learning multiple languages is key to anyone’s success as a programmer. Dr. Russel Winder gained experience with learning and teaching multiple languages first as Professor of Computing Science and head of the department of computer science at King’s College London, then later working at various startups. Now retired, he continues to share his passion for learning programming languages, and here shares how learning multiple languages and paradigms can change your approach to programming for the better.We’d love to know your thoughts on this piece from 97 Things Every Programmer Should Know.

编者注: 学习多种语言是任何人成功成为程序员的关键。 Russel Winder博士首先担任计算科学教授和伦敦国王学院计算机科学系主任,在学习和教授多种语言方面积累了经验,随后又在多家初创公司工作。 现在退休了,他继续分享他对学习编程语言的热情,并在这里分享了学习多种语言和范式如何使您的编程方法变得更好的方法。我们很乐意从 每个程序员应该做的97件事中 了解您对这一部分的想法 知道了

程序设计心理学 (The Psychology of Programming)

People have known for a long time now that programming expertise is related directly to the number of different programming paradigms that a programmer is comfortable with — that is, not that he just knows about or knows a bit of, but that he can genuinely program with.

人们很久以来就已经知道编程专业知识与程序员可以适应的不同编程范式的数量直接相关,也就是说,不是他只是知道或不知道一点,而是他可以真正地使用。

Every programmer starts with one programming language. That language has a dominating effect on the way that programmer thinks about software. No matter how many years of experience the programmer gets using that language, if she stays with that language, she will know only that language. A one-language programmer is constrained in her thinking by that language.

每个程序员都从一种编程语言开始。 该语言在程序员思考软件的方式上起着主要作用。 不管程序员使用该语言有多少年的经验,如果她坚持使用该语言,那么她只会知道该语言。 一种语言的程序员在该语言中受到了限制。

A programmer who learns a second language will be challenged, especially if that language has a different computational model than the first. C, Pascal, Fortran — all have the same fundamental computational model. Switching from Fortran to C introduces a few, but not many, challenges. Moving from C or Fortran to C++ or Ada introduces fundamental challenges in the way programs behave. Moving from C++ to Haskell is a significant change and hence a significant challenge. Moving from C to Prolog is a very definite challenge.

学习第二语言的程序员将面临挑战,尤其是如果该语言与第一语言具有不同的计算模型时。 C,Pascal和Fortran都具有相同的基本计算模型。 从Fortran切换到C带来了一些但不是很多挑战。 从C或Fortran迁移到C ++或Ada带来了程序行为方面的根本挑战。 从C ++迁移到Haskell是一个重大的变化,因此是一个巨大的挑战。 从C转移到Prolog是一个非常明确的挑战。

We can enumerate a number of paradigms of computation: procedural, object-oriented, functional, logic, dataflow, etc. Moving among these paradigms creates the greatest challenges.

我们可以列举许多计算范例:过程,面向对象,功能,逻辑,数据流等。在这些范例之间移动会带来最大的挑战。

Why are these challenges good? That has to do with the way we think about the implementation of algorithms and the idioms and patterns of implementation that apply. In particular, cross-fertilization is at the core of expertise. Idioms for problem solutions that apply in one language may not be possible in another language. Trying to port the idioms from one language to another teaches us about both languages and about the problem being solved.

为什么这些挑战很好? 这与我们思考算法的实现方式以及适用的实现方式和模式有关。 特别是,交叉施肥是专业知识的核心。 可能无法使用另一种语言来提供适用于一种语言的问题解决方案的成语。 尝试将习惯用语从一种语言移植到另一种语言,可以使我们了解两种语言以及要解决的问题。

Cross-fertilization in the use of programming languages has huge effects. Perhaps the most obvious is the increased and increasing use of declarative modes of expression in systems implemented in imperative languages. Anyone versed in functional programming can easily apply a declarative approach even when using a language such as C. Using declarative approaches generally leads to shorter and more comprehensible programs. C++, for instance, certainly takes this on board with its wholehearted support for generic programming, which almost necessitates a declarative mode of expression.

在编程语言中使用交叉施肥会产生巨大的影响。 也许最明显的是在以命令式语言实现的系统中越来越多地使用声明式表达方式。 精通函数式编程的任何人都可以轻松地使用声明性方法,即使在使用诸如C之类的语言时也是如此。使用声明性方法通常会导致程序更短,更易于理解。 例如,C ++无疑会以其对泛型编程的全力支持来支持这一点,这几乎需要一种声明式的表达方式。

The consequence of all this is that it behooves every programmer to be well skilled in programming in at least two different paradigms, and ideally at least the aforementioned five. Programmers should always be interested in learning new languages, preferably from an unfamiliar paradigm. Even if their day job always uses the same programming language, the increased sophistication of use of that language when a person can cross-fertilize from other paradigms should not be underestimated. Employers should take this into account and allow room in their training budget for employees to learn languages that are not currently being used, as a way of increasing the sophistication of the languages that are being used.

所有这一切的结果是,每个程序员都应该在至少两个不同的范例中,最好在至少上述五个范例中,熟练地进行编程。 程序员应该始终对学习新语言感兴趣,最好是从陌生的范例中学习。 即使他们的日常工作总是使用相同的编程语言,当一个人可以从其他范式中相互取长补短时,使用该语言的复杂性也不应被低估。 雇主应考虑到这一点,并在培训预算中留出空间供员工学习当前不使用的语言,以增加使用的语言的复杂性。

Although it’s a start, a one-week training course is not sufficient to learn a new language: it generally takes a good few months of use, even if part-time, to gain a proper working knowledge of a language. It is the idioms of use, not just the syntax and computational model, that are the important factors.

尽管这是一个开始,但是为期一周的培训课程不足以学习新的语言:通常,即使是兼职,也要花几个月的时间才能获得正确的语言工作知识。 重要的因素是使用习惯,而不仅仅是语法和计算模型。

学得更快。 深入挖掘。 看得更远。 (Learn faster. Dig deeper. See farther.)

Join the O’Reilly online learning platform. Get a free trial today and find answers on the fly, or master something new and useful.

加入O'Reilly在线学习平台。 立即获得免费试用版,即时找到答案,或者掌握一些新的有用的知识。

Learn more

学到更多

Dr. Russel Winder was first a theoretical high energy particle physicist and then retrained himself as a Unix systems programmer. This led to him becoming a computer science academic (University College London, then King’s College London) interested in programming; programming languages, tools, and environments; concurrency; parallelism; build; human–computer interaction; and sociotechnical systems. Having been Professor of Computing Science and head of the department of computer science at King’s College London, he left academia to dabble with start-ups as CTO or CEO. After this he was an independent consultant, analyst, author, trainer, and expert witness for a decade before retiring in 2016. He is still very interested in programming; programming languages, tools, and environments; concurrency; parallelism; and build — it keeps him active during retirement.

Russel Winder博士最初是理论上的高能粒子物理学家,然后接受了Unix系统程序员的重新培训。 这导致他成为对编程感兴趣的计算机科学学者(伦敦大学学院,然后是伦敦国王学院)。 编程语言,工具和环境; 并发 并行性 建立; 人机交互; 和社会技术系统。 他曾是伦敦国王学院计算机科学系教授和计算机科学系系主任,他离开学术界开始涉足新兴企业担任CTO或CEO。 此后,他担任独立顾问,分析家,作家,培训师和专家见证达十年之久,直到2016年退休。 编程语言,工具和环境; 并发 并行性 和成长-使他在退休期间保持活跃。

翻译自: https://medium.com/oreillymedia/know-well-more-than-two-programming-languages-65a40464c848

两种编程语言转换

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要将 Go 代码转换为 Scala 代码,并不是一件直接的事情,因为 Go 和 Scala 是两种不同的编程语言,它们有不同的语法和语义规则。但是,你可以通过手动重写 Go 代码来实现类似的功能。 以下是一些指导步骤,可以帮助你将 Go 代码转换为 Scala 代码: 1. 理解 Go 代码:首先,你需要仔细阅读和理解 Go 代码的功能和逻辑。这将帮助你在转换过程中更好地理解代码的要求和目标。 2. 熟悉 Scala 语法:了解 Scala 的语法和特性,包括函数、类、模式匹配等。这样你才能够正确地将 Go 代码转换为 Scala 代码。 3. 创建 Scala 项目:在 Scala 中创建一个新的项目,并设置好相应的构建工具和依赖项。 4. 逐行转换代码:根据 Go 代码的功能,逐行将其转换为 Scala 代码。这可能涉及到重写函数、变量和数据结构等。确保在转换过程中保持程序的逻辑正确性。 5. 调试和测试:在完成代码转换后,进行调试和测试以确保转换后的代码功能正确。 需要注意的是,由于 Go 和 Scala 是两种不同的语言,所以在转换过程中可能会遇到一些挑战和问题。某些功能可能无法直接转换,或者存在语义上的差异。因此,这个转换过程可能需要耗费一些时间和精力。 此外,还可以考虑使用其他的语言转换工具或库来辅助转换过程。例如,可以使用 ANTLR、ScalaPB 等工具来自动转换一部分代码。但是,这些工具只能提供一部分的转换结果,还需要手动进行进一步的修改和调整。 总而言之,将 Go 代码转换为 Scala 代码是一个复杂的任务,需要深入理解两种语言的特点和语法规则。希望以上的步骤能对你有所帮助。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值