有了 Lua 和 Python 的可嵌入性,Basic 还有一席之地吗?

发布于 2024-07-08 04:58:19 字数 889 浏览 11 评论 0原文

我开始在 ZX81 上进行 Basic 编程,然后 BASICA, GW-BASICQBasic。 我转向 C(啊,Turbo C 3.1,我几乎不知道...)

当我开始使用微控制器时,我回归了 BASIC Stamp。 然而,BASIC 非常棒,因为它很容易理解,而且很难犯错误。 我最终转向汇编和 C,因为我需要额外的能力(速度、容量、资源等),但我知道,如果门槛高得多,很多人将永远不会进入微控制器编程。

我一直渴望制作自己的片上 BASIC 解释器,但我想知道现在是否需要 BASIC,因为 Lua 和 Python 很容易嵌入,并且与 BASIC 一样易于使用。

  • BASIC 相对于其他语言有哪些优势(如果有的话)?
  • 为什么它还存在?
  • 如果我决定制作带有解释器的通用微控制器板,是否有理由制作 BASIC 版本?

许多其他语言都被认为已经消亡,但 BASIC 却继续存在。

I started off programming in Basic on the ZX81, then BASICA, GW-BASIC, and QBasic. I moved on to C (Ah, Turbo C 3.1, I hardly knew ye...)

When I got started in microcontrollers I regressed with the BASIC Stamp from Parallax. However, BASIC is/was awesome because it was so easy to understand and so hard to make a mistake. I moved on to assembly and C eventually because I needed the additional power (speed, capacity, resources, etc.), but I know that if the bar was much higher many people would never get into programming microcontrollers.

I keep getting an itch to make my own on-chip BASIC interpretor, but I wonder if there's need for BASIC now that Lua and Python are easily embeddable, and just as approachable as BASIC.

  • What, if any, are the advantages BASIC has over other languages?
  • Why is it still around?
  • If I decide to make a general purpose microcontroller board with an interpreter, is there any reason to make a version of BASIC?

Plenty of other languages are considered dead, but BASIC just keeps hanging on.

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

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

发布评论

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

