Comment

Comment by nir

Javascript example in the article:

  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.
parent nir 17 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton