Is JavaScript , ok ?

Well there certainly are mistakes in its design. And since it came to be, out of pure accident, or luck, it could be much worse, that’s for sure. By far the worse mistake being its name.

But… nothing is more expressive then short and sweet JavaScript. I defy any C# “afficionado” to show me parallel to this, in her favourite language ;o)
[sourcecode lang=”jscript”] if ("function" !== typeof "".minus)
String.prototype.minus = function( what_ ) {
///<summary>
/// "ABCBDBEB".minus("B"), returns : "ACDE"
/// Argument is optional, by default it is one space char
/// myText.minus(), returns myText without spaces
/// argument can be an regular expression
/// reg.exp. given does not require ‘g’ or ‘m’ modifier
/// if argument is not found in the original, the original is returned
///</summary>
return (this.split(what_ || " " )).join( "" ) ;
}
[/sourcecode] This little nugget, can be talked about on more “levels” than one. But, you will not be reading this if you would need this explained in a greater detail, would you?

–DBJ

3 Replies to “Is JavaScript , ok ?”

  1. public static string minus(this string thestring, string what) {
    return thestring.Replace(what ?? ” “, “”);
    }

    But that is pretty much meaningless: you could take any language and create a sample that is very well-suited to that particular language and that would be difficult to recreate in other languages. For C#, that could be a Linq-based example.

  2. Oh wait, actually, this is even closer to your sample code:

    public static string minus(this string thestring, string what = ” “) {
    return thestring.Replace(what, “”);
    }

  3. @Bertrand, Thanks for your comment, but. I am confused ?

    Instead of imitating already not so good language, aka: Java. And still not finishing the job in 10+ years, Andreas H., could design and implement something better, I think. I also think this is not his fault. He was given the highly politically motivated “order”, instead of the “clean sheet” and high degree of freedom. The “order of the day” (in 1998?) was to find and develop Sun Java & JVM “killer”. Which thankfully has been done.

    Now we can perhaps admit, that we clearly see now, that at those “feverish decision making times”, someone has decided that JavaScript was also an obvious contender, and in the same time JScript.NET was born. Only to be forever kept in the realm of the command line. Far from the headlines and centre stage of the VisualStudio, given to C#.(and sometimes VB.NET).

    But this kind of “we will simply declare it as the best” attitude is curiously, present inside Apple, too.
    The only major software developer using “Objective-C” as its “flasgship” programming language. The official language of the OS-X API. Which was and is,built on C++ ?

    Strange but true …

Comments are closed.