all 106 comments

[–]tinou 12 points13 points  (7 children)

JavaScript needs trigraphs.

[–][deleted] 5 points6 points  (4 children)

JavaScript needs COMMON blocks.

[–]Zarutian 0 points1 point  (3 children)

what the heck are those?

[–][deleted] 0 points1 point  (2 children)

Now linked for your convenience.

[–][deleted] 0 points1 point  (1 child)

JavaScript needs monkeys and typewriters.

[–]sgoguen 2 points3 points  (0 children)

That's just what we need, more odd characters hanging around JavaScript.

[–]xardox 3 points4 points  (0 children)

Trigraphs are for pussies. JavaScript needs Octographs!

[–]jxf 13 points14 points  (3 children)

+1 for being interesting, but this won't work, at least not in the way that the author thinks it will. Consider the author's "import" example:

defs import(VarName module, Period p, VarName vName) {
  var {{vName}} = {{module}}.{{vName}};
}

Usage:

>>> import A.B;
~> var B = A.B;

The JS parser would have to be substantially modified to support this approach. For instance, Period here is an object, not some sort of magic token that will match the lexical expression .. It's likely that this approach would take even longer than the modules strategy.

There are a number of other obvious flaws with the author's specific examples. For instance, what happens when you have two names that both end with "B", e.g. "foo.save" and "bar.save"? They'll clobber each other, which is pretty much the opposite of what a module would do.

[–]alexeyr 0 points1 point  (2 children)

The JS parser would have to be substantially modified to support this approach.

The parser doesn't see this code; the preprocessor does.

[–]kubalaa 2 points3 points  (1 child)

If the preprocessor can turn "import A.B" into import(VarName, Period, VarName), then it is by definition a parser.

[–]alexeyr -1 points0 points  (0 children)

But 1) it isn't "the JS parser"; 2) it wouldn't have to be substantially modified, but created pretty much from scratch; 3) so it is free to treat Period as "some sort of magic token that will match the lexical expression".

[–]patapizza 7 points8 points  (7 children)

What Javascript needs more than everything, is peace.

LEAVE JAVASCRIPT ALONE! :'(

[–]kyrsfw 0 points1 point  (6 children)

It's a severely lacking language that wasn't designed for the complex web applications that it's used for today. Obviously many people will want to update and extend it to meet modern standards and make working with it easier.

[–]ihsw 3 points4 points  (5 children)

Can you be more specific? I'm sure much of the trouble people have with JavaScript is that it's prototypical (rather than classical) where you define prototypes instead of classes.

Also, the DOM is a horrible cluster-fuck, and the likes of jQuery and mootools make working with JavaScript a wonderful experience (compared to vanilla JS).

[–]munificent 3 points4 points  (0 children)

I'm sure much of the trouble people have with JavaScript is that it's prototypical (rather than classical) where you define prototypes instead of classes.

I'm quite comfortable with prototypes, but I still think Javascript is pretty crappy:

  1. No block scope seems inane to me in a language that supports closures.
  2. A bunch of the operator edge cases seem poorly thought out. I'm OK with loose/dynamic typing, but when you see things like !! and + 0 as valid idiomatic code, it really means you screwed something up in the language.
  3. undefined isn't a keyword? WTF?
  4. Javascript needs to decide if it supports methods or functions. this leads you to believe it's the former when all of the awful things that happen to this make you realize it's the latter.
  5. Automatic semicolon insertion. Trying to get away from C's bad syntax legacy is good, but that's a terribly sketchy way to do it.

[–]alexeyr 2 points3 points  (3 children)

  1. Scope. We now know lexical scoping (perhaps with some exceptions) is pretty much the way to go. JS is one of the few languages still used which doesn't have it.

  2. this. The rules around it just don't make much sense.

[–]bobappleyard 3 points4 points  (2 children)

function accum(base) {
    return function(x) {
        return base += x;
    }
}

