Shop OBEX P1 Docs P2 Docs Learn Events
The Official JavaScript Religious War Thread. - Page 11 — Parallax Forums

The Official JavaScript Religious War Thread.

1678911

Comments

  • KeithEKeithE Posts: 957
    edited 2015-02-24 13:28
    Heater - let us know of your reaction once you take a look. I just pointed out that remark so you would be aware of its existence.

    You can give your code example to Will Shortz for analysis ;-)
  • Heater.Heater. Posts: 21,230
    edited 2015-02-24 13:43
    I thank you for that.
  • ElectrodudeElectrodude Posts: 1,658
    edited 2015-02-24 16:09
    Heater. wrote: »
    Similarly, how can you claim to know JavaScript until you can write this:
    [][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]][([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+([][[]]+[])[+!+[]]+(![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[+!+[]]+([][[]]+[])[+[]]+([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+(!![]+[])[+!+[]]]((![]+[])[+!+[]]+(![]+[])[!+[]+!+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]+(!![]+[])[+[]]+(![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[!+[]+!+[]+[+[]]]+[+!+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[!+[]+!+[]+[+[]]])()
    

    :)

    How and why? What is this mysterious ! operator/variable/something?

    Can I obfuscate all of my javascript like that?

    While trying to figure that out, I discovered that true + true = 2, even though true + function() {} = 'truefunction () {}'. Why doesn't true + true = 'truetrue'?

    Seeing that this is The Official JavaScript Religious War Thread: Lua has separate .. (concat) and + (add) operators, another of the many reasons it is far superior to JS.
  • msrobotsmsrobots Posts: 3,709
    edited 2015-02-24 18:52
    How and why? What is this mysterious ! operator/variable/something?

    Can I obfuscate all of my javascript like that?

    While trying to figure that out, I discovered that true + true = 2, even though true + function() {} = 'truefunction () {}'. Why doesn't true + true = 'truetrue'?

    Seeing that this is The Official JavaScript Religious War Thread: Lua has separate .. (concat) and + (add) operators, another of the many reasons it is far superior to JS.

    JavaScript has some weird things going on. But to get a 'truetrue' you need to start with 'true' as string not value. So 'true' + 'true' == 'truetrue' . Same in most other common languages. The need for two different operators like in lua is more cosmetic in my opinion. Or a parser thing. But basically it is a definition how it should behave. Concat strings and add numerical values.

    That true + function(){} equals truefunction(){} is funny. Never tried that.

    No languages is superior to any other as like no race is superior to any other. This is BS.

    Every language has its place in the universe.
    Algol can still do things easy where you will fight in C/C#/C++.
    Basic (not Visual...) is still easy to understand for a newbie.
    C/C#/C++ are quite versatile, but not easy to understand..
    COBOL is still used in systems doing a lot of batch processing (banks/insurance/usps/military) .
    nothing with D
    Erlang is - well - interesting.
    FORTRAN, F# - hmm - never really tried functional languages but the concept is quite different.
    ...
    the list is long and I used many of them in my life. The right tool for the right job.

    Is a Phillips screw driver superior over a flat one? What if you need a flat one? Or vice versa?

    The same applies for languages and operating systems.

    Mike
    .
  • Heater.Heater. Posts: 21,230
    edited 2015-02-24 19:27
    You can obfuscate any JS you like. Just paste your code into the text box here:
    or download the program from github and use it locally. Problem is it makes your code ten or a hundred time bigger!

    We can say that true is represented by 1 in JS, ergo, true + 1 == 2, and true + true = 2. That makes some sense does it not?

    We like to stick strings together. So "Big" + "Apple" == "BigApple". This seems quite reasonable. One might wish to argue that it's concatenation not addition. But to the average Joe that is just making things unecessarilly complicated.

    With that in place obviously true + function() {} == 'truefunction () {}'. Why? Well, what is a function in JS other than that string that defines it you typed into your source code?

    People like to poke fun at JS for these weird type coercions all the time. In practice they are not a big problem.

    It is wise to use the triple equals operator === to inhibit these coercions. That ensures things are equal only if their types are the same.

    Always use jslint. In can run in your editor and always be reminding you not to make such a faux pas.

    Lua, is a wonderful thing. If you want you can use it in the browser. Just compile the Lua run time engine into JavaScript! http://kripken.github.io/lua.vm.js/lua.vm.js.html

    JavaScript can run at speeds approaching that of C code compiled to native binary. Lua though is substantially slower: http://flux242.blogspot.fi/2013/09/javascript-vs-perl-vs-python-vs-lua.html
  • Heater.Heater. Posts: 21,230
    edited 2015-02-24 19:42
    Looking at how one might write a web server in Lua I find this:
    local http = require('luanode.http')
    
    http.createServer(function(self, request, response)
       response:writeHead(200, {["Content-Type"] = "text/plain"})
       response:finish("Hello World")
    end):listen(8080)
    
    console.log('Server running at [url]http://127.0.0.1:8080[/url]')
    
    process:loop()
    
    Compare to JS version:
    http = require("http");
      
    http.createServer(function(request, response){  
        response.writeHeader(200, {"Content-Type": "text/plain"});    
        response.end("Hello World");  
    }).listen(8080);  
    console.log("Server running at http://127.0.0.1:8080");   
    

    Amazingly similar!

    I think I'll be sticking with JS.
  • Heater.Heater. Posts: 21,230
    edited 2015-02-24 19:54
    msrobots,

    Sure you have tried a functional language. JS is a functional language. As is Java since version 8 I believe.

    Although terms like "functional language" and "functional programming" seem to mean many different things depending on who you speak to.

    It's probably worth getting into a real "pure functional" language like Haskell to experience the rigour of the functional approach. That is somewhere on the end of my TODO list.
  • ElectrodudeElectrodude Posts: 1,658
    edited 2015-02-24 21:24
    msrobots wrote: »
    JavaScript has some weird things going on. But to get a 'truetrue' you need to start with 'true' as string not value. So 'true' + 'true' == 'truetrue' . Same in most other common languages. The need for two different operators like in lua is more cosmetic in my opinion. Or a parser thing. But basically it is a definition how it should behave. Concat strings and add numerical values.

    That true + function(){} equals truefunction(){} is funny. Never tried that.
    That is probably my #1 problem with JS.
    No languages is superior to any other as like no race is superior to any other. This is BS.

    Every language has its place in the universe.
    Algol can still do things easy where you will fight in C/C#/C++.
    Basic (not Visual...) is still easy to understand for a newbie.
    C/C#/C++ are quite versatile, but not easy to understand..
    COBOL is still used in systems doing a lot of batch processing (banks/insurance/usps/military) .
    nothing with D
    Erlang is - well - interesting.
    FORTRAN, F# - hmm - never really tried functional languages but the concept is quite different.
    ...
    the list is long and I used many of them in my life. The right tool for the right job.

    Is a Phillips screw driver superior over a flat one? What if you need a flat one? Or vice versa?

    The same applies for languages and operating systems.
    I agree. I hate C++ with a passion and yet I'm writing a compiler from scratch in it right now. One cannot say whether Lisp, OCaml, or Haskell is better than C/C++ (Oh boy - a dangerous statement) - higher level languages are easier to program in but usually much less efficient. Different programming paradigms are better for different people and projects. I prefer Gentoo Linux (probably one of the hardest to use of all distros), but I would recommend OSX to anyone buying a computer who's not a computer programmer or who prefers a more graphical environment (i.e. doesn't live in a terminal).

    However, Lua has pretty much all the same features JS has, except that it implements them better. At first glance, the only differences between Lua and JS are that Lua has Basic syntax and JS has C syntax, and JS differentiates between tables and arrays while Lua doesn't (explicitly). However, when you dig deeper and find that Lua has features critical for event-driven and secure systems, like coroutines and sandboxable function environments, as well as other useful features like sensible and consistent comparison and operator overloading, that JS is somehow missing. Lua isn't even a proper OO language, and yet I prefer doing OO in Lua over JS because it's very easy to write a OOP library

    Heater. wrote: »
    We can say that true is represented by 1 in JS, ergo, true + 1 == 2, and true + true = 2. That makes some sense does it not?
    Then why not use 1 instead of true?
    JavaScript can run at speeds approaching that of C code compiled to native binary. Lua though is substantially slower: http://flux242.blogspot.fi/2013/09/javascript-vs-perl-vs-python-vs-lua.html

    That comparison is horribly unfair. They used node, which does JIT, but not LuaJIT?
  • TorTor Posts: 2,010
    edited 2015-02-25 01:27
    I've looked at Lua now and then. I've not been able to find anything that sticks out as something that makes it a better candidate than anything else. So I'm a bit surprised by the praise I've seen here and there over the years.
    Just now I took a look at the wiki at lua-users.org where they compare it with Perl - which is a tool I know very well and use a lot - I know that Heater doesn't like Perl but some of us do like Perl. Well, what do you know, Lua's own wiki couldn't come up with a single real reason for why Lua would be better than Perl. And then there are the other contenders. So I still don't know what Lua is better for.

    -Tor
  • Martin_HMartin_H Posts: 4,051
    edited 2015-02-25 03:37
    @Electrodude, remember the old saying: "lies, damn lies, and benchmarks".
  • KeithEKeithE Posts: 957
    edited 2015-02-25 13:27
    Tor - this isn't really directly related to the language itself, but is Lua perhaps easier to embed and sandbox than Perl? I know it's used as a scripting language in a number of video games.
  • Heater.Heater. Posts: 21,230
    edited 2015-02-25 14:37
    KeithE,

    Good point.

    There is the language, it's syntax and semantics. Then there is the implementation.

    JavaScript was for a long time regarded as a slow and useless interpreted language. Now it's nearly as fast as writing native C code.

    Lua is cool because the implementations make it dead easy to embed in other C/C++ programs, like game engines.

    One big question is "how can I say what I want to happen, and have it happen. With the least amount of friction?"

    That question pulls in all the implementation details.

    For example. I quoted a webserver in Lua in a recent post here. Turns out that actually installing everything you need to make that work is a huge pile of effort.

    I was looking toward benchmarking a node.js server vs a luajit server. But no, I don't have time for that.
  • TorTor Posts: 2,010
    edited 2015-02-25 19:06
    KeithE wrote: »
    but is Lua perhaps easier to embed and sandbox than Perl?
    I think that's exactly the one thing Lua has got. It's small and easy to embed. On the desktop it doesn't have any edge as far as I can tell.

    -Tor
  • msrobotsmsrobots Posts: 3,709
    edited 2015-02-26 00:51
    just stumbled over this. Not much to find about Grace Hopper.

    http://espn.go.com/video/clip?id=12205119

    Enjoy!

    Mike
  • Heater.Heater. Posts: 21,230
    edited 2015-02-26 01:07
    Can't enjoy. That vid won't play here. Except the stupid Treehouse commercial at the beginning.

    We should be specific when we talk of embedding a language like Lua.

    We are not talking embedded systems as understood in our micro-controller world.

    We are talking embedding a scripting language into an otherwise compiled application. Like the Emacs editor has elisp, Qt based apps might use QML (JavaScript), games often use Lua I have heard.

    Lua has been used in actual embedded systems though. Interestingly the guys who made the Electric Imp (WIFI internet connectivity in an SD card form factor) built the the thing with Lua and then at the last moment changed to some other language because Lua was too hungry for memory. I forget what they ended up using. https://electricimp.com/
  • msrobotsmsrobots Posts: 3,709
    edited 2015-02-26 01:18
    Heater. wrote: »
    Can't enjoy. That vid won't play here. Except the stupid Treehouse commercial at the beginning....

    Who is censoring your internet? Will try over Remote desktop from a server in Germany to check.

    Told you a couple of times now to get over here. North Cal or South Cal, Does not matter. San Jose is as fine as Rocklin. No snow here.

    Enjoy!
  • Heater.Heater. Posts: 21,230
    edited 2015-02-26 01:50
    OK it finally started to play here. Great vid. Now, where can I get myself a processor that is big enough to live in?
  • mindrobotsmindrobots Posts: 6,506
    edited 2015-02-26 06:55
    eLua anybody??

    You probably even have a board sitting around to run it on. If not, you can pick up one of the STM32F4 boards for under $20 or the NXP mbed for about the same.

    So for the cost of night at the Pub, you can start playing with a new language...and if you can't find Yet Another Fine Language to try on a microcontroller, what's the point of doing any of this?? :o)
  • Heater.Heater. Posts: 21,230
    edited 2015-02-26 07:02
    eLua looks cool. And I just happen to have an STM32F4 Discovery here...thanks for that suggestion.
  • mindrobotsmindrobots Posts: 6,506
    edited 2015-02-26 08:23
    Heater. wrote: »
    eLua looks cool. And I just happen to have an STM32F4 Discovery here...thanks for that suggestion.

    I was pretty sure you had one of those Discovery boards sitting around. I also thought you wouldn't mind eLua since it doesn't start with 'P' or look like Forth! :o)

    You need one of these arminarm boards to sit on top of your RasPi - it lets you play with Espruino and eLua and other stuff all hosted by your Raspberry Pi!!
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2015-02-26 09:19
    I recently purchased a Canon Elph 110 HS digicam for use on the floating ROVs the kids in my class are designing. I installed CHDK (Canon Hacker's Development Kit), which allows me to script the camera in both uBASIC and Lua. So far, I've only used uBASIC. But Lua is faster and seems to have a more complete interface to the camera's functions.So I may need to come up to speed with it soon.

    With either language, one is able to adjust the camera's settings, to take pictures under program control or via pulsing 5V to the USB power input, to log data to text files on the SD card, to display text in the viewfinder, and to flash the camera's LEDs. CHDK seems to be popular with the UAV and KAP crowd. There's a lot of info on the web, but you really have to dig to find some of it. 'Should be an interesting ride!

    So far, I've modified a sample uBASIC script to set the zoom, then take pictures at 15-second intervals. I put the camera in a transparent watertight box, along with a couple lasers (which will be used to measure depth) and floated it over some shallow water next to my kayak. Here's one of the photos (wrong year programmed in):

    attachment.php?attachmentid=113280&d=1424971092

    'Still MUCH to do before semester's end ...

    -Phil
    800 x 600 - 63K
  • mindrobotsmindrobots Posts: 6,506
    edited 2015-02-26 09:37
    Cool pictures, Phil!! (and a great project for us to follow) It looks like the Canon in a box is working well.

    I'm curious how deep the shallow water is?

    Was this taken in the target area you showed us a map of a while back? (the one with the "sail up" bar?)

    They are quite clear, that's why I'm curious about the depth and location. Very little sediment and since I don't think you've gone to the Caribbean, I'm assume relatively shallow. :O)
  • Heater.Heater. Posts: 21,230
    edited 2015-02-26 09:54
    @Phil,

    That's a great project. Looks like a lot of fun.

    @midrobots,

    Drats, you are right. Arminarm is a very neat looking board. I'm kind of hoping eLua can be made to run on my Espruino boards. Then we can compare with JS on there.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2015-02-26 15:32
    mindrobots wrote:
    I'm curious how deep the shallow water is?
    In the above photo, probably less than two feet. The lasers are about 100mm apart. They're not very well collimated yet, so the beams aren't exactly parallel, which they have to be to get an accurate read on the depth. The maximum target depth is 10 feet. I'm not sure these Class IIIa red lasers are up to the task. I'm going to try a green laser that's coming from Sparkfun to see if I get better water penetration.
    Was this taken in the target area you showed us a map of a while back? (the one with the "sail up" bar?)
    Heh, no. This was taken just outside of the other marina in town where I keep my kayak. It's maybe a mile or two northeast of the bar.

    BTW, I gave the kids some heavy math homework today (attached). I'd be curious how some of our forumistas fare with it and -- more importantly -- whether my formulae are correct. :)

    I probably ought to start a separate thread with this project. I only posted here because the subject of Lua came up.

    -Phil
  • mindrobotsmindrobots Posts: 6,506
    edited 2015-02-26 16:33
    I read through the homework! I'm glad I'm just auditing! :0)

    I had assumed the camera was submerged the pictures are even more impressive since you are shooting above the surface.
  • Heater.Heater. Posts: 21,230
    edited 2015-06-05 02:18
    Here is a good joke:

    What's the difference between JavaScript and Java?

    One is essentially a toy, designed for writing small pieces of code, and traditionally used and abused by inexperienced programmers.

    The other is a scripting language for web browsers.

    http://stackoverflow.com/questions/245062/whats-the-difference-between-javascript-and-java/245073#245073
  • Heater.Heater. Posts: 21,230
    edited 2015-08-06 21:35
    Not your father's Javascript.

    We now have a new JS standard, ES6. It enables one to write code that does not look like JS at all. I was hit by this when I realized my latest JS creation has no functions, no loops and no variables! WTF?

    There are a lots of nice new features in ES6. It includes a syntax for classes which seems to be a carrot for Java programmers who think that OOP is a good idea. I'm not sure if I like that development or not.

    Anyway here is an example of a modern JS program with some comments about some of the new JS features:
    // A module system that also works in the browser
    import React from 'react';
    
    // Classes with inheritance and decorators.
    @someDecorator
    class Floater extends React.Component {
    // Constructors
    constructor(props) {
    super(props);
    this.state = {counter: 0};
    this.style =  {
    position:   'fixed',
    top:        '300px',
    left:       '50px',
    zIndex:     '10',
    background: '#1c1e22';
    };
    }
    
    componentWillMount () {
    // Don't use "function" use "fat arrows"!
    setInterval (() => {
    // Fat arrow functions ensure "this" works, no need for "self" or "bind". Yay!
    this.state.counter += 1;
    console.log(this.state.counter);
    }, 1000);
    }
    
    render() {
    // Use "let" or "const" instead of "var" for proper scoping
    const listElements = [ ];
    this.props.people.map((person, index) = <{
    listElements.push(Name: {person.name} Age: {person.age});
    }>);
    return (
    // OK this is not ES6 but is preprocessed by react's JSX
    <div>
        <div>{this.state.counter}</div>
        <ul  className='floater well' style={this.style}>
            {listElements}
        </ul>;
    </div>
    );
    }
    }
    
    const people = [
    {name: 'Fred',   age: 20},
    {name: 'Bert',   age: 22},
    {name: 'George', age: 30}
    ];
    
    // Enhanced Object Literals means no more {people: people} and other good things.
    const element = React.createElement(Floater, {people});
    
    // We are not in the browser here so render component to HTML string
    const str = React.renderToString(element);
    console.log(str);
    
    // Export symbol from this module
    export default Floater;
    
  • Heater.Heater. Posts: 21,230
    edited 2015-08-06 13:06
    For anyone remaining who may think that Javascript is slow take a look at this:

    http://arstechnica.com/security/2015/08/dram-bitflipping-exploit-for-attacking-pcs-just-add-javascript/

    From the article:
    We found that JavaScript performance for our test program is close to our native g++ -O3 compiled code.

    Of course in this case such performance may be a liability...
  • This is progress?
  • Heater.Heater. Posts: 21,230
    edited 2015-08-06 17:29
    Martin,
    This is progress?
    Please elaborate. Which part of the story do you mean?
Sign In or Register to comment.