What is wrong with the BASIC language?

General discussion for topics related to the FreeBASIC project or its community.
anonymous1337
Posts: 5494
Joined: Sep 12, 2005 20:06
Location: California

Re: What is wrong with the BASIC language?

Post by anonymous1337 »

agamemnus wrote:
anonymous1337 wrote:Dude, v8 is f*ing fast these days :)

http://benchmarksgame.alioth.debian.org ... &lang2=gcc

Considering most people are processing server-side js using v8 + node.js (which then hands execution off to async c++ modules), those benchmarks are not bad at all given everything JavaScript can do.
It's far faster to code with than many other languages. But still, static typing and weak garbage collection will always be faster than non-static typing and automatic garbage collection... right?
Depends on how much you depend on those features, but I'm just speculating. (It's not like I have the capacity to work on V8 or LLVM myself, for example.)

How much faster than "normal" automatically optimized code, vs code that was specifically structured to avoid cache misses and optimize for a specific system (which a JIT can do, but an optimizing static compiler can only do if you target that system specifically)? Or how about garbage collection vs manual memory management? How good are people at manual memory management, really? (Allocating memory is one of the most expensive operations, and thus it's often done in big batches in highly optimized code by, for example, turning separate arrays into a vectorized single array.)

I'd say that if you're just writing code, not optimizing it at the framework level, you're not getting as many benefits from C or C++ as you might think. That depends on the underlying libraries as well as compiler implementation. Of course, the reference Ruby compiler is still entirely interpreted from what I recall. It's very slow. Scaled horribly for Twitter when it got to that point. Ruby's still an incredibly useful language. You just wouldn't want your game engine's inner loop written in Ruby, for example.

Now, Node.js and JavaScript with V8 is particularly interesting because JavaScript can be made extraordinarily fast. One, you have the V8 compiler which is going to determine the best ways to cache and optimize code. Thank you, Google. Two, you have the architecture which delegates the "inner loop"-type processing to async C++ threads, so there, your code is as basically as optimized as it's going to get already. (How expensive are function calls or marshalling between languages, really? Java does it all the time and it's maybe a fraction slower than C++ except for the cases, again, where people specifically optimize their code.)

So yeah, obviously there's overhead (RTTI, processing) to permit dynamic typing. I'm not soooo sure about garbage collection because that's already being done in modern C++ apps anyways. At least some sort of automated memory management via auto / smart ptrs.

Again, if you are using something like JavaScript how you would a statically typed language, maybe there are things that can be optimized. There will certainly still be overhead, but it appears to be surprisingly minimal for most uses. With something like ASM.js and the right JS compiler, I think you can achieve real desktop client performance now anyways... but don't quote me on that. I haven't followed that particular end of technology in a while.

ASM.js removes a lot of info / safety checks from JS, which makes it more barebones. And there's an important question... Can you remove features of a language at compile-time to allow optimizations? That's a crazy thought. It's what C, C++ allow you to do. C++ is really complex, but so much of that complexity is built on top of these surprisingly powerful and heavily optimized core features. But imagine JS without all of the safety, RTTI information, maybe even remove duck typing capabilities (although that might break the core of how the language functions in other places).

The fact that you get all of these features in JS and it's still fast as hell really confuses me to an extent. It's just crazy to think about. Or how algorithms written in JS or Ruby could actually perform faster than the same algorithm implementations in C or C++. That's weird, right? Just because a language offers ways to accomplish different things out of the box without interference from language, runtime or syntactical restrictions. One might think that shouldn't matter when you're comparing something to C or C++ (I think especially C++ because of its powerful standard library) because you're so close to how processing on the CPU actually works, but it apparently does.

I'd be interested in seeing the resultant processing / ASM from the simplest possible cases when JS or Ruby significantly outperform C or C++ implementations.
marcov
Posts: 3455
Joined: Jun 16, 2005 9:45
Location: Netherlands
Contact:

Re: What is wrong with the BASIC language?

Post by marcov »

Keep in mind that these benchmarks with their high locality are a sweet spot for JITs though.

I don't know JS' internals that well, but you can actually push Java a lot by pretending it is C and only using value types if it is all fairly overviewable with nice localized bottlenecks the VM can optimize the hell out.
Last edited by marcov on Jan 21, 2024 11:33, edited 1 time in total.
caseih
Posts: 2157
Joined: Feb 26, 2007 5:32

Re: What is wrong with the BASIC language?

Post by caseih »

