Like FreeBASIC? Try JavaScript

General discussion for topics related to the FreeBASIC project or its community.
marcov
Posts: 3455
Joined: Jun 16, 2005 9:45
Location: Netherlands
Contact:

Re: Try JavaScript

Post by marcov »

Lost Zergling wrote:My arguments are indeed armchair philosophical. Are they worthless ?
As is, without additional argumentation resting on soundbites like "industry standard", yes, they are.
You said "But that is not a good reason to let Javascript escape the browser."..
Problem : Javascript already escape the browser.
In some industries. It yet has to achieve the dominance it has in the browser in other fields. It might, and it might not. I'd say, if it does, then not in this form.

Moreover, contrary to languages that made industry standards like Java and C#, javascript is horribly fragmented over toolchains. Even for client usage, the amount of generated javascript (in the form of typescript and others) is slowly outpacing the lines written in javascript natively.
Question is how and why. I'm using FB, not java script (I do not need it). On other hand, my opinion is that some of anonymous1337's arguments are to be considered carefully. Your remark about Java "Java would be as well suited as javascript" is very interesting from my point of view : when Lotus Notes / Domino jumped from Basic to Java I prefered staying on basic.
The point was that they share syntax, and that syntax is only a rather superficial part of a programming langauge. One could argue though that javascript+static typing like done by the various javascriptgenerators is closer to java than to javascript.
We are very small when facing industrial standards !
Doing serverside javascript is not an industry standard. C#/ASP.NET or Java are the industry standards. Javascript, despite its client monopoly is still an up and coming technology that has to survive the first crunch. Of course hypes sometimes turn into industry standards, but being a hype is not a guarantee. (where is Ruby on Rails nowadays?)
Last edited by marcov on Nov 05, 2018 9:20, edited 1 time in total.
anonymous1337
Posts: 5494
Joined: Sep 12, 2005 20:06
Location: California

Re: Try JavaScript

Post by anonymous1337 »

marcov, with all due respect, NodeJS is being used at a fundamental level in many organizations. JavaScript work is just as common as C# or Java work in a lot of places, although it is perhaps still a bit more niche. It owns a lot of the general web dev space (front-end and back-end) and many industrial and fin-tech areas. JSON (very closely related to JS) has become the preferred way of serializing data for web technologies and similar standards (ex: BSON) power technologies like MongoDB.

I'd say JS or at least JS-related technologies are fairly "ubiquitous", but like every language, it depends on where you look and how you define that.

Also, the comparisons of Java and JavaScript from both you and Lost Zerling are IMO misplaced... JS and Java share as much in common as pretty much any C-style languages, except JavaScript is actually wildly different.

Lost Zerling, (I may have misunderstood, but) JavaScript is not "Java Scripts". They are common by name only and honestly other than early attempts to market JavaScript as "Java for the web" (which were horribly untrue) they're completely different languages. JavaScript is not Java, doesn't run on Java's JIT or related technologies, and is largely inoperable / incompatible with Java code.

Take for example some Java code to read from a file:

Code: Select all

 / Java program to illustrate reading data from file 
// using nio.File 
import java.util.*; 
import java.nio.charset.StandardCharsets; 
import java.nio.file.*; 
import java.io.*; 
public class ReadFileIntoList 
{ 
  public static List<String> readFileInList(String fileName) 
  { 
  
    List<String> lines = Collections.emptyList(); 
    try
    { 
      lines = 
       Files.readAllLines(Paths.get(fileName), StandardCharsets.UTF_8); 
    } 
  
    catch (IOException e) 
    { 
  
      // do something 
      e.printStackTrace(); 
    } 
    return lines; 
  } 
  public static void main(String[] args) 
  { 
    List l = readFileInList("C:\\Users\\pankaj\\Desktop\\test.java"); 
  
    Iterator<String> itr = l.iterator(); 
    while (itr.hasNext()) 
      System.out.println(itr.next()); 
  } 
} 
Some JavaScript code to read from a file:

Code: Select all

 var fs = require('fs');
 
var contents = fs.readFileSync('DATA', 'utf8');
console.log(contents);
JavaScript as a language or environment isn't any more client/server than C#, C++, BASIC, etc. Even in the browser, JavaScript is only client-server because of the DOM components that are available in the execution context as part of web browser standards. For native applications, no one is making you spin up a server in NodeJS. It's just really easy to do:

Code: Select all

 const http = require('http');

