Re: Mathematica daily WTF
- To: mathgroup at smc.vnet.net
- Subject: [mg115136] Re: Mathematica daily WTF
- From: David Bailey <dave at removedbailey.co.uk>
- Date: Sun, 2 Jan 2011 04:54:51 -0500 (EST)
- References: <ifj6n0$594$1@smc.vnet.net>
On 31/12/2010 00:04, Andrzej Kozlowski wrote: > On 29 Dec 2010, at 11:55, Richard Fateman wrote: > >> When common programming terms are used in a different >> manner, it sows the seeds of misunderstanding. > > Actually, it works both ways. No doubt for people with a "deeper" understanding of other languages who tend to assume that they are dealing with something familiar when in fact they are not, this could be a source of misunderstanding and as such a "bad thing". But for most "unsophisticated" users (whose cause you often claim to champion here) the situation is usually the opposite to this; this sort of superficial resemblance helps them to use Mathematica without the need for an extensive study and is therefore a "very good thing". In fact, this is closely related to an aspect of the Mathematica programming language for which you have explicitly expressed a dislike (in a private exchange with me): the fact that it contains all these "procedural" constructs like loops etc. While this certainly would be offensive to the aesthetics of a pure functional language like Lisp (or better Scheme), it actually is one of the main reasons for the success of Mathematica. I remember someo ne telling me that the lack of such constructs was the principal reason for the (relative) failure of SMP (I don't know if this is true, I have never used SMP and don't know anything about it). While Mathematica's procedural programming is usually unattractive and often inefficient, there are plenty of users who will not use anything else (including one user who frequently takes similar positions to yours on various Mathematica related issues) and would not even consider a alternative program that used Lisp for programming - just for that very reason. > > What I referred to as a matter of "convenient syntax" is actually a quite crucial issue, for most people easily overriding in importance anything else mentioned in this thread. > > Andrzej Kozlowski > I'd go further. I think the procedural aspects of Mathematica are vital to its success, and I am quite happy to use them all (except Goto) when I feel the need. Sometimes, particularly in the case of an outer loop, replacing a loop construct with a functional construct will make very little difference to the performance. In other cases, it is critical. In any case, Mathematica code can under-perform for a whole variety of reasons - something which I illustrated in a talk at the recent 2010 Technology Conference in Champaign. Procedural code lets anyone, 'hack' any process they desire, whereas functional code becomes conceptually harder and harder as complications set it - at least to those of us who spent many years writing code in C and Fortran! Fortran and C programmers, also worry about CPU cache coherence - the fact that code that operates on one chunk of memory at a time (rather than making scattered references to a large array) usually performs better because data in memory if pulled into the CPU cache in chunks (and sometimes it is even retrieved from the disk), so doing the most with each chunk is desirable. It is far easier to use the CPU cache efficiently when writing procedural code. The fact that functional code sometimes outperforms procedural code, is an artifact of Mathematica - caused essentially by the fact that there is an overhead associated with each individual step (checking types, OwnValues, etc.) The whole array operations of modern Fortran, offer little if any speed gain over using a Do loop - and indeed, a glance at the assembly code generated will reveal that there is very little difference in the code generated. As regards aesthetics, I'd say that sometimes functional code looks much more elegant than the procedural equivalent, but other times, it just looks obscure! (Raising flame barriers!) David Bailey http://www.dbaileyconsultancy.co.uk