D language as a basis for a Basic

General discussion for topics related to the FreeBASIC project or its community.
sean_vn
Posts: 283
Joined: Aug 06, 2012 8:26

D language as a basis for a Basic

Post by sean_vn »

Some of the D language is really badly though out. Like array views being total incompatible increasing array length. And some of it is overly complex or simply too much. However guy who designed it probably has an IQ of 150.
Nevertheless a subset of the D language seems like it would map to a Basic very well. Maybe there is only a fairly simple set of text transformations needed. Also you would have to use some sort of graphics library as well.

I can't use FreeBasic so easily now, it is getting a bit out of date. On the latest version of Linux I have the FB graphics are broken.
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: D language as a basis for a Basic

Post by D.J.Peters »

sean_vn wrote:I can't use FreeBasic so easily now, it is getting a bit out of date.
On the latest version of Linux I have the FB graphics are broken.
I have no problems with FreeBASIC on different Linux boxes.

What is the problem, can you describe it with more details ?

Joshy
caseih
Posts: 2157
Joined: Feb 26, 2007 5:32

Re: D language as a basis for a Basic

Post by caseih »

sean_vn wrote:Some of the D language is really badly though out. Like array views being total incompatible increasing array length. And some of it is overly complex or simply too much. However guy who designed it probably has an IQ of 150.
Nevertheless a subset of the D language seems like it would map to a Basic very well. Maybe there is only a fairly simple set of text transformations needed. Also you would have to use some sort of graphics library as well.
I'm not understanding what you mean about D's arrays. I took a quick look at the D language docs and it's arrays seem rather normal to me, with the powerful addition of slicing. From what little I know of D, having followed it a bit over the years, D seems rather well-though out to me. I'm not sure it will ever replace C++, as C++ is so mature and entrenched. I dunno.
I can't use FreeBasic so easily now, it is getting a bit out of date. On the latest version of Linux I have the FB graphics are broken.
Like Joshy says, what version of Linux? I had thought FB uses SDL, but actually I think it uses X directly. So as long as you have xcb libraries installed, and if you're using Wayland, if you have the X server compatibility thing working, it should work. Linux is moving away from X.org, so some time FB's runtime will need to support Wayland. But in the meantime, and for the foreseeable future, X apps should continue to run under Wayland desktops.
sean_vn
Posts: 283
Joined: Aug 06, 2012 8:26

Re: D language as a basis for a Basic

Post by sean_vn »

The problem with FB on Xenial Linux is that the graphics are always displayed in full screen mode.
The problem with array slices in D is they become invalid if you increase the length of the underlying array in a very messy way.
I think you can map everything in FB to D in a straight forward way, including assembly language facilities.
I'm definitely not interested in writing a full parser to map a Basic language to D, however if there is a set of simple text transformations that will work instead I might even try that.
caseih
Posts: 2157
Joined: Feb 26, 2007 5:32

Re: D language as a basis for a Basic

Post by caseih »

Do you mean Ubuntu 16.04?

If I understand you correctly, yes that's completely understandable and expected behaviour on D's part, much like how an iterator becomes invalid when the underlying list is changed. I'm sure in both instances the language could dynamically regenerate the view or iterator every time you accessed it, but that would be fantastically slow, especially in a looping situation. Sorry, but in this case, D does the right thing. Coming from FB, which doesn't have slicing or view, I'm a little uncertain why you find this feature problematic. If you liked everything else about D, couldn't you just not use array slicing?
TeeEmCee
Posts: 375
Joined: Jul 22, 2006 0:54
Location: Auckland

Re: D language as a basis for a Basic

Post by TeeEmCee »

