简体   繁体   English

扩展编程语言如何工作?

[英]How does extending a programming language work?

I have no programming experience but am interested in learning a language. 我没有编程经验,但是对学习语言感兴趣。

So reading this section " http://wiki.freaks-unidos.net/weblogs/azul/principles-of-software#extend-your-language-to-match-your-domain " made me curious about programming a single application in 2 or more languages. 因此,阅读本节“ http://wiki.freaks-unidos.net/weblogs/azul/principles-of-software#extend-your-language-to-match-your-domain ”使我对在其中编写单个应用程序感到好奇2种以上的语言。

How is it actually done? 实际如何完成?

A few thoughts: 一些想法:

  • The page you linked to explains pretty clearly how it's done 您链接到的页面非常清楚地说明了如何完成
  • If you are interested in learning a language, this is probably not the place to start 如果您对学习语言感兴趣,那么可能不是开始的地方
  • Programing a single application in two or more languages is only marginally related to the linked document. 用两种或更多种语言编写单个应用程序仅与链接文档有一点关系。

Still, in the face of all that, I'll try to give an example of how this works by analogy. 尽管如此,面对所有这些,我将通过类比尝试给出一个示例。

Suppose you need to work with a group of people on some technical task--ranking chess puzzles by difficulty or testing marshmallows for contamination or something. 假设您需要与一群人一起完成某些技术任务-按难度对象棋谜题进行排序或测试棉花糖中的污染物或其他物质。 Suppose further that one of the people on your team speaks only Japanese, another only Portuguese, and the third only Esperanto. 进一步假设您团队中的一个人只会说日语,另一个会说葡萄牙语,而第三个只会说世界语。

Being blessed with the ability to speak all of these languages fluently, your best bet is to make up an artificial language specialized to the task at hand; 拥有能够流利地说所有这些语言的能力,您最好的选择是构造一种专门用于即将完成的任务的人工语言。 this is called a Domain Specific Language, or DSL. 这称为领域特定语言或DSL。 It should have all the terminology you need to talk about knights and rooks or silicate nanoparticles or whatever for the task, and not much else. 它应该具有您需要谈论的所有术语,例如骑士,白嘴鸦或硅酸盐纳米粒子或用于任务的其他任何东西,而没有其他内容。 Teach this to each of your team members, and then you can give them all their instructions at the same time. 向每个团队成员进行讲授,然后您可以同时向他们提供所有指示。 They can talk to each other about what they are doing, ask for help (so long as it's related to something covered by your language) as if they all spoke the same language. 他们可以互相谈论自己在做什么,寻求帮助(只要这与您的语言所涵盖的内容有关),就好像他们都讲相同的语言一样。

That's roughly what he's talking about. 那大概就是他在说什么。

I think you may be trying to run before you can walk. 我认为您可能会尝试跑步才能走路。 The concepts in there probably require a little programming experience to start with. 首先,这里的概念可能需要一点编程经验。

The thrust of the article (and frankly poorly expressed) is that when you are programming you often encounter tasks that benefit from a declarative syntax, ie you should be able to express the intent of what you want to do and leave the implementation details to a library. 本文的主旨(坦率地说,表现不佳)是,在进行编程时,您经常会遇到受益于声明性语法的任务,即,您应该能够表达您想要做什么的意图,并将实现细节留给图书馆。 A good example is querying a database, it's much more readable (usually) to be able to declaratively describe what you want to do and let some middleware figure out the best way to do it, SQL and Linq are 2 examples of a declarative mechanism for querying data. 一个很好的例子是查询数据库,它(通常)更具可读性(能够以声明的方式描述您想要做的事情,并让一些中间件找出实现此操作的最佳方法),SQL和Linq是声明式机制的两个示例。查询数据。

This is a very interesting topic, but honestly if you have no programming experience it's probably more of a 201 subject than a 101 subject, get your basics down first. 这是一个非常有趣的话题,但是老实说,如果您没有编程经验,那么它可能更多是201而不是101的主题,请首先掌握基础知识。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM