ufm: (Default)
[personal profile] ufm
if a > b then
  env.out.print("a is bigger")
end

Can I use integers and pointers for the condition like I can in C? No. In Pony if conditions must have type Bool, i.e. they are always true or false. If you want to test whether a number a is not 0, then you need to explicitly say a != 0. This restriction removes a whole category of potential bugs from Pony programs.


Вот есть же у кого-то мозг. А еще прикольно:

1 + 2 * 3
We will get a value of 9 if we evaluate the addition first and 7 if we evaluate the multiplication first. In mathematics there are rules about the order in which to evaluate operators and most programming languages follow this approach.

The problem with this is that the programmer has to remember the order and people aren't very good at things like that. Most people will remember to do multiplication before addition, but what about left bit shifting versus bitwise and? Sometimes people misremember (or guess wrong) and that leads to bugs. Worse, those bugs are often very hard to spot.

Pony takes a different approach and outlaws infix precedence. Any expression where more than one infix operator is used must use parentheses to remove the ambiguity. If you fail to do this the compiler will complain.
This means that the example above is illegal in Pony and should be rewritten as:
1 + (2 * 3)
Repeated use of a single operator however is fine:
1 + 2 + 3


#ponylang #programming #software

(no subject)

Date: 2017-02-02 05:09 (UTC)
dil: (Default)
From: [personal profile] dil
Вычисление в порядке написания, без учёта приоритета операций - очень нетипично для языков программирования, поскольку не соответствует общепринятым нормам математики. Не нравится мне такая идея.

(no subject)

Date: 2017-02-02 21:22 (UTC)
dil: (Default)
From: [personal profile] dil
Ну как же - если 1 + 2 * 3 вычисляется как сначала 1+2, а потом *3, то это и есть в порядке написания, а не в порядке приоритета операций, когда сначала вычисляются умножения и деления, а потом уже сложения и вычитания.

(no subject)

Date: 2017-02-02 22:02 (UTC)
dil: (Default)
From: [personal profile] dil
Ну если там надо явно указывать скобками порядок вычисления, значит, без скобок посчитается неправильно..

(no subject)

Date: 2017-02-03 10:06 (UTC)
dil: (Default)
From: [personal profile] dil
Не обязательно, но, типа, может:
"Any expression where more than one infix operator is used must use parentheses to remove the ambiguity."