D's slices seem nicer than C++'s pairs of iterators. I didn't get very far with learning D, but it definitely seems to be a big improvement over C++98. Not sure how it's evolved since.
caseih wrote:I had thought FB uses SDL, but actually I think it uses X directly.
Right, it uses X directly, and doesn't use SDL at all, except for the emscripten and OSX ports of fbgfx, which use (emscripten's emulation of) SDL 1.2 and SDL 2 respectively. Neither of which has been merged.
sean_vn wrote:I'm definitely not interested in writing a full parser to map a Basic language to D, however if there is a set of simple text transformations that will work instead I might even try that.
I had the same idea, for FB to C++ translation. I wrote a PEG-based translator, but only got it half finished. Turns out that you really can translate a very large part of FB directly to C++ using a very simple PEG parser (which is basically a regexp matcher) which directly outputs the replacement text, but it's inevitable that you need to do much more to correctly translate expressions 100% of the time: to do that you need to know the type of each variable, so you have to parse all variable and argument declarations, and also type declarations, the return types of functions, and if you're parsing instead of doing direct replacements you also need to implement the preprocessor...
(If I had time, I'd still like to finish that translator, for fun)
caseih
Posts: 2157
Joined: Feb 26, 2007 5:32

Re: D language as a basis for a Basic

Post by caseih »

D seems to have remained a niche language, despite it's continued development and nice features. In the meantime C++ seems to have started to move again, and recent versions support a lot of nice features, including automatic variable typing, lambda expressions, and new types of smart pointers. I think C++'s resurgence has kind of damped D's growth. And in the meantime other languages that promote security and safety, such as Rust, have gained traction.

The problem with automatic translation into other languages like C++ is that idioms of the target language end up bleeding through into development process. Even FB's current close relationship with C can lead to programming in C style with FB syntax. Not that that's a bad thing necessarily. It's just that at a certain point, why not just C or C++ (or D)?
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: D language as a basis for a Basic

Post by MrSwiss »

caseih wrote:... why not just C or C++ ?
Maybe because:
- we like FB syntax (and, can't/won't cope, with C/C++ syntax)
- we might dislike curly braces
- we might dislike 'endless' break statements (in switch)
- we might dislike semi-colons (at every line end)
...
lizard
Posts: 440
Joined: Oct 17, 2017 11:35
Location: Germany

Re: D language as a basis for a Basic

Post by lizard »

What is the advantage to have hundreds of programming languages all similar like C++ or D? Who wants D can use it. BASIC should stay BASIC. Like it once was (from my viewpoint, i started with CBM BASIC V 3.5). Yes, there can be enhancements, but they should match the original style. Otherwise we end with hundreds of C++ clones.
caseih
Posts: 2157
Joined: Feb 26, 2007 5:32

Re: D language as a basis for a Basic

Post by caseih »

I agree, for the most part. Although trying to identify what is BASIC style is a bit challenging to pin down.

Definitely I don't understand the obsession with braces and semi-colons. I guess the only thing going for braces is that it's easy to type and multi-purpose. Pascal's BEGIN...END blocks drove me nuts. Besides all the extra typing, I was never quite sure how to format them. FB's multiple END statements is okay, since you don't have to specify BEGIN all the time. Oddly enough, Python's white-space syntax feels super natural to me.

As for semicolons, a lot of languages these days with C-inspired syntax make the semicolon optional, and use it much like FB uses the colon. In this instance, I prefer semicolons to colons as from a natural language point of view a colon implies that what follows is related; whereas a semicolon indicates a new though.
lizard
Posts: 440
Joined: Oct 17, 2017 11:35
Location: Germany

Re: D language as a basis for a Basic

Post by lizard »

caseih wrote:Definitely I don't understand the obsession with braces and semi-colons.
That was a idea from Kernighan and Rtchie and since then nobody changed it. I programmed a while in C, but never really liked the syntax.

Funny to think the first languange i came in contact was already the best. Like somet are thinking the first idea is the best. Naturally it was not my invention but from Commodore. They developed their CBM BASIC V 3.5 (used on "Commodore +4" 1986). It had a similar set of commands like FB today. There where even some more like sound and vol. And it was fast! Because it was in ROM it was immediately ready after switching on.

Now we have higher resolutions and a HD, but many things are still the same in FB.

If sean_vn wants something taken in FB he should explain exactly what. But because there are no developers, afaik, it most likely will not be implemented.
marcov
Posts: 3454
Joined: Jun 16, 2005 9:45
Location: Netherlands
Contact:

Re: D language as a basis for a Basic

Post by marcov »

caseih wrote:
Definitely I don't understand the obsession with braces and semi-colons. I guess the only thing going for braces is that it's easy to type and multi-purpose. Pascal's BEGIN...END blocks drove me nuts. Besides all the extra typing, I was never quite sure how to format them. FB's multiple END statements is okay, since you don't have to specify BEGIN all the time. Oddly enough, Python's white-space syntax feels super natural to me.
I think both C and Pascal got it wrong. Blocks should simply always be multiple lines (e.g. require an end block keyword, like } or "end"). So no more variant for one statement, just one for multiple statements.

Then (1) one doesn't need begin block token to differentiate between the two and (2) because then always an END (or whatever the end block keyword is) follows, IDEs can easier autocomplete it. (since any IF has an END etc).

That said, IDEs have gotten pretty good in completing blocks with extra keysome extra hinting, so it should not be exaggerated. Personally I prefer begin..end of course, with braces it is IMHO harder to see the block structure. Python is even worse, even with my relative modest work done in it. I hate it with a passion.

