Choosing between Python and Javascript for mathematical modelling

Continuing the discussion from What are you coding?:

I started out by reviewing Jon Zeigler’s draft new star system and world generation procedure and not liking (a) aspects of his algorithm or (b) its being written to be executed by hand with pencil, paper, dice, and a scientific calculator. Also, I grew dissatisfied with the procedurally generated world statistics I have been using to base the worlds on for my current writing project. So I started to develop my own star system and world generation procedure as an Excel workbook because (1) I know how to use Excel for that sort of thing (2) I don’t have any way to compile or run FORTRAN on my computer, FORTRAN being the programming language I used to use when I had to program mathematical models for work, and (3) I’m insane.

I’ve got to the point where I can easily generate the biosphere and the atmospheric chemistry, then the temperature, and I don’t see any real obstacles to moving on to climate and geography. Except that my system for generating the intensity of plate-tectonic phenomena isn’t working, and to mend it I have to model the primordial heat and gradual cooling of the mantle. The workbook is up to 220 columns or so, the formulas in those cells look like "=IF(BM22="","",AU22*(4.15*10^-12*POWER(0.5,$G$6/14)+6.13*10^-12*POWER(0.5,$G$6/4.47)+1.25*10^-11*POWER(0.5,$G$6/1.25)+1.41*10^-11*POWER(0.5,$G$6/0.704)))" and =IF(EA24="","",IF(EA24=6,IF(CP24<2,0.5,IF(CP24<4,0.3,IF(CA24<80,0.3,0))),0)), modifying what I wrote two days ago is proving difficult, and debugging is a bear.

I really, really need proper branches, loops, procedure calls, and variables with memorable names. Had I a FORTRAN development environment like what I used to have on the PCs at work twenty-five years ago this would be a snap. But everything I used to use is obsolete now. It doesn’t help to know what arrays and pointers, files, binary trees, and linked lists are, anymore. It looks as though to just write a piece of simple code in any modern language I have to learn what a paradigm is and what objects, classes, and methods are. :unamused:

That has hitherto always seemed like more work than was justified by the task at hand, and I program so infrequently now that I have always put it off and made do with Lovecraftian SAN-busting Excel workbooks. But now I feel about ready to bite the bullet. I’m going to teach myself to program in a modern language, but I am going to have to start at the “what application do I launch, and what window do I type code into?” level.

To answer that I have first to commit to a programming language. It seems to me that everyone who does the sort of thing I want to do (i.e. scientists and engineers) uses Python, but that all my friends who are programmers assure me that I have no sensible alternative to Javascript. Their reasons seem to boil down to Javascript being really cool for reasons that I don’t understand or care about, semantic whitespace sucking (it does), and Javascript being really easy to build interfaces to (I’d be content with FORTRAN I/O).

1 Like

FORTRAN, I believe, is still viable, at least on *nix platforms (I have no in-depth knowledge of specifics).

I strongly recommend python.

That said, I have friends who are big data scientists and they are using Scala and R. Where Scala may be interchanged with (functional programming language du jour).

I strongly recommend python unless you are up to the functional programming idiom shift

1 Like

Nevermind, I misread this section.

Find a functional language that appeals to you

Edit: Scala being an interesting choice because you can share a JRE with Java and the UI options that accompany it.

GNU FORTRAN is readily available for Mac here.

Javascript is great if you are building web apps, but lots of people seem to have lost touch with the idea that programming can be for things that aren’t web apps.

2 Likes

FORTRAN is still being used in some areas of physics - the supercomputer used by the UK Met Office runs forecast models written in FORTRAN, so not obsolete just yet :wink:

I can recommend python, but you might as well use what you know.

Apparently everyone know uses Youtube videos for what I used to ask people to show me. I now see my way clear to installing Python 3 and IDLE on my Mac and getting stuck in. It looks pretty straightforward.

2 Likes

I don’t like Python and I love Javascript (like all your friends who are programmers maybe), but for what you’re doing I’d recommend Python over Javascript without reservation. Javascript’s coolness is totally unimportant in this case.

As you point out, nowadays you seem to have to learn not just a language but a sort of lifestyle like React in order to do certain things, but Python is still a decent scripting language for just getting specific jobs done. And there are loads of decent libraries that just work in normal ways, without expecting you to do everything asynchronously or using lambdas.

1 Like

Python has the NumPy library which is spoken of extremely highly though I haven’t yet tried it myself.

I’ve been playing with Python a bit for the Perl Weekly Challenges (long story, see blog). My feeling at the moment is that while it’s uninspiring and not as orthogonal as I’d like it is reasonably good at getting stuff done, and while its libraries are nothing like CPAN they’re not bad.

(And while you can certainly do classes in it, it doesn’t force you to.)

Speed may be a concern; it’s not compiled.

docs.python.org is pretty good; The Python Standard Library — Python 3.9.1 documentation is something I’ve been using a lot.

I am a programmer and I find Javascript really quite an unpleasant language, not surprising given that it wasn’t originally meant for anything terribly sophisticated and it’s had to remain backwards-compatible. I mean, it’s no PHP, but I write in it only if forced.

2 Likes

Honestly, I think it’s an amazing language. I recommend Douglas Crockford on the subject JavaScript: The World's Most Misunderstood Programming Language and The Little JavaScripter (quote from https://www.crockford.com/javascript/popular.html: “But despite JavaScript’s astonishing shortcomings, deep down, in its core, it got something very right. When you peel away the cruft, there is an expressive and powerful programming language there”)

Fair enough!

(I’m currently really liking Rust, but oh how I wish something like a hash/dict/associative array were built in rather than in a library. Much of my data structure work looks like “push onto the array that is this hash element” and in Rust that’s a pain.)

I have Excel workbooks that took 22 minutes to update.

1 Like

Once you realize how lispy it is, it’s much easier to understand.

Python, on the other hand, will always be a pile of flaming garbage.

Javascript only has floating point numbers, yeah? Depending on the maths you’re wanting to do, it might not be suitable.

Of course if that appeals then you would just use an actual lisp dialect : )

well, duh. But that’s not always an option. (there is a lisp project that compiles to javascript, though…)

For sure, but it definitely is an option in this instance.

Learning a lisp wouldn’t be the easiest option available; but if you’re willing to put some time and effort in, it can be quite the eye-opener as to what a programming language can be. (Potentially a bad thing if you find that the other languages you use suddenly seem deficient : )

1 Like