什么时候新语言才是适合这项工作的工具?

发布于 2024-07-06 17:07:40 字数 1775 浏览 9 评论 0原文

很长一段时间以来,我一直在尝试不同的语言来找到我想要的功能集,但我一直找不到它。 我拥有非常适合我的各种项目的语言,但我已经想出了这些语言的交集,这将使我能够用单一语言完成 99.9% 的项目。 我想要以下内容:

  • 构建在 .NET 之上或具有 .NET 实现
  • 在编译时和运行时都很少依赖 .NET 运行时(这一点很重要,因为主要用例之一是嵌入式开发,其中 . NET 运行时完全是自定义的)
  • 具有 100% .NET 代码的编译器,没有非托管依赖项
  • 支持任意表达式嵌套(见下文)
  • 支持自定义运算符定义
  • 支持类型推断
  • 优化尾部调用
  • 具有显式不可变/可变定义(很好 - 我'我开始喜欢这个,但没有它也可以生活)
  • 支持真正的宏以进行强大的元编程(绝对必须具备)

我一直使用的主要两种语言是 Boo 和 Nemerle,但我也尝试过 F#。

对 Nemerle 的主要抱怨:编译器有可怕的错误报告,实现有很多错误(编译器和库),宏只能在函数内部或作为属性应用,而且它的依赖性相当重(尽管还不够)破坏交易)。
针对 Boo 的主要抱怨:没有任意表达式嵌套(破坏者)、宏难以编写、没有自定义运算符定义(潜在的破坏者)。
对 F# 的主要抱怨:丑陋的语法、难以理解的元编程、非免费许可证(史诗般的交易破坏者)。

所以我越想,就越想开发自己的语言。

优点:

  • 获得我想要的确切语法
  • 获得更快的周转时间; 很难量化,但看到 1.5 倍的开发人员生产力我不会感到惊讶,特别是由于测试基础设施可以为某些项目提供支持,
  • 我可以轻松地向编译器添加自定义功能,以便与我的运行时很好地配合
  • 我得到的东西是设计和工作完全按照我想要的方式 - 尽管这听起来像 NIH,但这将使我的生活更轻松

缺点:

  • 除非它能够普及,否则我将陷入维护的负担。 我知道我至少可以让内梅尔人过来,因为我认为每个人都想要更专业的东西,但这需要一个村庄。
  • 由于第一个缺点,我对在专业环境中使用它持谨慎态度。 也就是说,我已经在使用 Nemerle 并使用我自己的自定义修改编译器,因为他们根本没有很好地维护它。
  • 如果它不受欢迎,寻找开发人员将变得更加困难,Paul Graham 甚至可能不会宽恕。

基于所有这些,普遍的共识是什么——这是一个好主意还是一个坏主意? 也许更有帮助的是,我是否错过了任何重大的优点或缺点?

编辑:忘记添加嵌套示例 - 这是 Nemerle 的一个案例:

def foo = 
    if(bar == 5)
        match(baz) { | "foo" => 1 | _ => 0 }
    else bar;

编辑 #2:认为给出一个将转换为这种语言的代码类型的示例(如果存在的话)不会有什么坏处(S. Lott 的仅凭答案可能就足以让我不敢这样做)。 该代码大量使用自定义语法(操作码、:=、引用块等)、表达式嵌套等。您可以在此处查看一个很好的示例:此处

For a long time I've been trying different languages to find the feature-set I want and I've not been able to find it. I have languages that fit decently for various projects of mine, but I've come up with an intersection of these languages that will allow me to do 99.9% of my projects in a single language. I want the following:

  • Built on top of .NET or has a .NET implementation
  • Has few dependencies on the .NET runtime both at compile-time and runtime (this is important since one of the major use cases is in embedded development where the .NET runtime is completely custom)
  • Has a compiler that is 100% .NET code with no unmanaged dependencies
  • Supports arbitrary expression nesting (see below)
  • Supports custom operator definitions
  • Supports type inference
  • Optimizes tail calls
  • Has explicit immutable/mutable definitions (nicety -- I've come to love this but can live without it)
  • Supports real macros for strong metaprogramming (absolute must-have)

The primary two languages I've been working with are Boo and Nemerle, but I've also played around with F#.

Main complaints against Nemerle: The compiler has horrid error reporting, the implementation is buggy as hell (compiler and libraries), the macros can only be applied inside a function or as attributes, and it's fairly heavy dependency-wise (although not enough that it's a dealbreaker).
Main complaints against Boo: No arbitrary expression nesting (dealbreaker), macros are difficult to write, no custom operator definition (potential dealbreaker).
Main complaints against F#: Ugly syntax, hard to understand metaprogramming, non-free license (epic dealbreaker).

So the more I think about it, the more I think about developing my own language.

Pros:

  • Get the exact syntax I want
  • Get a turnaround time that will be a good deal faster; difficult to quantify, but I wouldn't be surprised to see 1.5x developer productivity, especially due to the test infrastructures this can enable for certain projects
  • I can easily add custom functionality to the compiler to play nicely with my runtime
  • I get something that is designed and works exactly the way I want -- as much as this sounds like NIH, this will make my life easier

Cons:

  • Unless it can get popularity, I will be stuck with the burden of maintenance. I know I can at least get the Nemerle people over, since I think everyone wants something more professional, but it takes a village.
  • Due to the first con, I'm wary of using it in a professional setting. That said, I'm already using Nemerle and using my own custom modified compiler since they're not maintaining it well at all.
  • If it doesn't gain popularity, finding developers will be much more difficult, to an extent that Paul Graham might not even condone.

So based on all of this, what's the general consensus -- is this a good idea or a bad idea? And perhaps more helpfully, have I missed any big pros or cons?

Edit: Forgot to add the nesting example -- here's a case in Nemerle:

def foo = 
    if(bar == 5)
        match(baz) { | "foo" => 1 | _ => 0 }
    else bar;

Edit #2: Figured it wouldn't hurt to give an example of the type of code that will be converted to this language if it's to exist (S. Lott's answer alone may be enough to scare me away from doing it). The code makes heavy use of custom syntax (opcode, :=, quoteblock, etc), expression nesting, etc. You can check a good example out here: here.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(10

杯别 2024-07-13 17:07:41

遗憾的是,没有关于失败语言的指标或故事。 只是成功的语言。 显然,失败的次数多于成功的次数。

我这样做的依据是什么? 两个共同的经历。

  1. 每年有一两次,我必须忍受对一种绝对会改变一切的产品/语言/工具/框架的推销。 我的回答在过去二十多年里一直是不变的。 向我展示需要支持的人,我的公司将为他们提供支持。 就是这样。 再也没有他们的消息了。 假设我听过其中的 25 个。

  2. 每年有一两次,我必须与拥有孤立技术的客户合作。 在过去的某个时刻,一些聪明的编程构建了一个工具/框架/库/包,在多个项目内部使用。 然后那个程序员就走了。 没有其他人能解决这个该死的问题,他们希望我们替换/重写它。 遗憾的是,我们也无法弄清楚,我们的建议是从头开始重写。 他们抱怨说,他们的天才在几周内就构建了一套应用程序,而我们不可能花几个月的时间用 Java/Python/VB/C# 重写它们。 假设我已经写了大约 25 个此类提案。

这就是我,一名顾问。

事实上,一个特别令人悲伤的情况是,一家公司的整个 IT 软件组合都是由一个聪明的人用私有语言和工具编写的。 他没有离开,但他意识到他的语言和工具集已经远远落后于时代——最先进的技术已经进步,而他却没有。

当然,此举是朝着意想不到的方向发展的。 他的语言和工具都还不错,但是世界已经开始采用关系数据库,他绝对没有办法升级他的垃圾以摆脱平面文件。 这是他没有预见到的。 确实,这是他无法预见的事情。 [你不会落入这个陷阱吧?]

于是,我们聊了聊。 他用普通的 VAX Fortran 重写了很多应用程序(是的,这是很久以前的事了。)并且他重写了它以使用普通的旧关系 SQL 东西(当时是 Ingres。)