If I ever design a language, it would have this Modula2 feature, and I make the BASIC option of having the type of block (end if, end <x> in general) optional. If you supply it, it has to match, but you can omit it, except at the end of a routine (sub,function,procedure)

(Modula2 had end "name of sub" but that was a hassle to keep in sync. It is mainly important if you allow nested subs)
As for semicolons, a lot of languages these days with C-inspired syntax make the semicolon optional, and use it much like FB uses the colon. In this instance, I prefer semicolons to colons as from a natural language point of view a colon implies that what follows is related; whereas a semicolon indicates a new though.
And then of course there is the discussion of the semicolon is a terminator or a separator (the difference between Pascal and C's ;) :-)
caseih
Posts: 2157
Joined: Feb 26, 2007 5:32

Re: D language as a basis for a Basic

Post by caseih »

Yeah there's definitely no syntactic need for anything other than "end" (or something similar) to end a block. The only problem with end is similar to the problem with braces in that it adds a bit of cognitive burden on the human if the formatting isn't perfect or if the code block is very long. I would suspect you'd find a whole bunch of comments in the code like:

Code: Select all

if ...
    if ...
        for ...
            ...
        end 'for
    end 'if
end 'if
Especially for longer code snippets that scroll off the screen. Never mind that a function should never be longer than a screen full making such comments unnecessary.

It's really humorous to me what strong feelings Python engenders in people who don't use it much. There are very very few people who after working with Python for a period of time, dislike the syntax. Most find it very natural. That was a surprise to me. I certainly didn't like what I saw when I first was exposed to Python. But having developed in it for some time, I now strongly prefer it; problems with whitespace indent levels have only caused me trouble on a couple of occasion when trying to refactor soemthing. There's something very appealing about executable pseudocode. ESR's experience with Python is actually the common case. I'm sure most non-python programmers feel we're zealous nutcases. But Python really has changed my life! :)
TeeEmCee
Posts: 375
Joined: Jul 22, 2006 0:54
Location: Auckland

Re: D language as a basis for a Basic

Post by TeeEmCee »

caseih: agreed with you wrt to Python. I write a lot of Python, and find the indentation pleasant because it means shorter code and less typing, even though on some occasions I've managed to get confused while refactoring.
caseih wrote:The problem with automatic translation into other languages like C++ is that idioms of the target language end up bleeding through into development process. Even FB's current close relationship with C can lead to programming in C style with FB syntax.
I don't see why you would write FB any differently if using the GCC backend or some new FB-to-C++ transpiler rather than the traditional assembly backend, aside from not using varargs because the GCC backend doesn't support those, and some other inline assembly edge cases. (If that's your point - that compatibility is not actually 100%, so it's a leaky abstraction, then you're certainly correct.)
And FB resembles C not because it has a GCC backend, which is irrelevant. (However, it is most certainly heavily influenced by design and limitations of the assembler-linker toolchain which FB inherits from C. Even QB was linkable with C.)
marcov
Posts: 3454
Joined: Jun 16, 2005 9:45
Location: Netherlands
Contact:

Re: D language as a basis for a Basic

Post by marcov »

caseih wrote:Yeah there's definitely no syntactic need for anything other than "end" (or something similar) to end a block. The only problem with end is similar to the problem with braces in that it adds a bit of cognitive burden on the human if the formatting isn't perfect or if the code block is very long.
Not that bad actually. But having a block structure at all, allows automated reformatting in complex edit scenarios, while with indent-only languages that is more complicated.

More advanced IDEs have highlighting that you can trust. (go to a token, and it highlights the matching token)

Such comments are workarounds for IDE deficiencies.
It's really humorous to me what strong feelings Python engenders in people who don't use it much. There are very very few people who after working with Python for a period of time, dislike the syntax.
I don't recognize that sentiment. I hear all the time that people don't like the whitespace identing. It is not that undisputed, even under Python users.

I had to use Python on some colloborative project, and hate every minute of it. Might have had something to do with the habit of using plain texteditors instead of proper IDEs though.
There's something very appealing about executable pseudocode. ESR's experience with Python is actually the common case. I'm sure most non-python programmers feel we're zealous nutcases. But Python really has changed my life! :)
Mine also! Just not for the better.

But I recognize the zealous nutcases aspect. That describes the people I had to work with perfectly. Personally I was seriously underwhelmed, and didn't understand what the fuzz was all about. Yes there are a million packages, but quality is fairly low.
Last edited by marcov on Mar 18, 2018 15:04, edited 1 time in total.
Post Reply