const hostname = '127.0.0.1';
const port = 3000;

const server = http.createServer((req, res) => {
  res.statusCode = 200;
  res.setHeader('Content-Type', 'text/plain');
  res.end('Hello World\n');
});

server.listen(port, hostname, () => {
  console.log(`Server running at http://${hostname}:${port}/`);
});
JavaScript is not a very elegant language and care has to be taken not to blow yourself up using it if you come from something more "pure" (take a look at JavaScript's truthy tables for an example of how ugly JS can get). It reminds me a lot of PHP in that sense. Ugly, but useful. Except JavaScript turns out to have strong enough of a foundation to build major technology platforms on and continues to evolve into something cool (esp. ES6+).

Arguments for JavaScript might be fast execution speed, portability, friction-free development thanks to duck-typing and interoperability between serialization and native objects, as well as the ecosystem of available tools and supported technologies (JavaScript knowledge is cross-applicable to client, server and mobile application environments). Its asynchronous event processing model is seen by some as an advantage.

I think Go is an example of a language that is really beautiful in theory but difficult to work with. Closer to C for the web. JavaScript is closer to a Java or C# for the web in spirit. Maybe even closer to a Python except it executes 10x as fast.
Last edited by anonymous1337 on Oct 08, 2018 1:49, edited 1 time in total.
St_W
Posts: 1619
Joined: Feb 11, 2009 14:24
Location: Austria
Contact:

Re: Try JavaScript

Post by St_W »

IMHO this discussion is a bit pointless, especially when considering that this is a FreeBasic forum, because this topic could be also discussed for so many other modern programming languages with probably similar results. The thing is that (Free)Basic is a niche language with many implications:
- it doesn't get many updates, especially when compared to widely used languages like JS, C#, Java, Python, ...
- the language itself gets updated very slowly and therefore is quite outdated nowadays
- there is far less tooling available (IDEs, code analysis, package/library managers, ...)
- less features due to less development resources
- smaller ecosystem with less existing resources (samples, libraries, tutorials, ...)
- .... just to mention some of them.
That means no matter which modern programming language you choose, they all provide "cool" features and great tooling that is better than FB's in many regards. This is true for JS, but it is also true for e.g. C# or Python. Similarily this thread could be also called "Try C#" or "Try Python" or "Try <whatever popular programing language>". All these have some interesting concepts that are definitly worth a try (especially if you only know FreeBasic). And finally, there's no better-worse relation between programming languages, only a "more/less suitable for a specific task" one. This means specifically for this thread: while JS has many advantages over other programming languages it is not superior to them (for example JS would be inappropriate for programming a µC). And even if FB doesn't have the most features or the greatest tooling or the biggest ecosystem it still has its own advantages over other languages.

Summa summarum: Yes, try JS! but also try other programming languages!
Last edited by St_W on Oct 08, 2018 1:04, edited 1 time in total.
anonymous1337
Posts: 5494
Joined: Sep 12, 2005 20:06
Location: California

Re: Try JavaScript

Post by anonymous1337 »

St_W wrote:IMHO this discussion is a bit pointless, especially when considering that this is a FreeBasic forum, because this topic could be also discussed for so many other modern programming languages with probably similar results.

Summa summarum: Yes, try JS! but also try other programming languages!
A few differences, IMO, as someone who has programmed professionally in C#, Java, Ruby on Rails, VB.NET, etc. not that it makes my opinion authoritative but I have used pretty much every major language out there:

1) You can do graphics in an "easy" language like ex: Python, but you can't run Python in the web browser. The spirit of the old FreeBASIC and QBASIC communities as heavily involved in making personal, distributable applications. We had an especially cool game community which I suppose I would be most-likely to pander to. Remember Lynn's Legacy?

2) A big draw of FreeBASIC was about improving performance over QBASIC. JavaScript is about as fast as FreeBASIC is - between 3x - 15x slower than C/C++ depending on execution context.

3) People like FreeBASIC's built-in utilities, especially having a basic graphics API available (again maybe pandering to my specific experience). With the web browser, JavaScript has built-in XMLHttp and Canvas through HTML5 components. On the backend/server side, you have built-in web API capabilities.

4) Syntactically, there's curly braces yeah... beyond that though, JS carries the same spirit of BASIC I feel. It's quirky, people are constantly asking for new features, you don't need semi-colons. It's easy for beginners to use but offers a lot of intricacies and explorations as you master it.

5) Community. I think there are plenty of JS opportunities for us in the community. I honestly think that's perhaps where the majority of us hobbyist folks should move on, except for those who need better control over datatypes, but we can probably curate to those folks as well through experimental technologies and Node C++ modules.

For a long time, my professional development loomed like a black cloud over me. JavaScript has reinvigorated a lot of excitement, honestly.

I feel like this post is either something you're going to "get" or "not get". You either feel the same vibe I do or you don't.

After JavaScript, I think Python is probably the next closest thing, but it's just so wildly different (as well as slow, not natively supported in web browser or mobile devices, fundamental language differences that are a shocker to some especially when it comes to OOP, etc.) that I personally don't think it applies.
Last edited by anonymous1337 on Oct 08, 2018 1:49, edited 1 time in total.
Lost Zergling
Posts: 534
Joined: Dec 02, 2011 22:51
Location: France

Re: Try JavaScript

Post by Lost Zergling »

anonymous1337, thanks for that clarification. With all due respect, I do not think I've confused javascript with java scripts, or it's a shell or a misinterpretation. On server client aspects, you may be right, but you may agree that easier access to the DOM, the appearance of a key-value object and nodejs features brings us a little closer to well-known terrain. Reminds me so much well known architecture by some aspects.
No client-server architecture here, it is promised sworn.
https://plugins.jquery.com/ => No new release) thus the site offers one way ticket links this one : to https://js.foundation/about/members
Thank you json, please my dear hide this ajax that I will not see. Joke.
As I said in my first post "But the evolution of Java Script is the fact of heavy investment in R & D by industry major, while you can always make your contribution to the language Free Basic. With Java script you become more a user than an actor, you are a little less 'at home'. As for Java, you will be good as long as you have the right tools, the right licenses, and even if it is without comparison to find a job, the future is not guaranteed in the same way, so this is where disadvantage."
anonymous1337, there is a lot of truth in your last post, and I thank you for the implicit compliment on the people who need better control over the types of data. Maybe you were referring to my opinions. I like being faithful to the technology to which I owe a lot.
Yours Zerglingly.
marcov
Posts: 3455
Joined: Jun 16, 2005 9:45
Location: Netherlands
Contact:

Re: Try JavaScript

Post by marcov »

anonymous1337 wrote:marcov, with all due respect, NodeJS is being used at a fundamental level in many organizations.
Nearly every toolchain is used at some level. Doesn't make an industry language.
JavaScript work is just as common as C# or Java work in a lot of places, although it is perhaps still a bit more niche.
No I think not. But that was I took pains to point out the difference in browser and server side javascript. The browser side probably more than dwarfs anything else, which makes statements like you do above dangerous without proper qualification.

You really mean node.js serverside (or mobile phones apps for all I care?)
It owns a lot of the general web dev space (front-end and back-end) and many industrial and fin-tech areas. JSON (very closely related to JS) has become the preferred way of serializing data for web technologies and similar standards (ex: BSON) power technologies like MongoDB.
IMHO not related. Yes, javascript pushed that, but it is fairly language agnostic. it is actually quite a lot like the PHP serialization used before it became popular.
I'd say JS or at least JS-related technologies are fairly "ubiquitous", but like every language, it depends on where you look and how you define that.
If I weight platforms against each other, I mostly imagine FTEs working on it.
Also, the comparisons of Java and JavaScript from both you and Lost Zerling are IMO misplaced... JS and Java share as much in common as pretty much any C-style languages, except JavaScript is actually wildly different.
Note that Zergling only said syntax. Semantics is a totally different matter.
JavaScript as a language or environment isn't any more client/server than C#, C++, BASIC, etc.
Thanks for confirming me on that. The coupling is
Even in the browser, JavaScript is only client-server because of the DOM components that are available in the execution context as part of web browser standards.
I don't understand that. I know what DOM is, but not what is client-server about it. To my best knowledge, clientside RUNNING script never calls serverside RUNNING javascript without serialization/deserialization to some JSON, HTTP (REST, XML based RPC) or other streaming format.
Except JavaScript turns out to have strong enough of a foundation to build major technology platforms on and continues to evolve into something cool (esp. ES6+).
I think in time they cut out the middle man. If fragmentation over the various typed javascript versions doesn't kill it beforehand.