经过一年的编码,他们遇到性能问题。 他们给我回电话,回顾他们在替换自制语言方面所做的所有伟大工作。 可悲的是,他们做了最糟糕的关系数据库设计。 最坏的可能。 他们进行了文件副本、合并、排序等操作,并使用 SQL 实现了每个低级文件系统操作,向左、向右和中心复制数据库行。

他深深地陷入了自己对完美语言的个人愿景中,以至于无法适应相对常见、普遍存在的新技术。

Sadly, there's no metrics or stories around failed languages. Just successful languages. Clearly, the failures outnumber the successes.

What do I base this on? Two common experiences.

  1. Once or twice a year, I have to endure a pitch for a product/language/tool/framework that will Absolutely Change Everything. My answer has been constant for the last 20 or so years. Show me someone who needs support and my company will support them. And that's that. Never hear from them again. Let's say I've heard 25 of these.

  2. Once or twice each year, I have to work with a customer who has orphaned technology. At some point in the past, some clever programming built a tool/framework/library/package that was used internally for several projects. Then that programmer left. No one else can figure that darn thing out, and they want us to replace/rewrite it. Sadly, we can't figure it out either, and our proposal is to rewrite from scratch. And they complain that their genius built the set of apps in a period of weeks, it can't take us months to rewrite them in Java/Python/VB/C#. Let's say I've written 25 or so of these kinds of proposals.

That's just me, one consultant.

Indeed one particularly sad situation was a company who's entire IT software portfolio was written by one clever guy with a private language and tools. He hadn't left, but he'd realized that his language and toolset had fallen way behind the times -- the state of the art had moved on, and he hadn't.

And the move was -- of course -- in an unexpected direction. His language and tools were okay, but the world had started to adopt relational databases, and he had absolutely no way to upgrade his junk to move away from flat files. It was something he had not foreseen. Indeed, it was something he could not possibly foresee. [You won't fall into this trap, will you?]

So, we talked. He rewrote a lot of the applications in Plain-Old VAX Fortran (yes, this is a long time ago.) And he rewrote it to use plain old relational SQL stuff (Ingres, at the time.)

After a year of coding, they were having performance problems. They called me back to review all the great stuff they'd done in replacing the home-built language. Sadly, they'd done the worst possible relational database design. Worst possible. They'd taken their file copies, merges, sorts, and what-not, and implemented each low-level file system operation using SQL, duplicating database rows left, right and center.

He was so mired in his private vision of the perfect language, that he couldn't adapt to a relatively common, pervasive new technology.

伤感在游骋 2024-07-13 17:07:41

我说去吧。

  • 无论是否投入生产,这都将是一次很棒的体验。
  • 如果您将其编译为 IL,那么您不必担心无法在 C# 中重用已编译的程序集。
  • 如果您认为您对上面列出的语言有有效的抱怨,那么许多人可能会认为喜欢你。 当然,每 1000 个感兴趣的人可能会有 1 个愿意帮助您维护它 - 但这始终是风险。

但这里有一些需要注意的事情:

  • 在开发之前将您的语言规范确定下来。 确保事先弄清楚所有语言功能 - 即使是您将来可能只需要的功能。 在我看来,C# 正在慢慢陷入“哦,只是多一种语言扩展”的陷阱,这将导致它最终的灭亡。
  • 一定要对其进行优化。 我不知道你已经知道了什么; 但如果你不知道,那就学习;)没有人会想要一种具有良好语法但运行速度像 IE 的 javascript 实现一样慢的语言。

祝你好运:D

I say go for it.

  • It would be an awesome experience regardless of weather it makes it to production or not.
  • If you make it compile down to IL then you do not have to worry about not being able to re-use your compiled assemblies with C#
  • If you believe that you have valid complaints about the languages you listed above, it is likely that many will think like you. Of course, for every 1000 interested person there might be 1 willing to help you maintain it - but that is always the risk

But here are a few things to be cautioned about:

  • Get your language specification IN STONE before development. Make sure any and all language features are figured out before hand - even things that you may only want in the future. In my opinion, C# is slowly falling into the "oh-just-one-more-language-extension" trap that will lead to its eventual doom.
  • Be sure to make it optimized. I dont know what you already know; but if you dont know then learn ;) Nobody will want a language that has nice syntax but runs as slow as IE's javascript implementation.