评论(9

小霸王臭丫头 2024-07-15 04:58:19

[这听起来可能比实际情况更消极。 我并不是说 Basic 是万恶之源,其他人也这么说过。 我是说这是我们可以留下的遗产。]

“因为它很容易理解,而且很难犯错误” 这当然是值得商榷的。 我在完全不透明的基础上有过一些糟糕的经历。 专业的东西——商业产品——非常糟糕的代码。 不得不放弃并拒绝这项工作。

“Basic 相对于其他语言有什么优势(如果有的话)?” 真的没有。

“为什么它仍然存在?” 两个原因:(1) Microsoft,(2) 所有开始使用 VB 的 IT 部门现在拥有数百万行 VB 遗留代码。

“许多其他语言被认为已经消亡......” 是的。 Basic 与 COBOL、PL/I 和 RPG 一起作为遗产,有时成本高于价值。 但由于大型 IT 的“如果没有坏就不要修理”的政策,他们坐在那里,吸收资源,而这些资源可以轻松地用更小、更简单、维护成本更低的东西来取代它。 但它并没有“失败”——只是成本过高。

30 年前的 COBOL 返工的情况非常糟糕。 从 2016 年开始,我们将关注已有 30 年历史的 MS Basic,我们只是无法弄清楚,不想没有它,也无法决定如何更换。

“但 Basic 一直坚持下去” 看来有些人喜欢 Basic。 其他人则认为它是另一种设计糟糕的语言。 它的优势在于早进入市场并得到大型供应商(最初是IBM)的支持。 糟糕的设计、过早的上市只会给我们留下几十年来难以承受的遗产。

我还保留着 1965 年版的达特茅斯基础手册。 我并不渴望过去的美好时光。

[This may come off sounding more negative than it really is. I'm not saying Basic is the root of all evil, others have said that. I'm saying it's a legacy we can afford to leave behind.]

"because it was so easy to understand and so hard to make a mistake" That's certainly debatable. I've had some bad experiences with utterly opaque basic. Professional stuff -- commercial products -- perfectly awful code. Had to give up and decline the work.

"What, if any, are the advantages Basic has over other languages?" None, really.

"Why is it still around?" Two reasons: (1) Microsoft, (2) all the IT departments that started doing VB and now have millions of lines of VB legacy code.

"Plenty of other languages are considered dead..." Yep. Basic is there along side COBOL, PL/I and RPG as legacies that sometimes have more cost than value. But because of the "if it ain't broke don't fix it" policy of big IT, there they sit, sucking up resources who could easily replace it with something smaller, simpler and cheaper to maintain. Except it hasn't "failed" -- it's just disproportionately expensive.

30-year old COBOL is a horrible situation to rework. Starting in 2016 we'll be looking at 30-year old MS Basic that we just can't figure out, don't want to live without, and can't decide how to replace.

"but basic just keeps hanging on" It appears that some folks love Basic. Others see it as yet another poorly-designed language; it's advantages are being early to market and being backed by huge vendors (IBM, initially). Poorly-design, early-to-market only leaves us with a legacy that we'll be suffering with for decades.

I still have my 1965-edition Dartmouth Basic manual. I don't long for the good old days.

半仙 2024-07-15 04:58:19

作为一种架构,BASIC 的主要优点在于您可以将 BASIC 解释器做得非常小——只有几 KB。 在 DG Nova 时代,这是一个胜利,因为您可以使用 Business BASIC 等系统在具有 64K RAM(甚至更少)的计算机上构建多用户应用程序。

BASIC(尤其是 VB)是一个遗留系统,拥有大量现有代码库。 可以说,VB 实际上是一种具有类似 BASIC 语法的语言(有些人会说是 COM 的薄包装器)。 如今,除了人们对它的熟悉程度以及维护现有的代码库之外,我认为没有什么理由保留该语言。 我当然不会提倡对其进行新的开发(请注意,VB.Net 并不是真正的 BASIC,而只是具有类似 VB 的语法。类型系统并没有像 VB 那样被破坏。)

是什么 计算世界缺少一种相关语言,它易于学习和修改,并且在主流应用程序开发中占有一席之地。 我是在 8 位机器时代长大的,在这些系统上编程的入门门槛非常低。 机器的架构非常简单,你可以很容易地在这些机器上学习编程和编写或多或少相关的应用程序。

现代架构要复杂得多,需要学习的难度也更大。 你可以看到人们武断地认为孩子们无法像 BASIC 和 8 位计算机时代那样轻松地学习编程,我认为这种论点有一定的道理。 留下了一些漏洞,使得编程变得更加困难。 玩具语言在这里没有多大用处——为了使编程有吸引力,必须能够渴望构建与你正在学习的语言相关的东西。

这导致了一个问题:一种语言对于孩子来说很容易学习,但仍然允许他们编写他们可能真正想要的相关程序(甚至游戏)。 它还必须被广泛认为是相关的。

我能想到的最接近这个的是Python。 它不是该类型语言的唯一示例,但它是最受关注的语言 - 并且(在我看来)要在这个利基市场中发挥作用,相关性的感知是必要的。 它也是我所经历过的最容易学习的语言之一(在我多年来使用过的 30 种左右语言中)。

As an architecture, the main claim to fame of BASIC is that you could make BASIC interpreters very small - just a few KB. In the days of a DG Nova this was a win as you could use systems like Business BASIC to build a multiuser application on a machine with 64K of RAM (or even less).

BASIC (VB in particular) is a legacy system and has a large existing code-base. Arguably VB is really a language (some would say a thin wrapper over COM) that has a BASIC-like syntax. These days, I see little reason to keep the language around apart from people's familiarity with it and to maintain the existing code base. I certainly would not advocate new development in it (note that VB.Net is not really BASIC but just has a VB-like syntax. The type system is not broken in the way that VB's was.)

What is missing from the computing world is a relevant language that is easy to learn and tinker with and has mind-share in mainstream application development. I grew up in the days of 8-bit machines, and the entry barrier to programming on those systems was very low. The architecture of the machines was very simple, and you could learn to program and write more-or-less relevant applications on these machines very easily.

Modern architectures are much more complex and have a bigger hump to learn. You can see people pontificating on how kids can't learn to program as easily as they could back in the days of BASIC and 8-bit computers and I think that argument has some merit. There is something of a hole left that makes programming just that bit harder to get into. Toy languages are not much use here - for programming to be attractive it has to be possible to aspire to build something relevant with the language you are learning.

This leads to the problem of a language that is easy for kids to learn but still allows them to write relevant programmes (or even games) that they might actually want. It also has to be widely perceived as relevant.

The closest thing I can think of to this is Python. It's not the only example of a language of that type, but it is the one with the most mind-share - and (IMO) a perception of relevance is necessary to play in this niche. It's also one of the easiest languages to learn that I've experienced (of the 30 or so that I've used over the years).

虫児飞 2024-07-15 04:58:19

为什么不尝试一下 Jumentum,看看它对您有何作用?

http://jumentum.sourceforge.net/

它是 microcontrollers 的开源 BASIC

elua 项目也是 lua对于微控制器

http://elua.berlios.de/

Why not give Jumentum a try and see how it works for you?

http://jumentum.sourceforge.net/