Seems like Javascript is becoming a new virtual machine in its own right. There are many compilers out there that can emit JS now. Using emscripten, almost any language that has a compiler in the LLVM system can be targeted to Javascript. So in theory evey FreeBasic could compile to Javascript and run in any of the JS virtual machines out there. I'm honestly not sure what to think of this!
ike
Posts: 387
Joined: Jan 17, 2011 18:59

Re: What is wrong with the BASIC language?

Post by ike »

the new generation of Delphi compilers (and also the C++Builder compilers) utilize the LLVM architecture.

it is worth mentioning that the LLVM architecture is gaining a lot of traction both in the open source tools world and in the proprietary world

The idea is to be able to compile Delphi source code to the LLVM IR and offer support for several CPU targets, starting with the ARM compilers for iOS and Android
caseih
Posts: 2157
Joined: Feb 26, 2007 5:32

Re: What is wrong with the BASIC language?

Post by caseih »

The Gnu Compiler Collection still is a good set of tools, is still a lot more portable actually (many more platforms, though some obscure ones are probably bitrotting). FB's emitted C code could probably compile fine under llvm clang compiler, though. LLVM seems to be a bit easier for compiler writers to work with. FB could probably emit LLVM AST directly.

I am in favor of sticking with the c emitter and gcc compiler though. Wonder if there's a use case for a native client port of the FB compiler. The basics are already available, even SDL.
marcov
Posts: 3455
Joined: Jun 16, 2005 9:45
Location: Netherlands
Contact:

Re: What is wrong with the BASIC language?

Post by marcov »

ike wrote:the new generation of Delphi compilers (and also the C++Builder compilers) utilize the LLVM architecture.
Afaik only the ARM compilers use LLVM, the x86 and x64 Windows compiler are still the old. And the "mobile" compilers only support part of the dialect.
it is worth mentioning that the LLVM architecture is gaining a lot of traction both in the open source tools world and in the proprietary world
I would say the traction is a bit less than a few years ago. GCC seems to be invigorated and pushed out a generally lauded 5.0, and in small language communities you hear the complained that CLang and LLVM are more and more entangled, and it is harder as an external to keep up.
The idea is to be able to compile Delphi source code to the LLVM IR and offer support for several CPU targets, starting with the ARM compilers for iOS and Android
They started with that 4 versions ago, but still no better optimization for x86/x86_64. I begin too suspect it isn't as succesfull as they hoped.
caseih
Posts: 2157
Joined: Feb 26, 2007 5:32

Re: What is wrong with the BASIC language?

Post by caseih »

GCC goes through cycles of decline and resurgence. Back in the GCC 2.x days, it actually completely died. It was replaced by the EGCS project, so GCC 3 was essentially a fork. Rather than merging it back into the mainline, it simply replaced GCC. Now GCC is being reinvigorated by its LLVM competition, as well as the rise of JIT languages that rival compiled language speed. Like I say, GCC has a long life ahead of it. It's typically first to get ported to new platforms and architectures.
anonymous1337
Posts: 5494
Joined: Sep 12, 2005 20:06
Location: California

Re: What is wrong with the BASIC language?

Post by anonymous1337 »

Wow, didn't even know about the 5.0 release.

Look at this :)
https://gcc.gnu.org/wiki/JIT
caseih
Posts: 2157
Joined: Feb 26, 2007 5:32

Re: What is wrong with the BASIC language?

Post by caseih »

Very cool. I hadn't heard about that part either. Some of what drew people to LLVM was that it could be used as a library to emit code in a JIT-like fashion. Or just do cool analysis by having the parser and abstract syntax tree available to a program. For example a smart code completion module that dynamically pulls in symbols and names from the complete project.
marcov
Posts: 3455
Joined: Jun 16, 2005 9:45
Location: Netherlands
Contact:

Re: What is wrong with the BASIC language?

Post by marcov »

caseih wrote:GCC goes through cycles of decline and resurgence. Back in the GCC 2.x days, it actually completely died. It was replaced by the EGCS project, so GCC 3 was essentially a fork. Rather than merging it back into the mainline, it simply replaced GCC. Now GCC is being reinvigorated by its LLVM competition, as well as the rise of JIT languages that rival compiled language speed. Like I say, GCC has a long life ahead of it. It's typically first to get ported to new platforms and architectures.
Yeah, it was all to be expected, the world dominance plans of LLVM were a bit overly optimistic. As said the LLVM propaganda reminded me a lot of the GCC propaganda (when they introduced GIMPLE and the IR before) in the mid nineties.