Good luck :D

握住你手 2024-07-13 17:07:41

当我在 90 年代初开始我的职业生涯时,似乎每个人都热衷于开发自己的内部语言。 我的第一份3份工作是在做过这件事的公司工作。 一家公司甚至开发了自己的操作系统!

根据经验,我认为这是一个坏主意,原因如下:

1)除了其之上的代码库之外,您还将花费时间调试语言本身
2) 您雇用的任何开发人员都需要经历该语言的学习曲线
3)很难吸引和留住开发人员,因为使用专有语言工作对于某人的职业生涯来说是一条死胡同

我离开这三份工作的主要原因是因为他们拥有专有语言,而且你会注意到没有多少公司接受这一点路线不再:)。

我要提出的另一个论点是,大多数语言都有整个团队,其全职工作就是开发该语言。 也许你会是一个例外,但如果你仅通过兼职学习该语言就能达到这种发展水平,我会感到非常惊讶。

When I first started my career in the early 90s, there seemed to be this craze of everyone developing their own in-house languages. My first 3 jobs were with companies that had done this. One company had even developed their own operating system!

From experience, I'd say this is a bad idea for the following reasons:

1) You will spend time debugging the language itself in addition to the code base on top of it
2) Any developers you hire will need to go through the learning curve of the language
3) It will be hard to attract and keep developers since working in a proprietary language is a dead-end for someone's career

The main reason I left those three jobs was because they had proprietary languages and you'll notice that not many companies take this route any more :).

An additional argument I'd make is that most languages have entire teams whose full time job it is to develop the language. Maybe you'd be an exception, but I'd be very surprised if you'd be able to match that level of development by only working on the language part-time.

中二柚 2024-07-13 17:07:41

针对 Nemerle 的主要投诉:
编译器有可怕的错误报告,
实现是有问题的
(编译器和库),宏
只能在函数内部应用
或者作为属性,而且它相当
严重依赖(虽然不是
足以破坏交易)。

我看到你的帖子是两年多前写的。
我建议您今天尝试一下 Nemerle 语言。
编译器稳定。 今天没有阻止程序错误。
VS集成有很多改进,还有SharpDevelop集成。

如果你给它一个机会,你不会失望的。

