问题起因:
在github的chisel训练营里的第三模块2.1_first_module有一句
Chisel stands for Constructing Hardware In a Scala Embedded Language. That means it is a DSL in Scala, allowing you to take advantage of both Scala and Chisel programming within the same code means it is a DSL in Scala
STACKFLOW里面回答:
在需要将系统控制的某些方面交给其他人的情况下,DSL很有用。(DSL’s are good in situations where you need to give some aspect of the system’s control over to someone else. )
I’ve used them in Rules Engines, where you create a simple language that is easier for less-technical folks to use to express themselves- particularly in workflows.In other words, instead of making them learn java:
DocumentDAO myDocumentDAO = ServiceLocator.getDocumentDAO();
for (int id : documentIDS) {
Document myDoc = MyDocumentDAO.loadDoc(id);
if (myDoc.getDocumentStatus().equals(DocumentStatus.UNREAD)) {
ReminderService.sendUnreadReminder(myDoc)
}
I can write a DSL that lets me say:
for (document : documents) {
if (document is unread) {
document.sendReminder
}
There are other situations, but basically, anywhere you might want to use a macro language(宏语言), script a workflow, or allow after-market customization(售后定制)- these are all candidates for DSL’s.