Disclaimer: I'm sure someone is going to moan about easy-of-use, for the purpose of this question consider readability to be the only factor that matters

So I found this site that converts to easting northing, it's not really important what that even means but here's how the piece of javascript looks.

 * Convert Ordnance Survey grid reference easting/northing coordinate to (OSGB36) latitude/longitude
 * @param   {OsGridRef} gridref - easting/northing to be converted to latitude/longitude
 * @returns {LatLonE} latitude/longitude (in OSGB36) of supplied grid reference
OsGridRef.osGridToLatLong = function(gridref) {
    var E = gridref.easting;
    var N = gridref.northing;

    var a = 6377563.396, b = 6356256.909;         // Airy 1830 major & minor semi-axes
    var F0 = 0.9996012717;                        // NatGrid scale factor on central meridian
    var φ0 = 49*Math.PI/180, λ0 = -2*Math.PI/180; // NatGrid true origin
    var N0 = -100000, E0 = 400000;                // northing & easting of true origin, metres
    var e2 = 1 - (b*b)/(a*a);                     // eccentricity squared
    var n = (a-b)/(a+b), n2 = n*n, n3 = n*n*n;    // n, n², n³

    var φ=φ0, M=0;
    do {
        φ = (N-N0-M)/(a*F0) + φ;

        var Ma = (1 + n + (5/4)*n2 + (5/4)*n3) * (φ-φ0);
        var Mb = (3*n + 3*n*n + (21/8)*n3) * Math.sin(φ-φ0) * Math.cos(φ+φ0);
        var Mc = ((15/8)*n2 + (15/8)*n3) * Math.sin(2*(φ-φ0)) * Math.cos(2*(φ+φ0));
        var Md = (35/24)*n3 * Math.sin(3*(φ-φ0)) * Math.cos(3*(φ+φ0));
        M = b * F0 * (Ma - Mb + Mc - Md);              // meridional arc

    } while (N-N0-M >= 0.00001);  // ie until < 0.01mm

    var cosφ = Math.cos(φ), sinφ = Math.sin(φ);
    var ν = a*F0/Math.sqrt(1-e2*sinφ*sinφ);            // nu = transverse radius of curvature
    var ρ = a*F0*(1-e2)/Math.pow(1-e2*sinφ*sinφ, 1.5); // rho = meridional radius of curvature
    var η2 = ν/ρ-1;                                    // eta = ?

    var tanφ = Math.tan(φ);
    var tan2φ = tanφ*tanφ, tan4φ = tan2φ*tan2φ, tan6φ = tan4φ*tan2φ;
    var secφ = 1/cosφ;
    var ν3 = ν*ν*ν, ν5 = ν3*ν*ν, ν7 = ν5*ν*ν;
    var VII = tanφ/(2*ρ*ν);
    var VIII = tanφ/(24*ρ*ν3)*(5+3*tan2φ+η2-9*tan2φ*η2);
    var IX = tanφ/(720*ρ*ν5)*(61+90*tan2φ+45*tan4φ);
    var X = secφ/ν;
    var XI = secφ/(6*ν3)*(ν/ρ+2*tan2φ);
    var XII = secφ/(120*ν5)*(5+28*tan2φ+24*tan4φ);
    var XIIA = secφ/(5040*ν7)*(61+662*tan2φ+1320*tan4φ+720*tan6φ);

    var dE = (E-E0), dE2 = dE*dE, dE3 = dE2*dE, dE4 = dE2*dE2, dE5 = dE3*dE2, dE6 = dE4*dE2, dE7 = dE5*dE2;
    φ = φ - VII*dE2 + VIII*dE4 - IX*dE6;
    var λ = λ0 + X*dE - XI*dE3 + XII*dE5 - XIIA*dE7;

    return new LatLonE(φ.toDegrees(), λ.toDegrees(), GeoParams.datum.OSGB36);

I found that to be a really nice way of writing an algorythm, at least as far as redability is concerned. Is there any way to easily write the special symbols. And by easily write I mean NOT copy/paste them.

  • Use a greek keyboard layout. Seriously, for example, using MS Windows: conversationexchange.com/resources/keyboard-language.php
    – Doc Brown
    Jun 8, 2014 at 12:29
  • @DocBrown so um can you post a answer with how I would actually go about typing those after I set it up; not familiar with greek keyboard layout patterns
    – srcspider
    Jun 8, 2014 at 12:48
  • 1
    Well, you still make a secret of the OS you are using, so I cannot tell you what is necessary in your environment. All the "math symbols" shown in your example are nothing but greek letters. Under Windows 8 for example (my current environment), you install the greek layout, switch to it by pressing "Win-Space" and enter "α=a", "β=b", "γ=g", "δ=d" and so on.
    – Doc Brown
    Jun 8, 2014 at 14:07
  • @DocBrown operating system it should work on is Windows/Ubuntu (potentially other linux systems).
    – srcspider
    Jun 8, 2014 at 15:02
  • 1
    Oh, and I think this question is not so much a programming question, it would have been better placed on "Superuser". See here superuser.com/questions/239577/… or here superuser.com/questions/346486/… for similar questions.
    – Doc Brown
    Jun 9, 2014 at 10:10

1 Answer 1


I thought what a funny question until I realized that you want to make use of the fact that some languages allow more than the plain ASCII characters in their identifiers and go towards a notation that fits the problem domain more, like in intentional programming. Here the problem domain being geometry.

The answer to your question depends on your environment. I suppose you want to enter Unicode charcters. On a windows machine you would use a different tool than on an iPhone or Mac or X11 machine. Most of these systems feature some kind of extended keyboard application.

In general I think the advantage of improved understanding would be not worth the hassle to edit these lines using this primitive method.

But that changes if the system is well done:

In fact I enjoy the MathJax editor on math.stackexchange very much which allows me to enter and view LaTeX mathematical formulas in an acceptable way.

I would love to hove something like this in my general programming environments Emacs (alas that would need one better integrated with the GUI) and the JetBrains IDEs.

I still believe in Knuth's literate programming. But all this is not well integrated in real world / industry environments yet, sadly.

Thanks for your question because it made me revisiting intentional programming and there I noted that intentional has released (see above Fowler link) and that there is a DSL IDE from JetBrains: Meta Programming System!

  • I do understand the concern however with out experimenting with it first hand I don't really want to form any preconceptions. For something like a security algorithm, which is the case that annoys me to convert to longVariableNames you want more then just input => output tests, you also want someone reading the algorythm to be able to tell that it's not actually vulnerable to attack in the way it's written/working. In that scenario any extra readability is invaluable, and wall on updates to the code is almost desirable (ie. either you think in the math and its easy for you or you dont touch).
    – srcspider
    Jun 8, 2014 at 13:28
  • ...and by someone reading the algorythm that includes yourself as well.
    – srcspider
    Jun 8, 2014 at 13:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.