Main complaints against Nemerle: The
compiler has horrid error reporting,
the implementation is buggy as hell
(compiler and libraries), the macros
can only be applied inside a function
or as attributes, and it's fairly
heavy dependency-wise (although not
enough that it's a dealbreaker).

I see your post has been written more than two years ago.
I advise you trying Nemerle language today.
The compiler is stable. There are no blocker bugs for today.
The VS integration has a lot of improvements , also there is SharpDevelop integration.

If you give it a chance, you won't be disappointed.

水晶透心 2024-07-13 17:07:41

永远不要开发自己的语言。

开发自己的语言是一个傻瓜陷阱,更糟糕的是,它会限制您的想象力,并要求您弄清楚您的开发环境和您正在编写的实际程序。

如果您是 Larry Wall、AWK 人员,或者是致力于测试编程边界的大量人员中的一员,则这种情况几乎不适用。 如果您属于这些类别中的任何一个,则不需要我的建议,但我强烈怀疑您所针对的利基市场没有适合该任务的编程语言以及执行该任务的人员的特征。

NEVER EVER develop your own language.

Developing your own language is a fool's trap, and worse it will limit you to what your imagination can provide, as well demanding that you work out both your development environment and the actual programme you're writing.

The cases in which this doesn't apply are pretty much if you're Larry Wall, the AWK guys, or part of a substantial group of people dedicated to testing the boundaries of programming. If you're in any of those categories, you don't need my advice, but I strongly doubt that you're targeting a niche where there is no suitable programming language for the task AND the characteristics of the people doing the task.

温柔嚣张 2024-07-13 17:07:41

如果你像你看起来一样聪明(有可能),我的建议是先进行语言的设计,迭代几次,询问一些你信任的智能编程语言相关的聪明人社区讨论您提出的具体设计,然后做出决定。

例如,您可能会在创建设计的过程中意识到,只需对 Nemerle 进行快速修改即可满足您所需的一切。 当你认真思考一个问题时,很多事情可能会发生,而最终的解决方案可能并不是你开始项目时真正想到的。

最坏的情况是,您将不得不实际实施设计,但到那时您将对其进行校对并使其成熟,并且您将高度确定地知道这是一条不错的道路。

一条相关的建议是,从小事做起,只需定义您绝对需要的功能,然后在它们的基础上进行构建以获得其余功能。

If you are as clever as you seem to be (a likely possibility), my advice is to go ahead and do the design of the language first, iterate a couple of times over it, ask some smart fellows you trust in smart programming language related communities about the concrete design you came up with and then take the decision.

You might realize in the process of creating the design that just a quick hack on Nemerle would give it all you need, for example. Many things can happen just when thinking hard about a problem, and the final solution might not be what you actually had in mind when beginning the project.

Worst case scenario, you're stuck with actually implementing the design, but by then you will have it proof read and mature, and you'll know with a high degree of certainty that it was a good path to take.

A related piece of advice, start small, just define the features you absolutely need and then build on them to get the rest.

ゃ懵逼小萝莉 2024-07-13 17:07:41

编写自己的语言不是一个容易的项目。尤其是要在任何一种“专业环境”中使用的语言,

这是一项巨大的工作量,我怀疑您是否可以编写自己的语言,并且仍然编写任何使用它的大型项目 - 您将花费很长时间添加所需的功能、修复错误和一般语言设计内容。

强烈建议选择一种最接近您想要的语言,并将其扩展以满足您的需要。 它永远不会完全是你想要的,但与你花在编写自己的语言上的时间相比,我想说这是一个小小的妥协。

Writing your own language is not a easy project.. Especially one to be used in any kind of "professional setting"

It is a huge amount of work, and I would doubt you could write your own language, and still write any big projects that use it - you will spend so long adding features that you need, fixing bugs, and general language-design stuff.

I would strongly recommend choosing a language that is closest to what you want, and extending it to do what you need. It'll never be exactly what you want, but compared to the time you'll spend writing your own language, I would say that's a small compromise..

も让我眼熟你 2024-07-13 17:07:41

Scala 有一个 .NET 编译器。 虽然我不知道这个的状态。 它有点像 Scala 世界中的二等公民(Scala 世界更关注 JVM)。 但采用 .NET 编译器而不是从头开始创建新语言可能是一个不错的权衡。

Scala 在元编程部门 ATM 方面有点弱。 其他语言功能可能会在一定程度上减少对元编程的需求。 无论如何,如果您要为其实现元编程功能,我认为没有人会感到难过。 此外,还有一个编译器插件基础设施正在开发中。

Scala has a .NET compiler. I don't know the status of this though. It's kind of a second class citizen in the Scala world (which is more focused on the JVM). But it might be a good tradeof to adopt the .NET compiler instead of creating a new language from scratch.

Scala is kind of weak in the meta-programming department ATM. It's possible that the need for metaprogramming is somewhat reduced by other language features. In any case I don't think anyone would be sad if you were to implement metaprogramming features for it. Also there is a compiler plug-in infrastructure on the way.

天煞孤星 2024-07-13 17:07:41

我认为大多数语言永远无法满足所有要求。

您可能想要结合您最喜欢的 2 种语言(在我的例子中是 C# 和 Scheme)并一起使用它们。

从专业角度来看,这可能不是一个好主意。

I think most languages will never fit all of the bill.

You might want to combine your 2 favourite languages (in my case C# and Scheme) and use them together.

From a professional point of view, this probably not a good idea though.

如何视而不见 2024-07-13 17:07:41

听到一些您认为现有语言无法做到的事情会很有趣。 您正在进行哪些无法用 C# 完成的项目?

我只是好奇而已!

It would be interesting to hear some of the things you feel you can't do in existing languages. What kind of projects are you working on that can't be done in C#?

I'm just curios!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文