That doesn't mean that either GCC or LLVM are on the way out (Even FPC has a LLVM and JVM backends nowadays), it is just that the honeymoon period of LLVM is over. Reality set in.

Still I fail to see the Javascript attraction other than the web tie-in. Yes it is a cheap runtime to maintain for mobile vendors since they to anyway for the browser, and for smaller apps it doesn't matter much. But to say it is great and the future of everything? Brrrr.
Last edited by marcov on May 02, 2015 12:06, edited 1 time in total.
jcfuller
Posts: 325
Joined: Sep 03, 2007 18:40

Re: What is wrong with the BASIC language?

Post by jcfuller »

One of my favorite distros just updated:
http://nuwen.net/mingw.html

Note: 64bit only
James
TESLACOIL
Posts: 1769
Joined: Jun 20, 2010 16:04
Location: UK
Contact:

Re: What is wrong with the BASIC language?

Post by TESLACOIL »

ref What is wrong with the BASIC language?

Q What is wrong with ALL programing languages ?

None of them are designed with common sense in mind ! , Ive not seen a single language that even comes close to close to being 'fit for human consumption' ...the chasm between what we should have as a programming language and what we do have is so vast and so deep that it not only defies explanation it defies my comprehension !!!

The blame for this deficit
lies almost entirely with experienced programmers, for they are the human beings responsible for creating computer languages. Paid or unpaid, it matters not, their crime is the same, their guilt the same, such truths are self evident and set out plain clear and clear to all humankind !

Guilty !

To close to the problem to see the solution
marcov
Posts: 3455
Joined: Jun 16, 2005 9:45
Location: Netherlands
Contact:

Re: What is wrong with the BASIC language?

Post by marcov »

TESLACOIL wrote:
None of them are designed with common sense in mind ! , Ive not seen a single language that even comes close to close to being 'fit for human consumption' ...the chasm between what we should have as a programming language and what we do have is so vast and so deep that it not only defies explanation it defies my comprehension !!!
If you know so well what we should have, why don't you simply create it then?
pidd
Posts: 31
Joined: Nov 11, 2022 16:27

Re: What is wrong with the BASIC language?

Post by pidd »

7 years on, has anything changed?

I started pretty much with Basic after some minor other weird stuff and soon did a lot of assembler on 8-bit CPU's. Basic was and still is an essential tool for me when I want something either quick and dirty or when I am throwing a program around trying to find the best way to proceed. Freebasic has been a godsend in recent years.

I find it incredulous that Python has gained a lot of ground and even more incredulous that it is gaining ground as a training language. I tried hard with Python and never felt one bit comfortable with it and hanging indents are a waste of classroom time in a training environment.

These days I program in Freebasic, C and PHP. I get slated every time I say this but I like PHP as a general programming language, it is hugely flexible and a massive but usually logical command set (eat your heart out VBA). I resisted C for many years but seeing some of the alternatives in recent times it has become a lot more attractive to me, when I'm in "the zone" C is great, when I'm struggling with something I end up thinking I would prefer to be using Freebasic.

I am very strictly a procedural programmer, objects are occasionally handy but normally are an unnecessary overhead. I retained the mindset of early programming with limited speed and memory, I still find me doing optimisations that are often totally necessary.

I would like to see two things for freebasic; a proper standard IDE similar to the capabilities and style of QuickBasic45 compiler's IDE, and bit more flexibility added to the language, things like being able to change the default tab width. I love most of the progression Freebasic has achieved over Dartmouth-ish Basics.

What is bad about Basic? I overuse for-next loops when other types of loops are probably more appropriate. Probably younger Basic programmers haven't got this problem, its a hangover from the past.

What is good about Basic? The retention of "goto", its 100% normal in assembler to have jumps or branches and I dislike some of the snobbery about the use of goto's - not that I use goto often but sometimes it is the best way. C retained goto but that is not talked about.

I notice some K&R/White-Book stuff is getting deleted in C23!

What else is good about Freebasic? I like cross-platform languages and Freebasic is pretty good for that, I use it on three architectures.

What is bad about Freebasic? Having to have a Freebasic binary to build Freebasic, chicken and egg nightmare.
caseih
Posts: 2157
Joined: Feb 26, 2007 5:32

Re: What is wrong with the BASIC language?

Post by caseih »

Just curious. What are you doing in C that you couldn't do in FB? Leaving aside the mountains of macros that are involved in C header files making them a challenge to translate to FB, C code itself is 1:1 translatable to FB.

What do you mean by over using for/next loops?
Last edited by caseih on Dec 01, 2022 19:41, edited 2 times in total.
Post Reply