9

It seems to me that programming languages meant for use in science and engineering are consistently weird compared to general-purpose languages. Some examples off the top of my head:

  • In Matlab, each function has to be placed in a separate file
  • In R, <- is the assigment operator, as opposed to = in almost every other language
  • Matlab, R, Julia and others are all 1-indexed
  • Matlab uses % for comments, and not the standard # or //

Of course, these languages all have several design features that actually make them easier to use for scientific applications, such as more natural matrix notation. Still, they all inexplicably make all these bizarre choices which don't make anything easier and could easily have been avoided if the language designers had just chosen to do what 99% of other languages do. Is the reason vendor lock-in? A lack of contact with the wider software development community? Something else?

I read this thread and didn't find the explanations satisfactory. Just because R were designed as a scientific language doesn't mean it had to completely ignore conventions and use <- instead of =.

closed as primarily opinion-based by gnat, user39685, Blrfl, Jan Hudec, user40980 Feb 21 '14 at 13:05

Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 6
    Short answer: because they were made for scientists, not for programmers. – Bart van Ingen Schenau Feb 21 '14 at 11:03
  • 19
    Short answer: Because every language you think is normal was influenced by a common ancestor, C. – Ross Patterson Feb 21 '14 at 11:17
  • 3
    I think you'll struggle to find any conventions across languages. It depends on their heritage. – Robbie Dee Feb 21 '14 at 11:19
  • 6
    Nothing of that is weird. It's just different. Because there is no particular reason to choose one syntax over the other except what the specific author of the specific language is used to. – Jan Hudec Feb 21 '14 at 13:05
  • 8
    Your 99% is wrong. If you only know C and its derivatives you might think so, but well over 50% of non-C languages use something different for assignment, indexing and/or comments. – david.pfx Feb 21 '14 at 13:59
21
  • There are different conventions. Conventions in mathematics, logic, and applied sciences and conventions in IT. The first ones are far older.
  • The scientific languages are made to make the life of THEIR users more convenient. The user is seen as a scientist, who can realize some algorithm from time to time or to check some theory, without the need to learn something really new. So, the languages for scientists MUST be made up to non - IT standards. Because they are not meant for the use of IT people. They are up to OTHER standards and that is good because of the target auditory. Because the good SW UI, and language is SW UI, must be done based on needs of user, not of the coder.
  • Our IT standards are industry standards. IT is industry. Science is not industry. Scientists are proud of it. And they would reluctantly take anything from our practice into theirs. And they don't like standards at all. And nobody likes foreign standards. So, if somebody will make a scientific language that will look up to IT standards, it would be hardly selling well, because of the dislike of the target auditory, even if it were objectively more convenient.

And even if we'll judge only according to IT standards... Sorry, what standards do you mean? Have you tried to write a prog in APL or SNOBOL? These two language are, IMHO, the MOST powerful in appropriate fields (counting and strings). But the syntax is something VERY strange (and effective) Reading a line of APL code could take days. On the other hand, such line is a serious piece of SW. You'd return to Mathlab with tears of relief.

As for "=", many people have problems to be accustomed that it is not equality, but assignment. BTW, in Pascal it IS equality and assignment is ":=".

And you really think that == for equality is more natural? On the contrary, mixing = and == is the MOST common error in C programming, it happens very often even in contemporary IDEs, with their automatic control.

About indexing from 1 - it is the only natural one. When you were a child, you had learned poems and songs, where you counted: one, two, three... And not 0,1,2... In school math we studied that the counting starts from 1, and that 0 doesn't belong to natural/counting numbers. Only with the definition of functions non-natural indices come. After all, the 0 was invented many thousands of years after our ancestor raised a finger up.

0-start was more simple to realize and immediately got into IT practice after C appearance. But in Fortran, the first language, the 1-indexing is used. The same with other languages of the pre-industrial epoch.

And yes, I had read Dyjkstra's article on naturality of the 0-based counting. And totally disagree with his argumentation. It is natural for musicians ony. And even 0 enthusiasts that create the C and Java compilers, count the lines of the code STARTING FROM 1!

  • 1
    ":=" for assignment and 1-based indexing are used in Smalltalk too. – Rory Hunter Feb 21 '14 at 10:52
  • 1
    I don't buy that 0 based indexing is because of ease of implementation (FORTRAN pretty much disproves this). cs.utexas.edu/users/EWD/transcriptions/EWD08xx/EWD831.html gives some reasons one might prefer 0-based indexing, but note the choice is fairly arbitrary. – jk. Feb 21 '14 at 11:26
  • 2
    FORTRAN had 1-based indexing. PASCAL allowed arbitrary-based indexing: you could declare an array whose index ranged over, for example, -42 to +57. (See en.wikipedia.org/wiki/… for an example where this is useful.) – John R. Strohm Feb 21 '14 at 12:43
  • 1
    @Gangnus I think it is a mistake to compare modern languages to C and deem it to be intentionally hard to read. It was designed to be a high level alternative to lower level languages. – Robbie Dee Feb 21 '14 at 13:19
  • 1
    FORTH is a stack based language. Think HP calculator. It was very compact and fast, but it was hard to write code that wasn't impenetrable. In FORTH, you rarely use variables but rather push things onto the stack and use operators that act on the stack. – Steven Burnap Feb 24 '14 at 18:57
16

Indexing from 1 is not weird, it is completely normal and expected except for programmers, because they've been conditioned to expect 0-based counting by C (which was conditioned from the properties of processor architecture).

Comments are denoted in many, many many different ways in different languages; there is no standard way, every language chooses a symbol or digraph that isn't already taken.

Assignment is likewise a strange and incomprehensible concept, except for programmers; most people couldn't care less whether it's = or := or <-, they struggle to understand the meaning (and for them, it is in fact better not to use =, because this emphasizes that assignment is not equality - the most common hurdle for non-programmers to understand code).

In short, programming languages intended for people other than professional programmers look different because the people who use them most want it that way.

  • 4
    I disagree that indexing from 1 is not weird. 0-indexing is at least as common as 1-indexing in mathematics, and it had obviously been the norm in programming for years before the advent of Matlab or S/R. – haroba Feb 21 '14 at 10:47
  • 9
    @Aqwis Oh, yes, I already see the baby counting zero, one, two... The most natural way, really. – Gangnus Feb 21 '14 at 10:48
  • 4
    Babies don't write code. There are good reasons to use zero-indexing (see: Dijkstra), and when zero-indexing is also common in mathematics I cannot see many reasons to use 1-indexing. – haroba Feb 21 '14 at 10:51
  • 1
    @Aqwis Answer for your own words. What is weird and not. A thing that is set from the babyhood and by maths (natural numbers do not include zero), can not be weird from any side. And what contradicts with it, IS weird. And that you have accustomed to something else, is irrelevant. These languages simply are not made for you or me. – Gangnus Feb 21 '14 at 10:59
  • 1
    @phresnel To paraphrase from the answer: Indexing from 1 is normal. Except for programmers, because they've been conditioned to expect it [indexing from 0] from C – Robbie Dee Feb 21 '14 at 17:00
5

There are three problems:

  1. You are unaware of certain traditions, and the good reasons for certain choices.
  2. You put too much emphasis on syntax, too little on semantics.
  3. Engineers and scientists have no experience in language design, leading to questionable syntax.

Now to your specific points:

  • I don't know Matlab, so I can't comment on the requirements of file organization. Note that Java wants you to use one file per public class.

  • In R, = can be used as an assignment operator as well. Note that it needs multiple assignment operators <- and <<- to deal with its concept of scoping (<<- assigns to a symbol in an outside scope instead of creating a new symbol inside a function). The arrows can be used in the other direction too, potentially making cleaner code: complex_calculation() -> x.

  • 1-based indexing is the standard in mathematics, which is what Matlab's and R's users are more comfortable with than C. Julia follows Matlab in order to have a better learning curve.

  • % for comments is also used in TeX/LaTeX. The # is only a convention from Unix scripting languages, and their descendants.

You also ignore that “real” programming languages have many weird parts. Why doesn't Scheme use =? Instead:

(define foo 5)

Why does C use * for dereferencing, when obviously a caret ^x is more common in other traditions?

  • "I don't know Matlab, so I can't comment on the requirements of file organization. Note that Java wants you to use one file per public class." I think it's perfectly reasonable for the language to expect you to divide your project into several files. However, a class is usually a relatively large amount of code. Functions don't have to be. By forcing a separate file for every function, Matlab discourages you from creating small functions and instead promotes large, monolithic functions. – haroba Feb 21 '14 at 10:54
  • 1
    I agree almost with everything, except p.3. Scientists do not make their languages, they ORDER them. They are clients, users, but not their creators. If somebody is, he/she is already an IT geek. And syntax of any language is questionable, no one is ideal for all tasks. – Gangnus Feb 21 '14 at 10:55
  • Matlab compiles functions/files on a just-in-time basis as required. It has no real concept of a program, just a bunch of functions. If I am running a function which makes a call to foo(), then it will search its path for a file called foo.m, compile it, and run it. There's no need to tell Matlab in advance what set of files I intend to use. – Simon B Jan 8 '16 at 12:18
1

I guess it depends on your exposure to other languages. Off the top of my head:

  • C/C++ have separate source files (.c/.cpp & .h)
  • The -> characters are used in C# for lambda expressions
  • Old versions of VB used 1 as a default index (although this could be changed with Option Base)
  • 1
    In C and C++, you can define as many functions as you want in one file. – haroba Feb 21 '14 at 10:42
  • I'm just making the point that it isn't unusual for modules to be split across multiple files. If you wished to you could put all your functions in separate files using .NET languages with the partial class construct. – Robbie Dee Feb 21 '14 at 10:45
  • 1
    Of course it is not unusual for modules to be split across several files, and it is in many cases desirable. But in Matlab you have to put every single function in its own file, which means that if you have a thousand functions you need a thousand files. – haroba Feb 21 '14 at 10:46
  • 3
    Comments in HTML look like <!-- ... -->. The percent sign is used for URL-encoding: http://example.com/() becomes http://example.com/%28%29. – amon Feb 21 '14 at 11:02
  • Sorry, my mistake. – Robbie Dee Feb 21 '14 at 11:16

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