[Tutor] a puzzle about -3**2 vs (-3)**2

Alan Gauld alan.gauld at btinternet.com
Fri Jul 31 20:51:37 CEST 2015


On 31/07/15 18:08, D Wyatt wrote:
> > It looks odd to us but that's not the point, its how the language works.
> > You learn to get used to it. Most languages have some idiosyncrasies like
> > this.
>
> Yes, I understand that the creator of the language can make it work
> however he wants, but I was really hoping for a logical answer.  Just
> because 'that's the way it is' kind of sucks and will make it more
> difficult to remember.
Many languages do their own thing because it makes the compiler go faster,
or makes the code produced more reliable/consistent. That's often more
important to a language designer than making it intuitive to the reader.

In fact, some languages deliberately use a different set of 
rules/notation because
the language designer believes that his/her way is superior to the 
traditional
notation and uses the language to test those ideas.

Now, as others have pointed out, Python does in fact follow traditional 
math
in most things, so is usually intuitively correct, but you should never 
assume
that of any programming language. The designers are often reaching for 
different
targets than the eventual user. And very often we the users don't know what
the designer's aims or priorities were. (For example Forth was designed 
to fit
into the very small amount of memory left over on an astronomical telescope
control system, so is very, very terse, and uses many "illogical" code 
layouts.
Everything was sacrificed to save space.)

Of course as users we get to decide whether the designers choices are
acceptable to us or whether we will adopt another language. Many
experimental languages full of good, powerful programming ideas never
made it into common use precisely because they chose some weird syntax
or layout convention that was just too far out for programmers to accept.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos



More information about the Tutor mailing list