Pythonic syntax to declutter Javascript
azarask.in
azarask.in
function triangle(a,b){
if(a > 0 && b > 0 ){
function sqroot(x){
if( x > 0 ){
return Math.pow(x,.5);
}
else {
return 0;
}
}
return sqroot( a*a + b*b );
}
else {
return 0;
}
}
Can be made much cleaner: function triangle(a,b){
if (a <= 0 || b <= 0 ) return 0
function sqroot(x){ return ( x > 0 ? Math.pow(x,.5) : 0 ) }
return sqroot( a*a + b*b )
}
I don't know about a whitespace-sensitive language in the browser. Much JS is written by non-coders, later quickly edited on live servers (yeah, I know. But that's reality) etc.. It all comes down to taste, of course, but personally I find Ruby at least as readable as Python, so I'm not sure whitespaces are where the elegance is found. function triangle(a,b)
a <= 0 || b <= 0 ? 0 : (a = a*a + b*b) > 0 ? Math.pow(a,.5) : 0;Also really, honestly, I hate to post python script somewhere in forum, and because of the identation someone else cannot test it.
Hey there is clojurehub@appspot.com - right - you type something in google.wav - send it to the address above, and the clojure appspot program gives you back the result - nice REPL :)
Now how would that work with python, or this pyscript? Just thing about it?
Also - reminds me of CoffeeScript (which has similarly clean (if less Pythonic) syntax, but has to be compiled to Javascript, I believe). http://jashkenas.github.com/coffee-script/#overview
I think Python is dandy. I will be starting a new project on it, actually. But "stark" and "modern" are relative. While there's a lot of very pretty Python that reads like pseudocode, there's also a bit of Python that goes down the same sinful path as C header files or Perl in the use of arcane symbols. There's no reason why things like meta-programming have to look like anything different from plain old programming.
That said, I think Python hits a very attractive middle ground. There is just enough syntax to fit the most basic cultural expectations of technical people as well as a large number of programmers. That, if you think about it, is a stunning achievement in human-interface design. (Read that straight-up!)
(And to be fair: Smalltalk - even more minimal, but ignores lots of important cultural expectations. Lisp - even more minimal and just about everything, no matter how meta, looks like normal Lisp. But on the downside, everything looks like normal Lisp.)
Not to mention that in his samples half the curlies were unnecessary.
I'm not sure if it's better to write in real Python or just know that you're using JS with different syntax ala pyscript. Emulating all the bizarre Python attribute access behaviour in JS (e.g. __get__) is quite complex.
What's a "scripting language"?
Won't that be rather slow?
Firefox is implemented in JavaScript. It's pretty fast, and a little more complicated than a parser.
i'm pretty sure that much of the performance-critical core is in C++; javascript is th UI/extensions layer, to the best of my knowledge
Obviously parts are C++ but isn't interfacing with such code one of the defining characteristics of a "scripting language" and javascript in particular?
Or interpreted language, if the nomenclature is that important.