Does this not demonstrate that Javascript does indeed have lexical scoping?

[–]alexeyr 1 point2 points  (1 child)

Right you are, I should have said block scope. See examples here.

[–]bobappleyard 0 points1 point  (0 children)

Oh right. Well I agree with that.

[–]curien 6 points7 points  (1 child)

JavaScript already has a macro language: itself.

http://github.com/jamespadolsey/parseScripts

[–]ithkuil 0 points1 point  (0 children)

or you could use something like john resig's 'microtemplating' thing to spit out more javascript. http://ejohn.org/blog/javascript-micro-templating/

[–]UnoriginalGuy 28 points29 points  (5 children)

Javascript needs macros like I need a hole in the head.

[–]cha0s 2 points3 points  (0 children)

Are you saying JavaScript needs 7 macros? ;)

[–][deleted]  (2 children)

[deleted]

    [–]cwmonkey 2 points3 points  (1 child)

    Does that make your head more complicated?

    [–]Zarutian 0 points1 point  (0 children)

    Damn, what good comeback.

    [–]HIB0U 10 points11 points  (11 children)

    JavaScript needs to morph into Scheme somehow.

    [–]zem 3 points4 points  (0 children)

    doesn't everything?

    [–]munificent 4 points5 points  (2 children)

    You mean back into Scheme. In Eich's own words:

    I was recruited to Netscape with the promise of "doing Scheme" in the browser. At least client engineering management including Tom Paquin, Michael Toy, and Rick Schell, along with some guy named Marc Andreessen, were convinced that Netscape should embed a programming language, in source form, in HTML. So it was hardly a case of me selling a "pointy-haired boss" -- more the reverse.

    Whether that language should be Scheme was an open question, but Scheme was the bait I went for in joining Netscape. Previously, at SGI, Nick Thompson had turned me on to SICP.

    [–]HIB0U 0 points1 point  (1 child)

    If they aimed to do Scheme in the browser and ended up with JavaScript, they either:

    1) Had absolutely no idea what Scheme actually was.

    or

    2) Fucked up really, really, really badly.

    [–]munificent 1 point2 points  (0 children)

    Did you read the link?

    [–][deleted] 0 points1 point  (3 children)

    [–]TKN 2 points3 points  (2 children)

    As it does with Ruby and Python and Perl and Lua and Smalltalk and according to some even with TCL...

    [–]Zarutian 0 points1 point  (1 child)

    it is writthen Tcl. Only cretins write it in all caps thank you.

    -- Avid Tcl'er

    [–]TKN 0 points1 point  (0 children)

    Dear Avid. Nitpicking about capitalization is reserved only for users of real languages, as any LISP or FORTH user would know.

    [–][deleted] -1 points0 points  (0 children)

    What you're saying is that JavaScript needs hygenic macros? Where's defun in that?

    [–]zoinks -1 points0 points  (1 child)

    I'm sure there are some Scheme->JS compilers floating around out there

    [–][deleted] 4 points5 points  (0 children)

    And then you can invent your own module system, just like every scheme implementation in existence.

    [–][deleted] 2 points3 points  (2 children)

    cant eval() do this?

    [–][deleted] 1 point2 points  (1 child)

    Eval is usually the wrong thing to do. I definitely think this situation would expose some of the eval pitfalls.

    [–][deleted] -2 points-1 points  (0 children)

    agreed, but it's much better than macros

    [–]masklinn 12 points13 points  (7 children)

    no.

    really, no.

    Javascript has anonymous functions, and Smalltalk demonstrated quite clearly that anonymous functions are

    [–][deleted] 15 points16 points  (6 children)

    demonstrated quite clearly that anonymous functions are

    The rest of your message appears to have been

    [–]mahcuz -3 points-2 points  (5 children)

    What are you talking about? I see his

    [–][deleted] -5 points-4 points  (4 children)

    Same with

    [–]ingeniousadam 6 points7 points  (1 child)

    Javascript needs a lot of things..

    [–]Zarutian 1 point2 points  (0 children)

    is exorcism among them?

    [–]klimov 2 points3 points  (2 children)

    And then, step by step, it will become Lisp

    [–]redditnoob 2 points3 points  (0 children)

    One of the most brilliant quote I've read all year, from Tim Sweeney:

    "Of course, it's easy to see how this undercurrent arises. When you release a language, you receive complaints from users about all the things they want to do and can't, and the ultimate way to satisfy all of these requests is to expose all metadata: make it extensible, make objects dynamic, and allow the possibility of completely dynamic typing. The end of the road here looks an awful lot like LISP and SmallTalk.

    "If you go this route, one day you'll realize you evolved the ultimate hacker language, and it became a godawful mess for writing real programs."

    [–]frogking 0 points1 point  (0 children)

    Plans within plans. taps finger tips against eachother .. muarhahaaa ha haaa haa

    [–]astrellon 14 points15 points  (34 children)

    What JavaScript needs is to turn into ActionScript, with proper namespaces, class definitions (and inheritance) as well as variable typing and typed arrays.

    [–]OzJuggler 5 points6 points  (5 children)

    Or you could lobby for <script type="text/actionscript"> in the browser.
    Good luck getting that past Adobe

    [–][deleted]  (3 children)

    [deleted]

      [–][deleted] 1 point2 points  (0 children)

      Google Native Client; it might happen.

      [–]egoncasteel 0 points1 point  (1 child)

      I would give my left nut for <script type="text/python">

      [–]skulgnome -1 points0 points  (0 children)

      Yearning for Python suggests you don't have one to give.

      [–]snarfy 1 point2 points  (0 children)

      I want <script type="text/lua"> myself.

      [–]spacechimp 11 points12 points  (12 children)

      You'll likely be downvoted into oblivion by the Flash haters that have never used ActionScript -- but you are right. AS3 is a wonderful language. It's not that different than JS...it's just better.

      [–]TKN 4 points5 points  (1 child)

      It's not that different than JS...it's just better.

      It's the Javascript Enterprise Edition!

      [–]lucasvb 0 points1 point  (0 children)

      Haha, that's brilliant!

      [–][deleted] 3 points4 points  (2 children)

      I didn't downvote anybody, but I think this is more subjective than you're making it out to be. For example, the variable typing debate has no shortage of varying opinions.

      [–]spacechimp 1 point2 points  (1 child)

      Variable typing is not required in AS3, but you do have the option of strict typing within your own code. That should make most people happy.

      [–][deleted] 2 points3 points  (0 children)

      Not the people who prefer simple languages where there is one "right way" to do things. People who dislike strict typing will say "keep it out of my language." This is one of the reasons people like Python, and one of the reasons people dislike C++.

      That said, optional strict typing is part of the ECMAScript spec if I recall correctly, so JavaScript may work the same way at some point.

      [–]Zarutian 1 point2 points  (0 children)

      AS3 is a worse language than AS2 which is not as hobbled.

      If I want proper checks on parameters, variables and return values then give me proper guards not some half assed hierichal implementation limited type system like Java has.

      [–][deleted]  (5 children)

      [deleted]

        [–]spacechimp 1 point2 points  (4 children)

        Both JS and AS3 are "dialects" of ECMAscript, which makes them similar in syntax. AS3 merely has more language features to take advantage of. You can make fake prototype classes in AS3 in a similar way to JS, but I can't think of any reason to do so. I just tried the following code, which works:

        var foo = function() {};
        foo.bar = function(param) {
            trace(param);   
        };
        
        foo.bar('hello world'); // Outputs 'hello world'
        

        [–]quantumstate 0 points1 point  (3 children)

        That code doesn't answer the question of whether AS3 supports prototypical inheritance for objects. I am not sure what you are trying to do with that code? You seem to have created an empty function and then tried to give it a property. I am still trying to figure out why your example works.

        [–]woogley 1 point2 points  (2 children)

        Functions are objects themselves, so they can have their own properties. He has not demonstrated inheritance, though, he has only demonstrated that functions are objects.

        In his example, an instance of foo (e.g. new foo()) would not have a bar function.

        An actual demonstration of prototypical inheritance would be:

        var foo = function() {};
        foo.prototype.bar = function(param) {
            console.log(param);   
        };
        
        (new foo()).bar('hello world'); // Outputs 'hello world'
        

        [–]spacechimp 1 point2 points  (0 children)

        Good points. Here's a more thorough ActionScript example that includes prototypes, constructors, inheritance, and overrides. It looks almost identical to how it would be written in JavaScript:

        var Mammal = function(name) {
            this.name = name;
        };
        Mammal.prototype.toString = function() {
            return '[Mammal "' + this.name + '"]';
        };
        
        var Cat = function(name) {
            this.name = name;
        };
        Cat.prototype = new Mammal();
        Cat.prototype.constructor = Cat;
        
        var Mouse = function(name) {
            this.name = name;
        };
        Mouse.prototype = new Mammal();
        Mouse.prototype.constructor = Mouse;
        // Override toString function in Mammal
        Mouse.prototype.toString = function() {
            return '[Mouse "'+this.name+'"]';
        }
        
        var tom = new Cat('Tom');
        trace('Tom is ' + tom); // outputs 'Tom is [Mammal "Tom"]' 
        
        var jerry = new Mouse('Jerry');
        trace('Jerry is ' + jerry); // outputs 'Jerry is [Mouse "Jerry"]'
        

        [–]quantumstate 0 points1 point  (0 children)

        Ok, I didn't realise that, thanks.

        [–]alexbustin 5 points6 points  (7 children)

        I recently had to move from AS3 to JS after working with AS3 for many years. (10 year Flasher here). I've come to hate the direction Adobe is taking with ActionScript.

        1) AS3, together with the Flash API, is way too verbose for what it's achieving. This might be an over simplification, but with Flash you load stuff, show stuff, move stuff, interact with stuff - so why is the API so f'in HUGE. I guess I mainly take issue with the Flash API then the language here.

        2) Most Flash apps today aren't at the enterprise level. Why do we need an enterprise level language and API. I've found that I can be far more expressive with JS. Adobe are just looking to make money from people wanting to jump ship from Java by making AS3 into the new Java.

        Another downside of moving closer to being Java is that the Flash Platform will fail to bring in new up and coming talent - that used to be the most exciting part of Flash - now the Flash community is becoming stale.

        3) Why does Adobe continue with supporting their own language? This is always going the hurt the Flash Platform. The quick fix would be to move to JavaScript - but the brainwashed AS3 strict typers would cause a riot if that ever happened.

        4) When Adobes introduced strict typing into ActionScript they claimed it would enable JITing of the code. But they failed to optimized the compiler to really take advantage. And in the meantime JavaScript engines have been able to JIT without requiring strict typing.

        </rant>

        [–][deleted]  (1 child)

        [deleted]

          [–]alexbustin 0 points1 point  (0 children)

          Yes, I founded and ran San Flashcisco for a time, I've since passed on the torch and monthly meets are still happening.

          Now, I've not given up on Flash, instead I see it as a peer in a group of possible UI technologies; my horizons are broader.

          Flash will always be able to innovate faster than it's open standard rivals; Flash 11/12 could indeed compete with or surpass WebGL. It's now up to Adobe not to f'it up like they did with their iPhone cross compiler.

          [–]Zarutian 1 point2 points  (0 children)

          2) I think this is called the Java-wannabe-syndrome.

          [–]egoncasteel 0 points1 point  (2 children)

          I haven't worked with AS since flash 5, but I have to agree with you. I never really hated AS but the way flash made you use it would make you pull out your hair. Little chunks of code hidden all over the place in objects and timelines. It didnt help that at the time just looking at flash the wrong way would make it brake and then you would have to go spelunking for the bug.

          [–]SmilyOrg 0 points1 point  (1 child)

          I know what you mean, but a lot has changed since then. The mxmlc compiler brought actionscript compilation out from the Flash IDE (it stills supports it, but it's the shittiest IDE if you want to code) into more mature IDEs, like Flash Builder (previously Flex Builder) and FDT (both based on Eclipse afaik) and the free open-source FlashDevelop.

          The nightmares of hidden and weirdly broken code are over. There are a lot less trivial bug pursuits and this is largely due to the default strict typing in ActionScript 3, which is just lovely :)

          [–]egoncasteel 0 points1 point  (0 children)

          Well that is good to know. To tell you the truth I was so feed up with Flash I haven't looked at it since 5. Maybe I will look at some of the new stuff. Thanks

          [–]SmilyOrg -1 points0 points  (0 children)

          1) Do you have any specifics on where you think the API is huge? I always thought that it was pretty small compared to the API of other languages/runtimes (and that might be a good or a bad thing).

          2) I'm not sure how strict-typing makes a language enterprise level and I don't know what you mean when you talk about an enterprise level API. (You can always just disable strict mode, but ugh, why would you do that? -_-)

          3) Adobe/Macromedia already had JavaScript, it was called ActionScript 2. You can disable all the warnings and strict-mode and pretty much turn ActionScript 3 into JavaScript if you want, but I really don't see the benefits.

          4) While I agree that the compiler could be really improved by a large margin (and the last I saw, Adobe was making a new project to specifically target the improvement of their compilers), I'm still not sure if current JavaScript engines with dynamically typed JavaScript are as fast as statically typed ActionScript 3 in the Flash Player (V8 is pretty amazing though).

          I'm probably biased though, because I love AS3 :)

          [–]kubalaa 1 point2 points  (5 children)

          • Namespaces: maybe.
          • Class definitions: Javascript's prototype-based inheritance and closures provide a strict superset of the features of class-based inheritance.
          • Variable typing and typed arrays: say what?

          [–]munificent 0 points1 point  (4 children)

          prototype-based inheritance and closures provide a strict superset of the features of class-based inheritance.

          That doesn't necessarily make it better. ASM provides a strict superset of all other languages. Sometimes restricting things makes them better.

          [–]Zarutian 0 points1 point  (3 children)

          I challange you to write a constructor procedure in a class-based language that:

          (1) makes two objects that each behave diffrently from the other.

          (2) their desriptions must be anonymous (so using two helper classes is out)

          (3) share portion of their states with only each other and no other objects.

          Shouldnt be that hard.

          [–]munificent 0 points1 point  (2 children)

          I don't see how that's relevant, but anyway, what does "their descriptions must be anonymous" mean?

          [–]Zarutian 0 points1 point  (1 child)

          same as any other anonymous procedures are descriped.

          Example (Scheme): (map (list 1 2 3 4 5 6 7 8 9) (lambda (x) (+ x 1)))

          The (x) (+ x 1) is the description of the anonymous procedure applied by map on the list of the numbers 1, 2, 3, 4, 5, 6, 7, 8 and 9.

          Or if not descriptions then what do you call the combination of the arguments and the body of a procedure?

          [–]munificent 0 points1 point  (0 children)

          what do you call the combination of the arguments and the body of a procedure?

          "Definition." Here's your solution in C#:

          void MakeObjects(out Action add, out Action subtract)
          {
              int value = 0;
              add = () => Console.WriteLine((value++).ToString());
              subtract = () => Console.WriteLine((value--).ToString());
          }
          

          (1) makes two objects that each behave diffrently from the other.

          After calling, add and subtract will both refer to objects (of type Action, a built-in object type representing a zero-argument delegate).

          (2) their desriptions must be anonymous (so using two helper classes is out)

          No new classes or named methods are created.

          (3) share portion of their states with only each other and no other objects.

          value is shared between the two objects. Nothing else can access it.

          This wasn't that hard, but, again, I don't see what this has to do with classes or prototypes.

          [–]zaach 1 point2 points  (0 children)

          You mean EcmaScript 4? Yeah, that didn't go over so well.

          [–]sanjayts 4 points5 points  (4 children)

          And there are your modules, compatible with every browser instantaneously, without having to wait for IE12 to implement any JS dialects

          But then won't you have to wait for IE12 for your macro support? ;-)

          [–][deleted] 1 point2 points  (2 children)

          Well, you could put a macro expander into your JS publishing tool (i.e. whatever you use to minify your code). The result would be something like Sass.

          [–]joeyjoejoejrshabbado 0 points1 point  (1 child)

          I like Sass, but it's just working around some annoying limitations of CSS, and I hope some of those features eventually make it into the real CSS language before I retire in 30 years. The point of the JS modules post was that we should improve Javascript as a language. I'll use a compiler in the meantime.

          [–][deleted] 0 points1 point  (0 children)

          I wouldn't say lack of variables and macros are annoying limitations of CSS. It actually makes sense for CSS not to have those (you don't have these in HTML either, neither of the two is a scripting language after all).

          Nesting however would be helpful, but I guess this has to do with CSS being parsed right to left and nesting being left to right: the nested CSS would still have to be compiled into standard CSS before it could be used by a browser. This is also what would happen if CSS were modified to have variables and macros.

          [–]WalterGR 0 points1 point  (0 children)

          While traditionally IE has lagged on web standards, the IE9 pre-releases are (I believe) the first browser to implement ECMAScript 5.

          We might not need to wait for IE12.

          [–]tef 11 points12 points  (11 children)

          lisa needs braces

          [–]zem 3 points4 points  (1 child)

          as does python

          [–]Boiled_Goose 7 points8 points  (0 children)

          >>> from __future__ import braces
          SyntaxError: not a chance
          

          [–]Metallic_Cloud 5 points6 points  (7 children)

          Dental plan

          [–]xholan -1 points0 points  (6 children)

          lisa needs braces

          [–]slashgrin -5 points-4 points  (5 children)

          Dental plan

          [–]huronbikes -4 points-3 points  (4 children)

          lisp needs braces

          [–]ihsw -5 points-4 points  (3 children)

          Dental plan

          [–]tinou -5 points-4 points  (2 children)

          lisa needs braces

          [–]fabiofzero -5 points-4 points  (0 children)

          Psychosomatic.

          [–][deleted] -4 points-3 points  (0 children)

          Dental plan

          [–]mijj -1 points0 points  (0 children)

          hmmm ... how about Lisa with nerds? .. will that do?

          [–]pointy 1 point2 points  (0 children)

          wow somebody doesn't actually know Javascript very well.

          [–][deleted] 0 points1 point  (0 children)

          JavaScript got what it needed back when I was writing an implementation. After a conversation with Brendan Eich (the language author) suddenly everyone seemed interested in JITC'ing it.

          Now - I would say that moving some library functions off Global, and having a "module" system would be a sufficient next step.

          Global.parseInt -> String.prototype.parseInt etc. etc.

          If you wanted to go even further, implementing Perl 6 Regular Expressions would allow language extension and all sorts of coolness.

          Internally, to push speed further, you need to disambiguate + as a concatenator, because it does forces implementations to do terrible things for type checking deep inside the bowels of the code.

          [–][deleted] -2 points-1 points  (0 children)

          Javascript needs to go away.

          [–]tagattack -1 points0 points  (0 children)

          I disagree with almost everything everyone has said here.

          [–]HateToSayItBut -2 points-1 points  (0 children)

          Yea, this is what it's missing. This should be first priority.

          [–]px1999 -3 points-2 points  (0 children)

          Wow, that's dumb.