it's an open source BASIC for micrcontrollers

The elua project is also lua for microcontrollers

http://elua.berlios.de/

土豪我们做朋友吧 2024-07-15 04:58:19

BASIC 仍然存在,特别是在 STAMP 实现中,因为它比大多数其他非常容易学习的编程语言级别要低。 对于大多数嵌入式 BASIC 实现,BASIC 指令直接映射到单个或一组机器指令,开销非常小。 用 Lua 或 Python 等“高级”语言编写的相同程序在相同的微控制器上运行速度会慢得多。

PS:尽管命名相似,但像 PBASIC 这样的 BASIC 变体与 Visual BASIC 等几乎没有共同之处。 他们的分歧方式截然不同。

BASIC persists, particularly in the STAMP implementation, because it is lower level than most other very-easy-to-learn programming languages. For most embedded BASIC implementations the BASIC instructions map directly to single or groups of machine instructions, with very little overhead. The same programs written in "higher level" languages like Lua or Python would run far slower on those same microcontrollers.

PS: BASIC variants like PBASIC have very little in common with, say, Visual BASIC, despite the naming similarity. They have diverged in very different ways.

べ映画 2024-07-15 04:58:19

好问题......

基本上(原文如此!),我没有答案。 我只想说 Lua 非常容易学习,可能和 Basic 一样简单(这也是我的第一个语言,我在很多 8 位计算机上使用方言......),但更强大(允许面向对象)或功能风格,甚至混合它们)并且在某种程度上更严格(没有 goto...)。

我不太了解Python,但从我所读到的来看,它比Lua一样简单、强大和严格。

此外,两者实际上都是“标准化”的,即。 没有方言(除了各种版本之外),这与有许多变体的 Basic 不同。

而且两者都有精心设计的虚拟机,高效,(大部分)无错误。 如果您创建自己的解释器,您应该使用现有的 VM 并从 Basic 源为其生成字节码,或者创建您自己的解释器。 当然有趣的东西,但耗时且容易出现错误...

所以,我只想让 Basic 过上愉快的退休生活... :-P

PS.: 为什么它挂在一边? 也许微软对此并不陌生...(VB、VBA、VBScript...)
还有很多方言(RealBasic、DarkBasic 等),有一些受众。

Good question...

Basically (sic!), I have no answer. I would say just that Lua is very easy to learn, probably as easy as Basic (which was one of my first languages as well, I used dialects on lot of 8-bit computers...), but is more powerful (allowing OO or functional styles and even mixing them) and somehow stricter (no goto...).

I don't know well Python, but from what I have read, it is as easy, powerful and strict than Lua.

Beside, both are "standardized" de facto, ie. there are no dialects (beside the various versions), unlike Basic which has many variants.

Also both have carefully crafted VM, efficient, (mostly) bugless. Should you make your own interpretor, you should either take an existing VM and generate bytecode for it from Basic source, or make your own. Sure fun stuff, but time consuming and prone to bugs...

So, I would just let Basic have a nice retirement... :-P

PS.: Why it is hanging on? Perhaps Microsoft isn't foreign to that... (VB, VBA, VBScript...)
There are also lot of dialects around (RealBasic, DarkBasic, etc.), with some audience.

最单纯的乌龟 2024-07-15 04:58:19

冒着听起来像两个坐在摇椅上的老前辈的风险,让我脾气暴躁地说“现在的孩子不欣赏 BASIC”,然后自相矛盾地说“他们不知道自己有多好。”

BASIC 的最大优势始终是它的可理解性。 这是人们可以获得的东西。 长期以来,这一点被学者和语言开发者所忽视。

当您谈论想要实现 BASIC 时,我假设您不是在谈论行编号的 BASIC,而是一种结构化形式。 问题是,一旦你开始进入结构化编程——函数,“为什么我不能直接转到那个地方?”等等——它的优点真的变得不清楚,如果有的话,BASIC 将会超过 Python。

此外,BASIC“如此容易正确使用”的原因之一是,在那些日子里,图书馆并不像今天那么重要。 库意味着结构化(如果不是面向对象的编程),因此您再次处于一种更现代的动态脚本语言“更适合”人们今天所做的事情的现实的情况。

如果真正的问题是“好吧,我想实现一个解释器,因此这取决于投资回报”,那么它就变成了一个实际上很容易实现的语法问题。 我认为 BASIC 在这方面也没有那么多优势(除非您真的确实返回行号和非常有限的语法)。

简而言之,我认为您不应该将精力投入到 BASIC 解释器上。

At the risk of sounding like two old-timers on rocking chairs, let me grumpily say that "Kids today don't appreciate BASIC" and then paradoxically say "They don't know how good they've got it."