Or the legacy. When technology is booming nobody cares a whit about that, just SHIP IT. But after a while reality sets in.
Arguments for JavaScript might be fast execution speed
"chokes on his coffee". Oh, wait, you mean relative to old interpreted javascript ?
anonymous1337
Posts: 5494
Joined: Sep 12, 2005 20:06
Location: California

Re: Like FreeBASIC? Try JavaScript

Post by anonymous1337 »

marcov wrote:"chokes on his coffee". Oh, wait, you mean relative to old interpreted javascript ?
marcov, I qualified what I mean by performance, but I can more. I mean relative to any interpreted language and with performance within the 3x - 5x range range of Java and C++. See: https://benchmarksgame-team.pages.debia ... e-gpp.html
I don't understand that. I know what DOM is, but not what is client-server about it. To my best knowledge, clientside RUNNING script never calls serverside RUNNING javascript without serialization/deserialization to some JSON, HTTP (REST, XML based RPC) or other streaming format.
... Yes... but this is how most of the web works? Do you want it to use raw TCP and binary data streams or something? What is your point? This is actually a benefit and silly thing to nitpick about IMO. The DOM APIs come with XMLHttpRequest objects, and Node comes with http built-in.

I feel you're just being contrarian at this point, especially given this context:
As you can see above, the survey revealed that JavaScript is the top programming language 2018, at 69.8% — for the sixth consecutive year.
https://hackernoon.com/top-3-most-popul ... b4a7354e06

We have a language that for SIX YEARS has been the most popular programming language (and probably a top language quite a bit longer than that). There's not debating its dominance. Next thing you know you'll be saying COBOL's more popular even though NodeJS is displacing a lot of old C/C++ and COBOL mainframes in fintech.
paul doe
Moderator
Posts: 1730
Joined: Jul 25, 2017 17:22
Location: Argentina

Re: Try JavaScript

Post by paul doe »

St_W wrote:IMHO this discussion is a bit pointless, especially when considering that this is a FreeBasic forum, because this topic could be also discussed for so many other modern programming languages with probably similar results.
A bit pointless, you say? I'd say that this entire thread is an exercise in pointlessness, and was created just for the sake of arguing (which some members seem to be quite fond of).

Not to mention some simply outlandish claims:
anonymous1337 wrote:2) A big draw of FreeBASIC was about improving performance over QBASIC. JavaScript is about as fast as FreeBASIC is - between 3x - 15x slower than C/C++ depending on execution context.
When? Back in 2008? I'd be hard pressed to see C++ code that runs 40%-50% faster than the equivalent FB code nowadays, and that's just because you can use inlining, register variables and a lot of intrinsics and features of C++ that FB simply doesn't have. Of course, you need to use a decent compiler (read: GCC), but fifteen times slower? Can you show at least one valid example of this claim?
anonymous1337 wrote:4) Syntactically, there's curly braces yeah...
Indeed, those are pretty scary, especially for BASIC programmers, it seems.
anonymous1337 wrote:...beyond that though, JS carries the same spirit of BASIC I feel. It's quirky, people are constantly asking for new features, you don't need semi-colons. It's easy for beginners to use but offers a lot of intricacies and explorations as you master it.
Those were real deal breakers for me. It's a relief knowing that all the stupid flaws of BASIC got carried over to JS so I can continue to 'enjoy' them. Hooray!
anonymous1337 wrote:5) Community. I think there are plenty of JS opportunities for us in the community. I honestly think that's perhaps where the majority of us hobbyist folks should move on, except for those who need better control over datatypes, but we can probably curate to those folks as well through experimental technologies and Node C++ modules.
The community thing I may buy (it just so happens that I know a sh*tload of other languages, and virtually ALL of them have more active communities than FB ATM), but hobbists will simply use whatever they feel most comfortable with (especially since the average FB user seems to be like 80+ years old =D). They don't need to 'get with the times' (some might do, but the majority won't). If you're not a professional working (or trying to work) on IT, the 'try JavaScript, you might get employed!' argument sounds just like cargo culting to me. Not that I'm interested in getting a job in the IT industry, alas.
anonymous1337 wrote:We have a language that for SIX YEARS has been the most popular programming language (and probably a top language quite a bit longer than that). There's not debating its dominance.
So, what's the entire point of this lame discussion? State it clearly, please. Don't do things like this:
anonymous1337 wrote:I think the JavaScript ecosystem is compelling enough to ditch FB altogether for all but a few niche cases (as far as where you would realistically pick between the two).
anonymous1337
Posts: 5494
Joined: Sep 12, 2005 20:06
Location: California

Re: Try JavaScript

Post by anonymous1337 »

paul doe: Happy to reply, but can you please calm down?
paul doe
Moderator
Posts: 1730
Joined: Jul 25, 2017 17:22
Location: Argentina

Re: Try JavaScript

Post by paul doe »

anonymous1337 wrote:paul doe: Happy to reply, but can you please calm down?
Just reply if you want, bud. I'm not angry, and if you can make your point, I'll be more than happy to concede. But 'throwing a curve' doesn't look like a promising start to me, though.
anonymous1337
Posts: 5494
Joined: Sep 12, 2005 20:06
Location: California

Re: Try JavaScript

Post by anonymous1337 »

paul doe wrote:
St_W wrote:IMHO this discussion is a bit pointless, especially when considering that this is a FreeBasic forum, because this topic could be also discussed for so many other modern programming languages with probably similar results.
A bit pointless, you say? I'd say that this entire thread is an exercise in pointlessness, and was created just for the sake of arguing
My intent with this thread is to share an idea I thought was cool. I'm still not sure what all the contrarian mindsets and arguing is about.
Not to mention some simply outlandish claims:
anonymous1337 wrote:2) A big draw of FreeBASIC was about improving performance over QBASIC. JavaScript is about as fast as FreeBASIC is - between 3x - 15x slower than C/C++ depending on execution context.
When? Back in 2008? I'd be hard pressed to see C++ code that runs 40%-50% faster than the equivalent FB code nowadays, and that's just because you can use inlining, register variables and a lot of intrinsics and features of C++ that FB simply doesn't have. Of course, you need to use a decent compiler (read: GCC), but fifteen times slower? Can you show at least one valid example of this claim?
Unfortunately, FreeBASIC has been removed from the benchmark games and I no longer have these comparisons available. Paul, I'm reading the italics as attitude / emphasis. Maybe that's not what you mean by them. Like why would I post an invalid example? It's really unnecessary.

I like how you took 3x - 15x and selectively nitpicked the 15x as though that's unheard of. It's incredibly common for this type of variation to exist even in "valid" benchmarks simply because some languages / runtimes are better than others are doing certain thing. Take Perl which is generally slow for example vs most other languages for Regex processing. Because Perl's has optimal regex support, it usually wins.

Skimming this thread, it looks like ~3x is typical for FreeBASIC, which is also what I said. So why focus on the 15x instead of that? viewtopic.php?f=17&t=26516

Selective reading and your own intent on being argumentative, IMO.
paul doe
Moderator
Posts: 1730
Joined: Jul 25, 2017 17:22
Location: Argentina

Re: Try JavaScript

Post by paul doe »

anonymous1337 wrote:My intent with this thread is to share an idea I thought was cool. I'm still not sure what all the contrarian mindsets and arguing is about.
Oh, right. So, I'll open a 'Like FreeBASIC? Try Erlang' thread to give folks here a taste of why Erlang is so cool (it really is), and why they're just a bunch of losers because they still use FreeBasic LOL
anonymous1337 wrote:Paul, I'm reading the italics as attitude / emphasis. Maybe that's not what you mean by them. Like why would I post an invalid example? It's really unnecessary.
By valid I meant an example that could be coded using 'native' FB and C++. No register variables, no SSE, no inlining, etc. And then compile them with the same switches (again, using the GCC backend; I'm not considering the GAS backend here). And the italics are emphatic words (or attitude, call them however you like)
anonymous1337 wrote:I like how you took 3x - 15x and selectively nitpicked the 15x as though that's unheard of. It's incredibly common for this type of variation to exist even in "valid" benchmarks simply because some languages / runtimes are better than others are doing certain thing. Take Perl which is generally slow for example vs most other languages for Regex processing. Because Perl's has optimal regex support, it usually wins.

Skimming this thread, it looks like ~3x is typical for FreeBASIC, which is also what I said. So why focus on the 15x instead of that? viewtopic.php?f=17&t=26516

Selective reading and your own intent on being argumentative, IMO.
Yeah, and I also like how you skimmed the thread and selected only one example that curve-fitted your claim (the slowest I saw on that thread was ~2.4x). And you're trying to arch the subject to me being argumentative? Please, that won't work, sorry. I'd like to think that you know better than this.
Post Reply