BASICs greatest strength was always its comprehensibility. It was something that people could get. That was long ignored by academics and language developers.

When you talk about wanting to implement BASIC, I assume you're not talking about line-numbered BASIC, but a structured form. The problem with that is that as soon as you start moving into structured programming -- functions, 'why can't I just GOTO that spot?', etc. -- it really becomes unclear what advantages, if any, BASIC would have over, say, Python.

Additionally, one reason BASIC was "so easy to get right" was that in those days libraries weren't nearly as important as they are today. Libraries imply structured if not object-oriented programming, so again you're in a situation where a more modern dynamic scripting language "fits" the reality of what people do today better.

If the real question is "well, I want to implement an interpreter and so it comes down to return on investment," then it becomes a problem of an grammar that's actually easy to implement. I'd suggest that BASIC doesn't really have that many advantages in that regard either (unless you really do return to line numbers and a very limited grammar).

In short, I don't think you should invest your effort in a BASIC interpreter.

随梦而飞# 2024-07-15 04:58:19

好吧,这些人似乎认为 basic 不仅在移动领域仍然占有一席之地,而且还可以从中赚钱:

http://www.nsbasic.com/symbian/

Well, these people seem to think that not only basic still has a place in the mobile space but also that they can make money off it:

http://www.nsbasic.com/symbian/

如日中天 2024-07-15 04:58:19

我也开始使用ZX81。 但正如 Tony Hoare 所说,用 BASIC 编程就像尝试做使用罗马数字进行长除法。

还有很多其他语言
被认为已经死了,但基本的只是保留
坚持下去。

可悲的是,是的。 我把这件事归咎于比尔·盖茨……BASIC 躺在担架上,牧师为它做最后的仪式,然后 MS 像天花一样把它带了回来。

I started out on a ZX81 too. But as Tony Hoare said, programming in BASIC is like trying to do long division using roman numerals.

Plenty of other languages are
considered dead, but basic just keeps
hanging on.

Sadly yes. I blame Bill Gates for this...BASIC was on a stretcher with a priest saying the last rites for it, and then MS brought it back like Smallpox.

唠甜嗑 2024-07-15 04:58:19

在 QBasic 时代,我曾经使用 BASIC 进行编程。 QBASIC 有子例程、函数、结构(它们过去被称为类型),我想就是这样。 现在,与 Python 拥有的所有功能相比,这似乎很有限——OO、lambda、元类、生成器、列表推导式,仅举几个我脑海中浮现的功能。 但我认为这种简单性正是 BASIC 的优势。 如果您正在寻找一种简单的嵌入式语言,我敢打赌 QBasic 会更快、更容易理解。 对于大多数嵌入/脚本类型的应用程序来说,程序语言可能绰绰有余。

我想说 BASIC 仍然存在的最重要原因是 Visual Basic。 在 90 年代的很长一段时间里,VB 是为 Windows 编写 GUI、COM 和 DB 代码而不会落入 C++ Turing tarpits 的唯一方法。 [也许Delphi也是一个不错的选择,但不幸的是它从未像VB那样流行]。 我确实认为正是因为所有这些 VB 和 VBA 代码仍在使用和维护,BASIC 仍未消亡。

也就是说,我想说今天为 BASIC 编写 BASIC 解释器(甚至可能是使用 LLVM 或类似的东西的编译器)是有很好的理由的。 如果您实现类似于 QBasic 的东西,您将获得一种干净、简单、易于使用且快速的语言。 您不必解决任何语言设计问题,最好的部分是人们已经了解您的语言。

I used to program in BASIC in the QBasic days. QBASIC had subroutines, functions, structures (they used to be called types), and I guess that's it. Now, this seems limited compared to all the features that Python has - OO, lambdas, metaclasses, generators, list comprehensions, just to name a few off the top of my head. But that simplicity, I think, is a strength of BASIC. If you're looking at a simple embeddable language, I'd bet that QBasic will be faster and easier to understand. And a procedural langauge is probably more than sufficient for most embedding/scripting type of applications.

I'd say the most important reason BASIC is still around is Visual Basic. For a long time in the 90s, VB was the only way to write GUIs, COM and DB code for Windows without falling into one of the C++ Turing tarpits. [Maybe Delphi was a good option too, but unfortunately it never became as popular as VB]. I do think it is because of all this VB and VBA code that is still being used and maintained that BASIC still isn't dead.

That said, I'd say there's pretty a good rationale to write BASIC interpreter (maybe even compiler using LLVM or something similar) for BASIC today. You'll get a clean, simple easy to use and fast language if you implement something that resembles QBasic. You won't have to solve any language design issues and the best part is people will already know your language.

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